back to sequelize

This commit is contained in:
Kaushik Narayan R 2024-07-27 23:30:37 +05:30
parent b79170aafd
commit 6c497c9be1
9 changed files with 1220 additions and 22 deletions

View File

@ -1,2 +1,7 @@
REDIRECT_URI = http://localhost:9001/api/auth/callback
TRUST_PROXY=1
TRUST_PROXY = 1
PG_USER = your_postgres_username
PG_PASSWD = your_postgres_password
PG_DATABASE = postgres_database_name
PG_HOST = localhost
PG_PORT = postgres_instance_port

6
.sequelizerc Normal file
View File

@ -0,0 +1,6 @@
require("dotenv-flow").config();
const path = require("path");
module.exports = {
"config": path.resolve("config", "sequelize.js")
};

33
config/sequelize.js Normal file
View File

@ -0,0 +1,33 @@
const logger = require("../utils/logger")(module);
let connConfigs = {
development: {
username: process.env.PG_USER,
password: process.env.PG_PASSWD,
database: process.env.PG_DATABASE,
host: process.env.PG_HOST,
port: process.env.PG_PORT,
},
test: {
username: process.env.PG_USER,
password: process.env.PG_PASSWD,
database: process.env.PG_DATABASE,
host: process.env.PG_HOST,
port: process.env.PG_PORT,
},
production: {
username: process.env.PG_USER,
password: process.env.PG_PASSWD,
database: process.env.PG_DATABASE,
host: process.env.PG_HOST,
port: process.env.PG_PORT,
},
}
// common config
for (const conf in connConfigs) {
connConfigs[conf]['logging'] = (msg) => logger.debug(msg);
connConfigs[conf]['dialect'] = 'postgres';
}
module.exports = connConfigs;

1176
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -27,11 +27,14 @@
"express-session": "^1.17.3",
"express-validator": "^7.0.1",
"helmet": "^7.0.0",
"pg": "^8.12.0",
"sequelize": "^6.37.3",
"winston": "^3.10.0"
},
"devDependencies": {
"@types/express": "^4.17.18",
"cross-env": "^7.0.3",
"nodemon": "^3.0.1"
"nodemon": "^3.0.1",
"sequelize-cli": "^6.6.2"
}
}

View File

@ -8,7 +8,6 @@ const validator = require("../validators");
router.get(
"/me",
isAuthenticated,
validator.validate,
getUserPlaylists
);

View File

@ -5,6 +5,10 @@
* @typedef {import('express').Response} Res
* @typedef {import('express').NextFunction} Next
*
* @typedef {import("sequelize").Sequelize} Sequelize
* @typedef {import("sequelize").Model} Model
* @typedef {import("sequelize").QueryInterface} QueryInterface
*
* @typedef {import('winston').Logger} Logger
*
* @typedef {{

View File

@ -21,7 +21,7 @@ const axiosInstance = axios.default.create({
});
axiosInstance.interceptors.request.use(request => {
logger.info("API call", {
logger.http("API call", {
url: request.url,
method: request.method,
params: request.params ?? {},

View File

@ -1,7 +1,7 @@
const path = require("path");
const { createLogger, transports, config, format } = require('winston');
const { combine, label, timestamp, printf, errors } = format;
const { colorize, combine, label, timestamp, printf, errors } = format;
const typedefs = require("../typedefs");
@ -55,10 +55,8 @@ const logger = (callingModule) => {
logFormat,
),
transports: [
process.env.NODE_ENV !== 'production' ?
new transports.Console() :
new transports.Console(),
new transports.File({ filename: __dirname + '/../logs/common.log' }),
new transports.Console({ level: 'debug' }),
new transports.File({ filename: __dirname + '/../logs/debug.log', level: 'debug' }),
new transports.File({ filename: __dirname + '/../logs/error.log', level: 'error' }),
]
});