From 09f0b1a1508658218f9be02ae6d31323d458d932 Mon Sep 17 00:00:00 2001 From: saisilinus Date: Wed, 6 Apr 2022 10:53:35 +0300 Subject: [PATCH] feat: add modules folder --- .eslintrc.json | 2 +- src/app.ts | 6 +++--- src/config/passport.ts | 6 +++--- src/custom.d.ts | 2 +- src/{components => modules}/auth/auth.controller.ts | 8 ++++++-- src/{components => modules}/auth/auth.middleware.ts | 0 src/{components => modules}/auth/auth.service.ts | 0 src/{components => modules}/auth/auth.test.ts | 0 src/{components => modules}/auth/auth.validation.ts | 0 src/{components => modules}/email/email.interfaces.ts | 0 src/{components => modules}/email/email.service.ts | 0 src/{components => modules}/errors/ApiError.ts | 0 src/{components => modules}/errors/error.test.ts | 0 src/{components => modules}/errors/error.ts | 0 src/{components => modules}/jest/setupTestDB.ts | 0 .../paginate/paginate.plugin.ts | 0 src/{components => modules}/swagger/components.yaml | 0 .../swagger/swagger.definition.ts | 0 .../toJSON/hideToJSON.plugin.ts | 0 src/{components => modules}/toJSON/toJSON.plugin.ts | 0 src/{components => modules}/token/token.fixture.ts | 0 src/{components => modules}/token/token.interfaces.ts | 0 src/{components => modules}/token/token.model.ts | 0 src/{components => modules}/token/token.service.ts | 0 src/{components => modules}/token/token.types.ts | 0 src/{components => modules}/user/user.controller.ts | 4 ++-- src/{components => modules}/user/user.fixture.ts | 0 src/{components => modules}/user/user.interfaces.ts | 0 src/{components => modules}/user/user.model.test.ts | 0 src/{components => modules}/user/user.model.ts | 0 src/{components => modules}/user/user.service.ts | 0 src/{components => modules}/user/user.test.ts | 0 src/{components => modules}/user/user.validation.ts | 0 src/{ => modules}/utils/catchAsync.ts | 0 src/{ => modules}/utils/pick.ts | 0 src/{ => modules}/utils/rateLimiter.ts | 0 .../validate/custom.validation.ts | 0 .../validate/validate.middleware.ts | 2 +- src/routes/v1/auth.route.ts | 8 ++++---- src/routes/v1/swagger.route.ts | 2 +- src/routes/v1/user.route.ts | 8 ++++---- tsconfig.json | 10 +++++++--- 42 files changed, 33 insertions(+), 25 deletions(-) rename src/{components => modules}/auth/auth.controller.ts (93%) rename src/{components => modules}/auth/auth.middleware.ts (100%) rename src/{components => modules}/auth/auth.service.ts (100%) rename src/{components => modules}/auth/auth.test.ts (100%) rename src/{components => modules}/auth/auth.validation.ts (100%) rename src/{components => modules}/email/email.interfaces.ts (100%) rename src/{components => modules}/email/email.service.ts (100%) rename src/{components => modules}/errors/ApiError.ts (100%) rename src/{components => modules}/errors/error.test.ts (100%) rename src/{components => modules}/errors/error.ts (100%) rename src/{components => modules}/jest/setupTestDB.ts (100%) rename src/{components => modules}/paginate/paginate.plugin.ts (100%) rename src/{components => modules}/swagger/components.yaml (100%) rename src/{components => modules}/swagger/swagger.definition.ts (100%) rename src/{components => modules}/toJSON/hideToJSON.plugin.ts (100%) rename src/{components => modules}/toJSON/toJSON.plugin.ts (100%) rename src/{components => modules}/token/token.fixture.ts (100%) rename src/{components => modules}/token/token.interfaces.ts (100%) rename src/{components => modules}/token/token.model.ts (100%) rename src/{components => modules}/token/token.service.ts (100%) rename src/{components => modules}/token/token.types.ts (100%) rename src/{components => modules}/user/user.controller.ts (95%) rename src/{components => modules}/user/user.fixture.ts (100%) rename src/{components => modules}/user/user.interfaces.ts (100%) rename src/{components => modules}/user/user.model.test.ts (100%) rename src/{components => modules}/user/user.model.ts (100%) rename src/{components => modules}/user/user.service.ts (100%) rename src/{components => modules}/user/user.test.ts (100%) rename src/{components => modules}/user/user.validation.ts (100%) rename src/{ => modules}/utils/catchAsync.ts (100%) rename src/{ => modules}/utils/pick.ts (100%) rename src/{ => modules}/utils/rateLimiter.ts (100%) rename src/{components => modules}/validate/custom.validation.ts (100%) rename src/{components => modules}/validate/validate.middleware.ts (95%) diff --git a/.eslintrc.json b/.eslintrc.json index c35fde1..29a6e7a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -24,7 +24,7 @@ "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2018, - "project": ["./tsconfig.json", "./src/tsconfig.json"] + "project": ["./tsconfig.json"] }, "rules": { "no-console": "error", diff --git a/src/app.ts b/src/app.ts index 4c4ebd1..cf7dc0b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -10,9 +10,9 @@ import httpStatus from 'http-status'; import config from './config/config'; import morgan from './config/morgan'; import jwtStrategy from './config/passport'; -import authLimiter from './utils/rateLimiter'; -import ApiError from './components/errors/ApiError'; -import { errorConverter, errorHandler } from './components/errors/error'; +import authLimiter from './modules/utils/rateLimiter'; +import ApiError from './modules/errors/ApiError'; +import { errorConverter, errorHandler } from './modules/errors/error'; import routes from './routes/v1'; const app: Express = express(); diff --git a/src/config/passport.ts b/src/config/passport.ts index 49c3f0b..4a23365 100644 --- a/src/config/passport.ts +++ b/src/config/passport.ts @@ -1,8 +1,8 @@ import { ExtractJwt, Strategy as JwtStrategy } from 'passport-jwt'; -import tokenTypes from '../components/token/token.types'; +import tokenTypes from '../modules/token/token.types'; import config from './config'; -import User from '../components/user/user.model'; -import { IPayload } from '../components/token/token.interfaces'; +import User from '../modules/user/user.model'; +import { IPayload } from '../modules/token/token.interfaces'; const jwtStrategy = new JwtStrategy( { diff --git a/src/custom.d.ts b/src/custom.d.ts index 7221edb..66fe69c 100644 --- a/src/custom.d.ts +++ b/src/custom.d.ts @@ -1,4 +1,4 @@ -import { IUserDoc } from './components/user/user.interfaces'; +import { IUserDoc } from './modules/user/user.interfaces'; declare module 'express-serve-static-core' { export interface Request { diff --git a/src/components/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts similarity index 93% rename from src/components/auth/auth.controller.ts rename to src/modules/auth/auth.controller.ts index 0d114fa..34039f3 100644 --- a/src/components/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -1,8 +1,12 @@ import httpStatus from 'http-status'; import { Request, Response } from 'express'; -import catchAsync from '../../utils/catchAsync'; +import catchAsync from '../utils/catchAsync'; import { registerUser } from '../user/user.service'; -import { generateAuthTokens, generateResetPasswordToken, generateVerifyEmailToken } from '../token/token.service'; +import { + generateAuthTokens, + generateResetPasswordToken, + generateVerifyEmailToken, +} from '../token/token.service'; import { loginUserWithEmailAndPassword, logout, refreshAuth, resetPassword, verifyEmail } from './auth.service'; import { sendResetPasswordEmail, sendVerificationEmail } from '../email/email.service'; import config from '../../config/config'; diff --git a/src/components/auth/auth.middleware.ts b/src/modules/auth/auth.middleware.ts similarity index 100% rename from src/components/auth/auth.middleware.ts rename to src/modules/auth/auth.middleware.ts diff --git a/src/components/auth/auth.service.ts b/src/modules/auth/auth.service.ts similarity index 100% rename from src/components/auth/auth.service.ts rename to src/modules/auth/auth.service.ts diff --git a/src/components/auth/auth.test.ts b/src/modules/auth/auth.test.ts similarity index 100% rename from src/components/auth/auth.test.ts rename to src/modules/auth/auth.test.ts diff --git a/src/components/auth/auth.validation.ts b/src/modules/auth/auth.validation.ts similarity index 100% rename from src/components/auth/auth.validation.ts rename to src/modules/auth/auth.validation.ts diff --git a/src/components/email/email.interfaces.ts b/src/modules/email/email.interfaces.ts similarity index 100% rename from src/components/email/email.interfaces.ts rename to src/modules/email/email.interfaces.ts diff --git a/src/components/email/email.service.ts b/src/modules/email/email.service.ts similarity index 100% rename from src/components/email/email.service.ts rename to src/modules/email/email.service.ts diff --git a/src/components/errors/ApiError.ts b/src/modules/errors/ApiError.ts similarity index 100% rename from src/components/errors/ApiError.ts rename to src/modules/errors/ApiError.ts diff --git a/src/components/errors/error.test.ts b/src/modules/errors/error.test.ts similarity index 100% rename from src/components/errors/error.test.ts rename to src/modules/errors/error.test.ts diff --git a/src/components/errors/error.ts b/src/modules/errors/error.ts similarity index 100% rename from src/components/errors/error.ts rename to src/modules/errors/error.ts diff --git a/src/components/jest/setupTestDB.ts b/src/modules/jest/setupTestDB.ts similarity index 100% rename from src/components/jest/setupTestDB.ts rename to src/modules/jest/setupTestDB.ts diff --git a/src/components/paginate/paginate.plugin.ts b/src/modules/paginate/paginate.plugin.ts similarity index 100% rename from src/components/paginate/paginate.plugin.ts rename to src/modules/paginate/paginate.plugin.ts diff --git a/src/components/swagger/components.yaml b/src/modules/swagger/components.yaml similarity index 100% rename from src/components/swagger/components.yaml rename to src/modules/swagger/components.yaml diff --git a/src/components/swagger/swagger.definition.ts b/src/modules/swagger/swagger.definition.ts similarity index 100% rename from src/components/swagger/swagger.definition.ts rename to src/modules/swagger/swagger.definition.ts diff --git a/src/components/toJSON/hideToJSON.plugin.ts b/src/modules/toJSON/hideToJSON.plugin.ts similarity index 100% rename from src/components/toJSON/hideToJSON.plugin.ts rename to src/modules/toJSON/hideToJSON.plugin.ts diff --git a/src/components/toJSON/toJSON.plugin.ts b/src/modules/toJSON/toJSON.plugin.ts similarity index 100% rename from src/components/toJSON/toJSON.plugin.ts rename to src/modules/toJSON/toJSON.plugin.ts diff --git a/src/components/token/token.fixture.ts b/src/modules/token/token.fixture.ts similarity index 100% rename from src/components/token/token.fixture.ts rename to src/modules/token/token.fixture.ts diff --git a/src/components/token/token.interfaces.ts b/src/modules/token/token.interfaces.ts similarity index 100% rename from src/components/token/token.interfaces.ts rename to src/modules/token/token.interfaces.ts diff --git a/src/components/token/token.model.ts b/src/modules/token/token.model.ts similarity index 100% rename from src/components/token/token.model.ts rename to src/modules/token/token.model.ts diff --git a/src/components/token/token.service.ts b/src/modules/token/token.service.ts similarity index 100% rename from src/components/token/token.service.ts rename to src/modules/token/token.service.ts diff --git a/src/components/token/token.types.ts b/src/modules/token/token.types.ts similarity index 100% rename from src/components/token/token.types.ts rename to src/modules/token/token.types.ts diff --git a/src/components/user/user.controller.ts b/src/modules/user/user.controller.ts similarity index 95% rename from src/components/user/user.controller.ts rename to src/modules/user/user.controller.ts index 8e88770..c7f19f0 100644 --- a/src/components/user/user.controller.ts +++ b/src/modules/user/user.controller.ts @@ -1,9 +1,9 @@ import httpStatus from 'http-status'; import { Request, Response } from 'express'; import mongoose from 'mongoose'; -import catchAsync from '../../utils/catchAsync'; +import catchAsync from '../utils/catchAsync'; import ApiError from '../errors/ApiError'; -import pick from '../../utils/pick'; +import pick from '../utils/pick'; import { createUser, queryUsers, getUserById, updateUserById, deleteUserById } from './user.service'; import { IOptions } from '../paginate/paginate.plugin'; diff --git a/src/components/user/user.fixture.ts b/src/modules/user/user.fixture.ts similarity index 100% rename from src/components/user/user.fixture.ts rename to src/modules/user/user.fixture.ts diff --git a/src/components/user/user.interfaces.ts b/src/modules/user/user.interfaces.ts similarity index 100% rename from src/components/user/user.interfaces.ts rename to src/modules/user/user.interfaces.ts diff --git a/src/components/user/user.model.test.ts b/src/modules/user/user.model.test.ts similarity index 100% rename from src/components/user/user.model.test.ts rename to src/modules/user/user.model.test.ts diff --git a/src/components/user/user.model.ts b/src/modules/user/user.model.ts similarity index 100% rename from src/components/user/user.model.ts rename to src/modules/user/user.model.ts diff --git a/src/components/user/user.service.ts b/src/modules/user/user.service.ts similarity index 100% rename from src/components/user/user.service.ts rename to src/modules/user/user.service.ts diff --git a/src/components/user/user.test.ts b/src/modules/user/user.test.ts similarity index 100% rename from src/components/user/user.test.ts rename to src/modules/user/user.test.ts diff --git a/src/components/user/user.validation.ts b/src/modules/user/user.validation.ts similarity index 100% rename from src/components/user/user.validation.ts rename to src/modules/user/user.validation.ts diff --git a/src/utils/catchAsync.ts b/src/modules/utils/catchAsync.ts similarity index 100% rename from src/utils/catchAsync.ts rename to src/modules/utils/catchAsync.ts diff --git a/src/utils/pick.ts b/src/modules/utils/pick.ts similarity index 100% rename from src/utils/pick.ts rename to src/modules/utils/pick.ts diff --git a/src/utils/rateLimiter.ts b/src/modules/utils/rateLimiter.ts similarity index 100% rename from src/utils/rateLimiter.ts rename to src/modules/utils/rateLimiter.ts diff --git a/src/components/validate/custom.validation.ts b/src/modules/validate/custom.validation.ts similarity index 100% rename from src/components/validate/custom.validation.ts rename to src/modules/validate/custom.validation.ts diff --git a/src/components/validate/validate.middleware.ts b/src/modules/validate/validate.middleware.ts similarity index 95% rename from src/components/validate/validate.middleware.ts rename to src/modules/validate/validate.middleware.ts index fbdd19f..2d69c37 100644 --- a/src/components/validate/validate.middleware.ts +++ b/src/modules/validate/validate.middleware.ts @@ -1,7 +1,7 @@ import { Request, Response, NextFunction } from 'express'; import Joi from 'joi'; import httpStatus from 'http-status'; -import pick from '../../utils/pick'; +import pick from '../utils/pick'; import ApiError from '../errors/ApiError'; const validate = diff --git a/src/routes/v1/auth.route.ts b/src/routes/v1/auth.route.ts index cb8bb86..ccb3ece 100644 --- a/src/routes/v1/auth.route.ts +++ b/src/routes/v1/auth.route.ts @@ -1,6 +1,6 @@ import express, { Router } from 'express'; -import validate from '../../components/validate/validate.middleware'; -import auth from '../../components/auth/auth.middleware'; +import validate from '@/modules/validate/validate.middleware'; +import auth from '@/modules/auth/auth.middleware'; import { forgotPasswordValidator, loginValidator, @@ -9,7 +9,7 @@ import { registerValidator, resetPasswordValidator, verifyEmailValidator, -} from '../../components/auth/auth.validation'; +} from '../../modules/auth/auth.validation'; import { forgotPasswordController, loginController, @@ -19,7 +19,7 @@ import { resetPasswordController, sendVerificationEmailController, verifyEmailController, -} from '../../components/auth/auth.controller'; +} from '../../modules/auth/auth.controller'; const router: Router = express.Router(); diff --git a/src/routes/v1/swagger.route.ts b/src/routes/v1/swagger.route.ts index 4a55bab..6ca479e 100644 --- a/src/routes/v1/swagger.route.ts +++ b/src/routes/v1/swagger.route.ts @@ -1,7 +1,7 @@ import express from 'express'; import swaggerJsdoc from 'swagger-jsdoc'; import swaggerUi from 'swagger-ui-express'; -import swaggerDefinition from '../../components/swagger/swagger.definition'; +import swaggerDefinition from '../../modules/swagger/swagger.definition'; const router = express.Router(); diff --git a/src/routes/v1/user.route.ts b/src/routes/v1/user.route.ts index 000860b..52b73ec 100644 --- a/src/routes/v1/user.route.ts +++ b/src/routes/v1/user.route.ts @@ -1,20 +1,20 @@ import express, { Router } from 'express'; -import validate from '../../components/validate/validate.middleware'; -import auth from '../../components/auth/auth.middleware'; +import validate from '../../modules/validate/validate.middleware'; +import auth from '../../modules/auth/auth.middleware'; import { createUserValidator, deleteUserValidator, getUsersValidator, getUserValidator, updateUserValidator, -} from '../../components/user/user.validation'; +} from '../../modules/user/user.validation'; import { createUserController, deleteUserController, getUserController, getUsersController, updateUserController, -} from '../../components/user/user.controller'; +} from '../../modules/user/user.controller'; const router: Router = express.Router(); diff --git a/tsconfig.json b/tsconfig.json index e14a228..802b89d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,9 +26,13 @@ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ "rootDir": ".", /* Specify the root folder within your source files. */ - // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + "paths": { + "@/modules/*": [ + "src/modules/*" + ], + }, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */