Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JsConfig With Paths & Module-Aliases #23

Merged
merged 5 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Date : 29-Sep-2021
* Description : Start file of a user service
*/

require('module-alias/register')
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
Expand All @@ -19,12 +19,12 @@ if (!environmentData.success) {
process.exit()
}

require('./configs')
require('@configs')

const app = express()

// Health check
require('./health-checks')(app)
require('@health-checks')(app)

app.use(cors())

Expand Down
8 changes: 4 additions & 4 deletions src/controllers/v1/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

// Dependencies
const accountHelper = require('../../services/helper/account')
const accountHelper = require('@services/helper/account')
const csv = require('csvtojson')
const common = require('../../constants/common')
const apiResponses = require('../../constants/api-responses')
const httpStatusCode = require('../../generics/http-status')
const common = require('@constants/common')
const apiResponses = require('@constants/api-responses')
const httpStatusCode = require('@generics/http-status')

module.exports = class Account {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/v1/cloud-services/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description : Google cloud services methods.
*/

const filesHelper = require('../../../services/helper/files')
const filesHelper = require('@services/helper/files')

module.exports = class File {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/v1/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Dependencies
const formsHelper = require('../../services/helper/form')
const formsHelper = require('@services/helper/form')

module.exports = class Form {
/**
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/v1/mentors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/

// Dependencies
const mentorsHelper = require('../../services/helper/mentors')

const mentorsHelper = require('@services/helper/mentors')
module.exports = class Mentors {
/**
* List of mentors
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/v1/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Dependencies
const profileHelper = require('../../services/helper/profile')
const profileHelper = require('@services/helper/profile')

module.exports = class Profile {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/v1/systemUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Dependencies
const systemUsersHelper = require('../../services/helper/systemUsers')
const systemUsersHelper = require('@services/helper/systemUsers')

module.exports = class SystemUsers {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/v1/userentity.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Dependencies
const userEntityHelper = require('../../services/helper/userentity')
const userEntityHelper = require('@services/helper/userentity')

module.exports = class UserEntity {
/**
Expand Down
23 changes: 23 additions & 0 deletions src/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"baseUrl": "./",
"moduleResolution": "node",
"resolveJsonModule": true,
"paths": {
"@configs*": ["./configs*"],
"@constants*": ["./constants*"],
"@controllers*": ["./controllers*"],
"@db*": ["./db*"],
"@generics*": ["./generics*"],
"@health-checks*": ["./health-checks*"],
"@middlewares*": ["./middlewares*"],
"@public*": ["./public*"],
"@routes*": ["./routes*"],
"@services*": ["./services*"],
"@validators*": ["./validators*"]
}
},
"exclude": ["node_modules"]
}
8 changes: 4 additions & 4 deletions src/middlewares/authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

const jwt = require('jsonwebtoken')

const httpStatusCode = require('../generics/http-status')
const apiResponses = require('../constants/api-responses')
const common = require('../constants/common')
const UsersData = require('../db/users/queries')
const httpStatusCode = require('@generics/http-status')
const apiResponses = require('@constants/api-responses')
const common = require('@constants/common')
const UsersData = require('@db/users/queries')

module.exports = async function (req, res, next) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fs = require('fs')

module.exports = (req, res, next) => {
try {
require(`../validators/${req.params.version}/${req.params.controller}`)[req.params.method](req)
require(`@validators/${req.params.version}/${req.params.controller}`)[req.params.method](req)
} catch (error) {}
next()
}
15 changes: 15 additions & 0 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"json2csv": "^5.0.6",
"jsonwebtoken": "^8.5.1",
"kafka-node": "^5.0.0",
"module-alias": "^2.2.2",
"moment": "^2.29.1",
"moment-timezone": "^0.5.34",
"mongodb": "^4.1.2",
Expand Down Expand Up @@ -61,5 +62,19 @@
"lint-staged": {
"../*": "prettier --ignore-unknown --write",
"*": "prettier --ignore-unknown --write"
},
"_moduleAliases": {
"@root": ".",
"@configs": "configs",
"@constants": "constants",
"@controllers": "controllers",
"@db": "db",
"@generics": "generics",
"@health-checks": "health-checks",
"@middlewares": "middlewares",
"@public": "public",
"@routes": "routes",
"@services": "services",
"@validators": "validators"
}
}
12 changes: 6 additions & 6 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* Description : Routes for available service
*/

const validator = require('../middlewares/validator')
const authenticator = require('../middlewares/authenticator')
const pagination = require('../middlewares/pagination')
const validator = require('@middlewares/validator')
const authenticator = require('@middlewares/authenticator')
const pagination = require('@middlewares/pagination')
const expressValidator = require('express-validator')
const fs = require('fs')

Expand Down Expand Up @@ -51,12 +51,12 @@ module.exports = (app) => {
'.js'
)
if (folderExists) {
controller = require(`../controllers/${req.params.version}/${req.params.controller}/${req.params.file}`)
controller = require(`@controllers/${req.params.version}/${req.params.controller}/${req.params.file}`)
} else {
controller = require(`../controllers/${req.params.version}/${req.params.controller}`)
controller = require(`@controllers/${req.params.version}/${req.params.controller}`)
}
} else {
controller = require(`../controllers/${req.params.version}/${req.params.controller}`)
controller = require(`@controllers/${req.params.version}/${req.params.controller}`)
}
controllerResponse = new controller()[req.params.method]
? await new controller()[req.params.method](req)
Expand Down
20 changes: 10 additions & 10 deletions src/services/helper/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ const bcryptJs = require('bcryptjs')
const jwt = require('jsonwebtoken')
const ObjectId = require('mongoose').Types.ObjectId

const utilsHelper = require('../../generics/utils')
const httpStatusCode = require('../../generics/http-status')
const apiResponses = require('../../constants/api-responses')
const common = require('../../constants/common')
const usersData = require('../../db/users/queries')
const notificationTemplateData = require('../../db/notification-template/query')
const kafkaCommunication = require('../../generics/kafka-communication')
const redisCommunication = require('../../generics/redis-communication')
const systemUserData = require('../../db/systemUsers/queries')
const FILESTREAM = require('../../generics/file-stream')
const utilsHelper = require('@generics/utils')
const httpStatusCode = require('@generics/http-status')
const apiResponses = require('@constants/api-responses')
const common = require('@constants/common')
const usersData = require('@db/users/queries')
const notificationTemplateData = require('@db/notification-template/query')
const kafkaCommunication = require('@generics/kafka-communication')
const redisCommunication = require('@generics/redis-communication')
const systemUserData = require('@db/systemUsers/queries')
const FILESTREAM = require('@generics/file-stream')

module.exports = class AccountHelper {
/**
Expand Down
10 changes: 5 additions & 5 deletions src/services/helper/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

// Dependencies
const cloudServices = require('../../generics/cloud-services')
const apiResponses = require('../../constants/api-responses')
const httpStatusCode = require('../../generics/http-status')
const common = require('../../constants/common')
const utils = require('../../generics/utils')
const cloudServices = require('@generics/cloud-services')
const apiResponses = require('@constants/api-responses')
const httpStatusCode = require('@generics/http-status')
const common = require('@constants/common')
const utils = require('@generics/utils')

module.exports = class FilesHelper {
/**
Expand Down
8 changes: 4 additions & 4 deletions src/services/helper/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

// Dependencies
const httpStatusCode = require('../../generics/http-status')
const apiResponses = require('../../constants/api-responses')
const common = require('../../constants/common')
const formsData = require('../../db/forms/queries')
const httpStatusCode = require('@generics/http-status')
const apiResponses = require('@constants/api-responses')
const common = require('@constants/common')
const formsData = require('@db/forms/queries')

module.exports = class FormsHelper {
/**
Expand Down
12 changes: 6 additions & 6 deletions src/services/helper/mentors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

// Dependencies
const usersData = require('../../db/users/queries')
const apiResponses = require('../../constants/api-responses')
const common = require('../../constants/common')
const httpStatusCode = require('../../generics/http-status')
const cloudServices = require('../../generics/cloud-services')
const utilsHelper = require('../../generics/utils')
const usersData = require('@db/users/queries')
const apiResponses = require('@constants/api-responses')
const common = require('@constants/common')
const httpStatusCode = require('@generics/http-status')
const cloudServices = require('@generics/cloud-services')
const utilsHelper = require('@generics/utils')

module.exports = class MentorsHelper {
/**
Expand Down
20 changes: 10 additions & 10 deletions src/services/helper/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// Dependencies
const ObjectId = require('mongoose').Types.ObjectId

const utilsHelper = require('../../generics/utils')
const httpStatusCode = require('../../generics/http-status')
const apiResponses = require('../../constants/api-responses')
const common = require('../../constants/common')
const usersData = require('../../db/users/queries')
const utilsHelper = require('@generics/utils')
const httpStatusCode = require('@generics/http-status')
const apiResponses = require('@constants/api-responses')
const common = require('@constants/common')
const usersData = require('@db/users/queries')

module.exports = class ProfileHelper {
/**
Expand All @@ -27,12 +27,12 @@ module.exports = class ProfileHelper {
static async update(bodyData, _id) {
bodyData.updatedAt = new Date().getTime()
try {
if (bodyData.hasOwnProperty("email")) {
if (bodyData.hasOwnProperty('email')) {
return common.failureResponse({
message: apiResponses.EMAIL_UPDATE_FAILED,
statusCode: httpStatusCode.bad_request,
responseCode: "CLIENT_ERROR",
});
message: apiResponses.EMAIL_UPDATE_FAILED,
statusCode: httpStatusCode.bad_request,
responseCode: 'CLIENT_ERROR',
})
}
await usersData.updateOneUser({ _id: ObjectId(_id) }, bodyData)
return common.successResponse({
Expand Down
10 changes: 5 additions & 5 deletions src/services/helper/systemUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

// Dependencies
const utilsHelper = require('../../generics/utils')
const httpStatusCode = require('../../generics/http-status')
const apiResponses = require('../../constants/api-responses')
const common = require('../../constants/common')
const systemUserData = require('../../db/systemUsers/queries')
const utilsHelper = require('@generics/utils')
const httpStatusCode = require('@generics/http-status')
const apiResponses = require('@constants/api-responses')
const common = require('@constants/common')
const systemUserData = require('@db/systemUsers/queries')

module.exports = class SystemUsersHelper {
/**
Expand Down
10 changes: 5 additions & 5 deletions src/services/helper/userentity.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// Dependencies
const ObjectId = require('mongoose').Types.ObjectId

const utilsHelper = require('../../generics/utils')
const httpStatusCode = require('../../generics/http-status')
const apiResponses = require('../../constants/api-responses')
const common = require('../../constants/common')
const userEntitiesData = require('../../db/userentities/query')
const utilsHelper = require('@generics/utils')
const httpStatusCode = require('@generics/http-status')
const apiResponses = require('@constants/api-responses')
const common = require('@constants/common')
const userEntitiesData = require('@db/userentities/query')

module.exports = class UserEntityHelper {
/**
Expand Down
5 changes: 3 additions & 2 deletions src/test/accountController.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('module-alias/register')
const chai = require('chai')
const sinon = require('sinon')
const expect = chai.expect
Expand All @@ -8,8 +9,8 @@ global.db = {
return
},
}
const accountService = require('../services/helper/account')
let controller = require('../controllers/v1/account')
const accountService = require('@services/helper/account')
let controller = require('@controllers/v1/account')

let mockData = require('./mock')

Expand Down