From c5537b3230646cabd335199fb4807ef8b67fc6ff Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Sun, 10 Mar 2024 12:49:51 +0300 Subject: [PATCH] convert project from microservices to rest apis --- apps/auth/src/auth.controller.spec.ts | 22 ------ apps/auth/src/auth.controller.ts | 12 --- apps/auth/src/auth.module.ts | 18 ----- apps/auth/src/auth.service.ts | 8 -- apps/auth/src/config/index.ts | 4 - apps/auth/src/config/jwt.config.ts | 11 --- .../src/modules/authentication/dtos/index.ts | 4 - apps/auth/test/app.e2e-spec.ts | 24 ------ apps/auth/test/jest-e2e.json | 9 --- apps/auth/tsconfig.app.json | 9 --- apps/backend/src/backend.controller.ts | 12 --- apps/backend/src/backend.module.ts | 20 ----- apps/backend/src/backend.service.ts | 8 -- apps/backend/src/config/app.config.ts | 9 --- apps/backend/src/config/auth.config.ts | 10 --- apps/backend/src/config/index.ts | 4 - apps/backend/src/main.ts | 36 --------- .../src/modules/user/controllers/index.ts | 1 - apps/backend/src/modules/user/dtos/index.ts | 1 - .../src/modules/user/services/index.ts | 1 - apps/backend/tsconfig.app.json | 9 --- libs/common/src/auth/auth.module.ts | 2 +- libs/common/src/auth/services/auth.service.ts | 6 +- .../src/auth/strategies/jwt.strategy.ts | 2 +- libs/common/src/common.module.ts | 4 +- libs/common/src/config/email.config.ts | 2 +- libs/common/src/database/database.module.ts | 3 +- .../strategies/snack-naming.strategy.ts | 1 - libs/common/src/guards/jwt.auth.guard.ts | 2 +- libs/common/src/helper/services/index.ts | 2 +- .../common/src/modules/abstract/dtos/index.ts | 2 +- .../abstract/entities/abstract.entity.ts | 6 +- .../src/modules/session/dtos/session.dto.ts | 1 - .../src/modules/session/entities/index.ts | 2 +- .../session/entities/session.entity.ts | 2 +- .../common/src/modules/user-otp/dtos/index.ts | 2 +- .../src/modules/user-otp/dtos/user-otp.dto.ts | 2 +- .../src/modules/user-otp/entities/index.ts | 2 +- .../user-otp/entities/user-otp.entity.ts | 6 +- .../src/modules/user/entities/user.entity.ts | 2 +- .../common/src/response/response.decorator.ts | 2 +- .../src/response/response.interceptor.ts | 8 +- libs/common/src/util/types.ts | 79 +++++++++---------- .../src/util/user-auth.swagger.utils.ts | 4 +- nest-cli.json | 42 +++------- package.json | 9 +-- src/app.module.ts | 17 ++++ .../auth/auth.module.ts | 10 +-- .../constants/login.response.constant.ts | 0 .../controllers/authentication.controller.ts | 0 .../auth}/controllers/index.ts | 0 .../auth}/controllers/user-auth.controller.ts | 4 +- src/auth/dtos/index.ts | 4 + .../auth}/dtos/user-auth.dto.ts | 16 ++-- .../auth}/dtos/user-login.dto.ts | 0 .../auth}/dtos/user-otp.dto.ts | 2 +- .../auth}/dtos/user-password.dto.ts | 0 .../auth}/services/authentication.service.ts | 1 - .../auth}/services/index.ts | 0 .../auth}/services/user-auth.service.ts | 16 ++-- {apps/auth/src => src}/config/app.config.ts | 0 {apps/auth/src => src}/config/auth.config.ts | 0 src/config/index.ts | 4 + .../backend/src => src}/config/jwt.config.ts | 2 +- {apps/auth/src => src}/main.ts | 11 ++- src/users/controllers/index.ts | 1 + .../users}/controllers/user.controller.ts | 7 +- src/users/dtos/index.ts | 1 + .../user => src/users}/dtos/user.list.dto.ts | 15 ++-- src/users/services/index.ts | 1 + .../users}/services/user.service.ts | 0 .../modules/user => src/users}/user.module.ts | 0 72 files changed, 155 insertions(+), 384 deletions(-) delete mode 100644 apps/auth/src/auth.controller.spec.ts delete mode 100644 apps/auth/src/auth.controller.ts delete mode 100644 apps/auth/src/auth.module.ts delete mode 100644 apps/auth/src/auth.service.ts delete mode 100644 apps/auth/src/config/index.ts delete mode 100644 apps/auth/src/config/jwt.config.ts delete mode 100644 apps/auth/src/modules/authentication/dtos/index.ts delete mode 100644 apps/auth/test/app.e2e-spec.ts delete mode 100644 apps/auth/test/jest-e2e.json delete mode 100644 apps/auth/tsconfig.app.json delete mode 100644 apps/backend/src/backend.controller.ts delete mode 100644 apps/backend/src/backend.module.ts delete mode 100644 apps/backend/src/backend.service.ts delete mode 100644 apps/backend/src/config/app.config.ts delete mode 100644 apps/backend/src/config/auth.config.ts delete mode 100644 apps/backend/src/config/index.ts delete mode 100644 apps/backend/src/main.ts delete mode 100644 apps/backend/src/modules/user/controllers/index.ts delete mode 100644 apps/backend/src/modules/user/dtos/index.ts delete mode 100644 apps/backend/src/modules/user/services/index.ts delete mode 100644 apps/backend/tsconfig.app.json create mode 100644 src/app.module.ts rename apps/auth/src/modules/authentication/authentication.module.ts => src/auth/auth.module.ts (61%) rename {apps/auth/src/modules/authentication => src/auth}/constants/login.response.constant.ts (100%) rename {apps/auth/src/modules/authentication => src/auth}/controllers/authentication.controller.ts (100%) rename {apps/auth/src/modules/authentication => src/auth}/controllers/index.ts (100%) rename {apps/auth/src/modules/authentication => src/auth}/controllers/user-auth.controller.ts (93%) create mode 100644 src/auth/dtos/index.ts rename {apps/auth/src/modules/authentication => src/auth}/dtos/user-auth.dto.ts (70%) rename {apps/auth/src/modules/authentication => src/auth}/dtos/user-login.dto.ts (100%) rename {apps/auth/src/modules/authentication => src/auth}/dtos/user-otp.dto.ts (83%) rename {apps/auth/src/modules/authentication => src/auth}/dtos/user-password.dto.ts (100%) rename {apps/auth/src/modules/authentication => src/auth}/services/authentication.service.ts (98%) rename {apps/auth/src/modules/authentication => src/auth}/services/index.ts (100%) rename {apps/auth/src/modules/authentication => src/auth}/services/user-auth.service.ts (85%) rename {apps/auth/src => src}/config/app.config.ts (100%) rename {apps/auth/src => src}/config/auth.config.ts (100%) create mode 100644 src/config/index.ts rename {apps/backend/src => src}/config/jwt.config.ts (98%) rename {apps/auth/src => src}/main.ts (79%) create mode 100644 src/users/controllers/index.ts rename {apps/backend/src/modules/user => src/users}/controllers/user.controller.ts (65%) create mode 100644 src/users/dtos/index.ts rename {apps/backend/src/modules/user => src/users}/dtos/user.list.dto.ts (61%) create mode 100644 src/users/services/index.ts rename {apps/backend/src/modules/user => src/users}/services/user.service.ts (100%) rename {apps/backend/src/modules/user => src/users}/user.module.ts (100%) diff --git a/apps/auth/src/auth.controller.spec.ts b/apps/auth/src/auth.controller.spec.ts deleted file mode 100644 index d59df3e..0000000 --- a/apps/auth/src/auth.controller.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AuthController } from './auth.controller'; -import { AuthService } from './auth.service'; - -describe('AuthController', () => { - let authController: AuthController; - - beforeEach(async () => { - const app: TestingModule = await Test.createTestingModule({ - controllers: [AuthController], - providers: [AuthService], - }).compile(); - - authController = app.get(AuthController); - }); - - describe('root', () => { - it('should return "Hello World!"', () => { - expect(authController.getHello()).toBe('Hello World!'); - }); - }); -}); diff --git a/apps/auth/src/auth.controller.ts b/apps/auth/src/auth.controller.ts deleted file mode 100644 index 758fe3b..0000000 --- a/apps/auth/src/auth.controller.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Controller, Get } from '@nestjs/common'; -import { AuthService } from './auth.service'; - -@Controller() -export class AuthController { - constructor(private readonly authService: AuthService) {} - - @Get() - getHello(): string { - return this.authService.getHello(); - } -} diff --git a/apps/auth/src/auth.module.ts b/apps/auth/src/auth.module.ts deleted file mode 100644 index 1701fc9..0000000 --- a/apps/auth/src/auth.module.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Module } from '@nestjs/common'; -import { AuthController } from './auth.controller'; -import { AuthService } from './auth.service'; -import { ConfigModule } from '@nestjs/config'; -import config from './config'; -import { AuthenticationModule } from './modules/authentication/authentication.module'; -import { AuthenticationController } from './modules/authentication/controllers/authentication.controller'; -@Module({ - imports: [ - ConfigModule.forRoot({ - load: config, - }), - AuthenticationModule, - ], - controllers: [AuthController,AuthenticationController], - providers: [AuthService], -}) -export class AuthModule {} diff --git a/apps/auth/src/auth.service.ts b/apps/auth/src/auth.service.ts deleted file mode 100644 index 53400c8..0000000 --- a/apps/auth/src/auth.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -@Injectable() -export class AuthService { - getHello(): string { - return 'Hello World!'; - } -} diff --git a/apps/auth/src/config/index.ts b/apps/auth/src/config/index.ts deleted file mode 100644 index f1ccc51..0000000 --- a/apps/auth/src/config/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import AuthConfig from './auth.config'; -import AppConfig from './app.config' - -export default [AuthConfig,AppConfig]; diff --git a/apps/auth/src/config/jwt.config.ts b/apps/auth/src/config/jwt.config.ts deleted file mode 100644 index 17a1e92..0000000 --- a/apps/auth/src/config/jwt.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { registerAs } from '@nestjs/config'; - -export default registerAs( - 'jwt', - (): Record => ({ - secret: process.env.JWT_SECRET, - expire_time: process.env.JWT_EXPIRE_TIME, - secret_refresh: process.env.JWT_SECRET_REFRESH, - expire_refresh: process.env.JWT_EXPIRE_TIME_REFRESH, - }) -); \ No newline at end of file diff --git a/apps/auth/src/modules/authentication/dtos/index.ts b/apps/auth/src/modules/authentication/dtos/index.ts deleted file mode 100644 index 069bcc1..0000000 --- a/apps/auth/src/modules/authentication/dtos/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './user-auth.dto' -export * from './user-login.dto' -export * from './user-otp.dto' -export * from './user-password.dto' \ No newline at end of file diff --git a/apps/auth/test/app.e2e-spec.ts b/apps/auth/test/app.e2e-spec.ts deleted file mode 100644 index 6eb0624..0000000 --- a/apps/auth/test/app.e2e-spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; -import * as request from 'supertest'; -import { AuthModule } from './../src/auth.module'; - -describe('AuthController (e2e)', () => { - let app: INestApplication; - - beforeEach(async () => { - const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [AuthModule], - }).compile(); - - app = moduleFixture.createNestApplication(); - await app.init(); - }); - - it('/ (GET)', () => { - return request(app.getHttpServer()) - .get('/') - .expect(200) - .expect('Hello World!'); - }); -}); diff --git a/apps/auth/test/jest-e2e.json b/apps/auth/test/jest-e2e.json deleted file mode 100644 index e9d912f..0000000 --- a/apps/auth/test/jest-e2e.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "moduleFileExtensions": ["js", "json", "ts"], - "rootDir": ".", - "testEnvironment": "node", - "testRegex": ".e2e-spec.ts$", - "transform": { - "^.+\\.(t|j)s$": "ts-jest" - } -} diff --git a/apps/auth/tsconfig.app.json b/apps/auth/tsconfig.app.json deleted file mode 100644 index 01d9c9a..0000000 --- a/apps/auth/tsconfig.app.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "declaration": false, - "outDir": "../../dist/apps/auth" - }, - "include": ["src/**/*"], - "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] -} diff --git a/apps/backend/src/backend.controller.ts b/apps/backend/src/backend.controller.ts deleted file mode 100644 index 6fc2a0e..0000000 --- a/apps/backend/src/backend.controller.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Controller, Get } from '@nestjs/common'; -import { AppService } from './backend.service'; - -@Controller() -export class AppController { - constructor(private readonly appService: AppService) {} - - @Get('healthcheck') - getHello(): string { - return this.appService.healthcheck(); - } -} diff --git a/apps/backend/src/backend.module.ts b/apps/backend/src/backend.module.ts deleted file mode 100644 index 9afbd2f..0000000 --- a/apps/backend/src/backend.module.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Module } from '@nestjs/common'; -import { AppController } from './backend.controller'; -import { AppService } from './backend.service'; -import { UserModule } from './modules/user/user.module'; -import { ConfigModule } from '@nestjs/config'; -import config from './config'; -import { CommonModule } from '@app/common'; - -@Module({ - imports: [ - ConfigModule.forRoot({ - load: config, - }), - UserModule, - CommonModule, - ], - controllers: [AppController], - providers: [AppService], -}) -export class BackendModule {} diff --git a/apps/backend/src/backend.service.ts b/apps/backend/src/backend.service.ts deleted file mode 100644 index 4f15a30..0000000 --- a/apps/backend/src/backend.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -@Injectable() -export class AppService { - healthcheck(): string { - return 'Healthcheck!'; - } -} diff --git a/apps/backend/src/config/app.config.ts b/apps/backend/src/config/app.config.ts deleted file mode 100644 index 0ea13da..0000000 --- a/apps/backend/src/config/app.config.ts +++ /dev/null @@ -1,9 +0,0 @@ -export default () => ({ - DB_HOST: process.env.AZURE_POSTGRESQL_HOST, - DB_PORT: process.env.AZURE_POSTGRESQL_PORT, - DB_USER: process.env.AZURE_POSTGRESQL_USER, - DB_PASSWORD: process.env.AZURE_POSTGRESQL_PASSWORD, - DB_NAME: process.env.AZURE_POSTGRESQL_DATABASE, - DB_SYNC: process.env.AZURE_POSTGRESQL_SYNC, - DB_SSL: process.env.AZURE_POSTGRESQL_SSL, -}); diff --git a/apps/backend/src/config/auth.config.ts b/apps/backend/src/config/auth.config.ts deleted file mode 100644 index 3a3f870..0000000 --- a/apps/backend/src/config/auth.config.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { registerAs } from '@nestjs/config'; - -export default registerAs( - 'auth-config', - (): Record => ({ - //DEVICE_ID: process.env.DEVICE_ID, - ACCESS_KEY: process.env.ACCESS_KEY, - SECRET_KEY: process.env.SECRET_KEY, - }), -); diff --git a/apps/backend/src/config/index.ts b/apps/backend/src/config/index.ts deleted file mode 100644 index f8720ad..0000000 --- a/apps/backend/src/config/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import AuthConfig from './auth.config'; -import AppConfig from './app.config' -import JwtConfig from './jwt.config' -export default [AuthConfig,AppConfig,JwtConfig]; diff --git a/apps/backend/src/main.ts b/apps/backend/src/main.ts deleted file mode 100644 index 156de0f..0000000 --- a/apps/backend/src/main.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { NestFactory } from '@nestjs/core'; -import { BackendModule } from './backend.module'; -import rateLimit from 'express-rate-limit'; -import helmet from 'helmet'; -import { ValidationPipe } from '@nestjs/common'; - -async function bootstrap() { - const app = await NestFactory.create(BackendModule); - - // Enable 'trust proxy' setting - app.use((req, res, next) => { - app.getHttpAdapter().getInstance().set('trust proxy', 1); - next(); - }); - - - app.enableCors(); - - app.use( - rateLimit({ - windowMs: 5 * 60 * 1000, // 5 minutes - max: 500, // limit each IP to 500 requests per windowMs - }), - ); - - app.use( - helmet({ - contentSecurityPolicy: false, - }), - ); - app.useGlobalPipes(new ValidationPipe()); - await app.listen(4000); -} - -console.log('Starting backend at port 7000...'); -bootstrap(); diff --git a/apps/backend/src/modules/user/controllers/index.ts b/apps/backend/src/modules/user/controllers/index.ts deleted file mode 100644 index bb9c2b0..0000000 --- a/apps/backend/src/modules/user/controllers/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './user.controller' \ No newline at end of file diff --git a/apps/backend/src/modules/user/dtos/index.ts b/apps/backend/src/modules/user/dtos/index.ts deleted file mode 100644 index ad0550f..0000000 --- a/apps/backend/src/modules/user/dtos/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './user.list.dto' \ No newline at end of file diff --git a/apps/backend/src/modules/user/services/index.ts b/apps/backend/src/modules/user/services/index.ts deleted file mode 100644 index 5a6a9db..0000000 --- a/apps/backend/src/modules/user/services/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './user.service' \ No newline at end of file diff --git a/apps/backend/tsconfig.app.json b/apps/backend/tsconfig.app.json deleted file mode 100644 index ffc1047..0000000 --- a/apps/backend/tsconfig.app.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "declaration": false, - "outDir": "../../dist/apps/backend" - }, - "include": ["src/**/*"], - "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] -} diff --git a/libs/common/src/auth/auth.module.ts b/libs/common/src/auth/auth.module.ts index 64de838..236fea3 100644 --- a/libs/common/src/auth/auth.module.ts +++ b/libs/common/src/auth/auth.module.ts @@ -22,7 +22,7 @@ import { UserRepository } from '../modules/user/repositories'; }), HelperModule, ], - providers: [JwtStrategy, UserSessionRepository,AuthService,UserRepository], + providers: [JwtStrategy, UserSessionRepository, AuthService, UserRepository], exports: [AuthService], }) export class AuthModule {} diff --git a/libs/common/src/auth/services/auth.service.ts b/libs/common/src/auth/services/auth.service.ts index 2d3c0ee..d305d94 100644 --- a/libs/common/src/auth/services/auth.service.ts +++ b/libs/common/src/auth/services/auth.service.ts @@ -1,9 +1,9 @@ import { BadRequestException, Injectable } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { HelperHashService } from '../../helper/services'; -import { UserRepository } from '@app/common/modules/user/repositories'; -import { UserSessionRepository } from '@app/common/modules/session/repositories/session.repository'; -import { UserSessionEntity } from '@app/common/modules/session/entities'; +import { UserRepository } from '../../../../common/src/modules/user/repositories'; +import { UserSessionRepository } from '../../../../common/src/modules/session/repositories/session.repository'; +import { UserSessionEntity } from '../../../../common/src/modules/session/entities'; @Injectable() export class AuthService { diff --git a/libs/common/src/auth/strategies/jwt.strategy.ts b/libs/common/src/auth/strategies/jwt.strategy.ts index 833f42c..ac43543 100644 --- a/libs/common/src/auth/strategies/jwt.strategy.ts +++ b/libs/common/src/auth/strategies/jwt.strategy.ts @@ -2,7 +2,7 @@ import { ConfigService } from '@nestjs/config'; import { ExtractJwt, Strategy } from 'passport-jwt'; import { PassportStrategy } from '@nestjs/passport'; import { BadRequestException, Injectable } from '@nestjs/common'; -import { UserSessionRepository } from '@app/common/modules/session/repositories/session.repository'; +import { UserSessionRepository } from '../../../src/modules/session/repositories/session.repository'; import { AuthInterface } from '../interfaces/auth.interface'; @Injectable() diff --git a/libs/common/src/common.module.ts b/libs/common/src/common.module.ts index 62ea3a4..e9d3f01 100644 --- a/libs/common/src/common.module.ts +++ b/libs/common/src/common.module.ts @@ -8,8 +8,8 @@ import config from './config'; import { EmailService } from './util/email.service'; @Module({ - providers: [CommonService,EmailService], - exports: [CommonService, HelperModule, AuthModule,EmailService], + providers: [CommonService, EmailService], + exports: [CommonService, HelperModule, AuthModule, EmailService], imports: [ ConfigModule.forRoot({ load: config, diff --git a/libs/common/src/config/email.config.ts b/libs/common/src/config/email.config.ts index 199d084..bd249e7 100644 --- a/libs/common/src/config/email.config.ts +++ b/libs/common/src/config/email.config.ts @@ -5,7 +5,7 @@ export default registerAs( (): Record => ({ SMTP_HOST: process.env.SMTP_HOST, SMTP_PORT: parseInt(process.env.SMTP_PORT), - SMTP_SECURE: process.env.SMTP_SECURE === 'true', + SMTP_SECURE: process.env.SMTP_SECURE === 'true', SMTP_USER: process.env.SMTP_USER, SMTP_PASSWORD: process.env.SMTP_PASSWORD, }), diff --git a/libs/common/src/database/database.module.ts b/libs/common/src/database/database.module.ts index a80d929..c3aafad 100644 --- a/libs/common/src/database/database.module.ts +++ b/libs/common/src/database/database.module.ts @@ -19,7 +19,7 @@ import { UserOtpEntity } from '../modules/user-otp/entities'; username: configService.get('DB_USER'), password: configService.get('DB_PASSWORD'), database: configService.get('DB_NAME'), - entities: [UserEntity, UserSessionEntity,UserOtpEntity], + entities: [UserEntity, UserSessionEntity, UserOtpEntity], namingStrategy: new SnakeNamingStrategy(), synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))), logging: true, @@ -32,7 +32,6 @@ import { UserOtpEntity } from '../modules/user-otp/entities'; }, continuationLocalStorage: true, ssl: Boolean(JSON.parse(configService.get('DB_SSL'))), - }), }), ], diff --git a/libs/common/src/database/strategies/snack-naming.strategy.ts b/libs/common/src/database/strategies/snack-naming.strategy.ts index fed7e37..4953cc2 100644 --- a/libs/common/src/database/strategies/snack-naming.strategy.ts +++ b/libs/common/src/database/strategies/snack-naming.strategy.ts @@ -32,7 +32,6 @@ export class SnakeNamingStrategy firstTableName: string, secondTableName: string, firstPropertyName: any, - _secondPropertyName: string, ): string { return snakeCase( firstTableName + diff --git a/libs/common/src/guards/jwt.auth.guard.ts b/libs/common/src/guards/jwt.auth.guard.ts index 1b57b77..a0ccdea 100644 --- a/libs/common/src/guards/jwt.auth.guard.ts +++ b/libs/common/src/guards/jwt.auth.guard.ts @@ -2,7 +2,7 @@ import { UnauthorizedException } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; export class JwtAuthGuard extends AuthGuard('jwt') { - handleRequest(err, user, info) { + handleRequest(err, user) { if (err || !user) { throw err || new UnauthorizedException(); } diff --git a/libs/common/src/helper/services/index.ts b/libs/common/src/helper/services/index.ts index f3f4682..0ede816 100644 --- a/libs/common/src/helper/services/index.ts +++ b/libs/common/src/helper/services/index.ts @@ -1 +1 @@ -export * from './helper.hash.service' \ No newline at end of file +export * from './helper.hash.service'; diff --git a/libs/common/src/modules/abstract/dtos/index.ts b/libs/common/src/modules/abstract/dtos/index.ts index fd297f8..8876774 100644 --- a/libs/common/src/modules/abstract/dtos/index.ts +++ b/libs/common/src/modules/abstract/dtos/index.ts @@ -1 +1 @@ -export * from './abstract.dto' \ No newline at end of file +export * from './abstract.dto'; diff --git a/libs/common/src/modules/abstract/entities/abstract.entity.ts b/libs/common/src/modules/abstract/entities/abstract.entity.ts index c065c9b..bc27899 100644 --- a/libs/common/src/modules/abstract/entities/abstract.entity.ts +++ b/libs/common/src/modules/abstract/entities/abstract.entity.ts @@ -8,11 +8,11 @@ import { } from 'typeorm'; import { AbstractDto } from '../dtos'; -import { Constructor } from '@app/common/util/types'; +import { Constructor } from '../../../../../common/src/util/types'; export abstract class AbstractEntity< T extends AbstractDto = AbstractDto, - O = never + O = never, > { @PrimaryGeneratedColumn('increment') @Exclude() @@ -38,7 +38,7 @@ export abstract class AbstractEntity< // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (!dtoClass) { throw new Error( - `You need to use @UseDto on class (${this.constructor.name}) be able to call toDto function` + `You need to use @UseDto on class (${this.constructor.name}) be able to call toDto function`, ); } diff --git a/libs/common/src/modules/session/dtos/session.dto.ts b/libs/common/src/modules/session/dtos/session.dto.ts index 7005249..8e7c052 100644 --- a/libs/common/src/modules/session/dtos/session.dto.ts +++ b/libs/common/src/modules/session/dtos/session.dto.ts @@ -22,5 +22,4 @@ export class SessionDto { @IsBoolean() @IsNotEmpty() public isLoggedOut: boolean; - } diff --git a/libs/common/src/modules/session/entities/index.ts b/libs/common/src/modules/session/entities/index.ts index 737110c..626a6a7 100644 --- a/libs/common/src/modules/session/entities/index.ts +++ b/libs/common/src/modules/session/entities/index.ts @@ -1 +1 @@ -export * from './session.entity' \ No newline at end of file +export * from './session.entity'; diff --git a/libs/common/src/modules/session/entities/session.entity.ts b/libs/common/src/modules/session/entities/session.entity.ts index a4518f2..d16ad2b 100644 --- a/libs/common/src/modules/session/entities/session.entity.ts +++ b/libs/common/src/modules/session/entities/session.entity.ts @@ -5,7 +5,7 @@ import { SessionDto } from '../dtos/session.dto'; @Entity({ name: 'userSession' }) export class UserSessionEntity extends AbstractEntity { @Column({ - type: 'uuid', + type: 'uuid', default: () => 'gen_random_uuid()', nullable: false, }) diff --git a/libs/common/src/modules/user-otp/dtos/index.ts b/libs/common/src/modules/user-otp/dtos/index.ts index 2848db5..114762e 100644 --- a/libs/common/src/modules/user-otp/dtos/index.ts +++ b/libs/common/src/modules/user-otp/dtos/index.ts @@ -1 +1 @@ -export * from './user-otp.dto' \ No newline at end of file +export * from './user-otp.dto'; diff --git a/libs/common/src/modules/user-otp/dtos/user-otp.dto.ts b/libs/common/src/modules/user-otp/dtos/user-otp.dto.ts index e98c700..febdacb 100644 --- a/libs/common/src/modules/user-otp/dtos/user-otp.dto.ts +++ b/libs/common/src/modules/user-otp/dtos/user-otp.dto.ts @@ -4,7 +4,7 @@ export class UserOtpDto { @IsString() @IsNotEmpty() public uuid: string; - + @IsString() @IsNotEmpty() public email: string; diff --git a/libs/common/src/modules/user-otp/entities/index.ts b/libs/common/src/modules/user-otp/entities/index.ts index f1c339e..d09957f 100644 --- a/libs/common/src/modules/user-otp/entities/index.ts +++ b/libs/common/src/modules/user-otp/entities/index.ts @@ -1 +1 @@ -export * from './user-otp.entity' \ No newline at end of file +export * from './user-otp.entity'; diff --git a/libs/common/src/modules/user-otp/entities/user-otp.entity.ts b/libs/common/src/modules/user-otp/entities/user-otp.entity.ts index 6bd1540..454a3b1 100644 --- a/libs/common/src/modules/user-otp/entities/user-otp.entity.ts +++ b/libs/common/src/modules/user-otp/entities/user-otp.entity.ts @@ -1,13 +1,13 @@ import { Column, Entity } from 'typeorm'; import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { UserOtpDto } from '../dtos'; -import { OtpType } from '@app/common/constants/otp-type.enum'; +import { OtpType } from '../../../../src/constants/otp-type.enum'; @Entity({ name: 'user-otp' }) export class UserOtpEntity extends AbstractEntity { @Column({ - type: 'uuid', - default: () => 'gen_random_uuid()', + type: 'uuid', + default: () => 'gen_random_uuid()', nullable: false, }) public uuid: string; diff --git a/libs/common/src/modules/user/entities/user.entity.ts b/libs/common/src/modules/user/entities/user.entity.ts index c168c11..63f2185 100644 --- a/libs/common/src/modules/user/entities/user.entity.ts +++ b/libs/common/src/modules/user/entities/user.entity.ts @@ -5,7 +5,7 @@ import { AbstractEntity } from '../../abstract/entities/abstract.entity'; @Entity({ name: 'user' }) export class UserEntity extends AbstractEntity { @Column({ - type: 'uuid', + type: 'uuid', default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value nullable: false, }) diff --git a/libs/common/src/response/response.decorator.ts b/libs/common/src/response/response.decorator.ts index 407f4e9..aab6ec9 100644 --- a/libs/common/src/response/response.decorator.ts +++ b/libs/common/src/response/response.decorator.ts @@ -1,4 +1,4 @@ import { SetMetadata } from '@nestjs/common'; export const ResponseMessage = (message: string) => - SetMetadata('response_message', message); \ No newline at end of file + SetMetadata('response_message', message); diff --git a/libs/common/src/response/response.interceptor.ts b/libs/common/src/response/response.interceptor.ts index 7186e9c..6a456f2 100644 --- a/libs/common/src/response/response.interceptor.ts +++ b/libs/common/src/response/response.interceptor.ts @@ -1,5 +1,5 @@ export interface Response { - statusCode: number; - message: string; - data?: T; - } \ No newline at end of file + statusCode: number; + message: string; + data?: T; +} diff --git a/libs/common/src/util/types.ts b/libs/common/src/util/types.ts index c04b857..49a9efe 100644 --- a/libs/common/src/util/types.ts +++ b/libs/common/src/util/types.ts @@ -1,46 +1,45 @@ export type Constructor = new ( - ...arguments_: Arguments - ) => T; - - export type Plain = T; - export type Optional = T | undefined; - export type Nullable = T | null; - - export type PathImpl = Key extends string - ? T[Key] extends Record - ? - | `${Key}.${PathImpl> & - string}` - | `${Key}.${Exclude & string}` + ...arguments_: Arguments +) => T; + +export type Plain = T; +export type Optional = T | undefined; +export type Nullable = T | null; + +export type PathImpl = Key extends string + ? T[Key] extends Record + ? + | `${Key}.${PathImpl> & + string}` + | `${Key}.${Exclude & string}` + : never + : never; + +export type PathImpl2 = PathImpl | keyof T; + +export type Path = keyof T extends string + ? PathImpl2 extends string | keyof T + ? PathImpl2 + : keyof T + : never; + +export type PathValue< + T, + P extends Path, +> = P extends `${infer Key}.${infer Rest}` + ? Key extends keyof T + ? Rest extends Path + ? PathValue : never - : never; - - export type PathImpl2 = PathImpl | keyof T; - - export type Path = keyof T extends string - ? PathImpl2 extends string | keyof T - ? PathImpl2 - : keyof T - : never; - - export type PathValue< - T, - P extends Path - > = P extends `${infer Key}.${infer Rest}` - ? Key extends keyof T - ? Rest extends Path - ? PathValue - : never - : never - : P extends keyof T + : never + : P extends keyof T ? T[P] : never; - - export type KeyOfType = { - [P in keyof Required]: Required[P] extends U - ? P - : Required[P] extends U[] + +export type KeyOfType = { + [P in keyof Required]: Required[P] extends U + ? P + : Required[P] extends U[] ? P : never; - }[keyof Entity]; - \ No newline at end of file +}[keyof Entity]; diff --git a/libs/common/src/util/user-auth.swagger.utils.ts b/libs/common/src/util/user-auth.swagger.utils.ts index faf1798..f6f053a 100644 --- a/libs/common/src/util/user-auth.swagger.utils.ts +++ b/libs/common/src/util/user-auth.swagger.utils.ts @@ -3,7 +3,7 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; export function setupSwaggerAuthentication(app: INestApplication): void { const options = new DocumentBuilder() - .setTitle('Authentication-Service') + .setTitle('APIs Documentation') .addBearerAuth({ type: 'http', scheme: 'bearer', @@ -13,7 +13,7 @@ export function setupSwaggerAuthentication(app: INestApplication): void { .build(); const document = SwaggerModule.createDocument(app, options); - SwaggerModule.setup('api/authentication/documentation', app, document, { + SwaggerModule.setup('api', app, document, { swaggerOptions: { persistAuthorization: true, }, diff --git a/nest-cli.json b/nest-cli.json index e6cd962..cf7551a 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -1,41 +1,19 @@ { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", - "sourceRoot": "apps/backend/src", + "sourceRoot": "src", "compilerOptions": { "deleteOutDir": true, "webpack": true, - "tsConfigPath": "apps/backend/tsconfig.app.json" + "tsConfigPath": "tsconfig.build.json" }, - "monorepo": true, - "root": "apps/backend", - "projects": { - "backend": { - "type": "application", - "root": "apps/backend", - "entryFile": "main", - "sourceRoot": "apps/backend/src", - "compilerOptions": { - "tsConfigPath": "apps/backend/tsconfig.app.json" - } - }, - "auth": { - "type": "application", - "root": "apps/auth", - "entryFile": "main", - "sourceRoot": "apps/auth/src", - "compilerOptions": { - "tsConfigPath": "apps/auth/tsconfig.app.json" - } - }, - "common": { - "type": "library", - "root": "libs/common", - "entryFile": "index", - "sourceRoot": "libs/common/src", - "compilerOptions": { - "tsConfigPath": "libs/common/tsconfig.lib.json" - } + "common": { + "type": "library", + "root": "libs/common", + "entryFile": "index", + "sourceRoot": "libs/common/src", + "compilerOptions": { + "tsConfigPath": "libs/common/tsconfig.lib.json" } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index b88e486..1cd47fb 100644 --- a/package.json +++ b/package.json @@ -10,19 +10,14 @@ "format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"", "start": "npx nest start", "start:dev": "npx nest start --watch", - "backend:dev": "npx nest start backend --watch", - "auth:dev": "npx nest start auth --watch", "start:debug": "npx nest start --debug --watch", - "start:prod": "node dist/apps/backend/main", + "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --config ./apps/backend/test/jest-e2e.json", - "start:auth": "npx nest start auth", - "start:backend": "npx nest start backend", - "start:all": "concurrently \"npm run start:auth\" \"npm run start:backend\"" + "test:e2e": "jest --config ./apps/backend/test/jest-e2e.json" }, "dependencies": { "@nestjs/common": "^10.0.0", diff --git a/src/app.module.ts b/src/app.module.ts new file mode 100644 index 0000000..ff8439b --- /dev/null +++ b/src/app.module.ts @@ -0,0 +1,17 @@ +import { Module } from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; +import config from './config'; +import { AuthenticationModule } from './auth/auth.module'; +import { AuthenticationController } from './auth/controllers/authentication.controller'; +import { UserModule } from './users/user.module'; +@Module({ + imports: [ + ConfigModule.forRoot({ + load: config, + }), + AuthenticationModule, + UserModule, + ], + controllers: [AuthenticationController], +}) +export class AuthModule {} diff --git a/apps/auth/src/modules/authentication/authentication.module.ts b/src/auth/auth.module.ts similarity index 61% rename from apps/auth/src/modules/authentication/authentication.module.ts rename to src/auth/auth.module.ts index 11069eb..2165d5e 100644 --- a/apps/auth/src/modules/authentication/authentication.module.ts +++ b/src/auth/auth.module.ts @@ -2,13 +2,13 @@ import { Module } from '@nestjs/common'; import { AuthenticationController } from './controllers/authentication.controller'; import { AuthenticationService } from './services/authentication.service'; import { ConfigModule } from '@nestjs/config'; -import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module'; -import { CommonModule } from '@app/common'; +import { UserRepositoryModule } from '../../libs/common/src/modules/user/user.repository.module'; +import { CommonModule } from '../../libs/common/src'; import { UserAuthController } from './controllers'; import { UserAuthService } from './services'; -import { UserRepository } from '@app/common/modules/user/repositories'; -import { UserSessionRepository } from '@app/common/modules/session/repositories/session.repository'; -import { UserOtpRepository } from '@app/common/modules/user-otp/repositories/user-otp.repository'; +import { UserRepository } from '../../libs/common/src/modules/user/repositories'; +import { UserSessionRepository } from '../../libs/common/src/modules/session/repositories/session.repository'; +import { UserOtpRepository } from '../../libs/common/src/modules/user-otp/repositories/user-otp.repository'; @Module({ imports: [ConfigModule, UserRepositoryModule, CommonModule], diff --git a/apps/auth/src/modules/authentication/constants/login.response.constant.ts b/src/auth/constants/login.response.constant.ts similarity index 100% rename from apps/auth/src/modules/authentication/constants/login.response.constant.ts rename to src/auth/constants/login.response.constant.ts diff --git a/apps/auth/src/modules/authentication/controllers/authentication.controller.ts b/src/auth/controllers/authentication.controller.ts similarity index 100% rename from apps/auth/src/modules/authentication/controllers/authentication.controller.ts rename to src/auth/controllers/authentication.controller.ts diff --git a/apps/auth/src/modules/authentication/controllers/index.ts b/src/auth/controllers/index.ts similarity index 100% rename from apps/auth/src/modules/authentication/controllers/index.ts rename to src/auth/controllers/index.ts diff --git a/apps/auth/src/modules/authentication/controllers/user-auth.controller.ts b/src/auth/controllers/user-auth.controller.ts similarity index 93% rename from apps/auth/src/modules/authentication/controllers/user-auth.controller.ts rename to src/auth/controllers/user-auth.controller.ts index 085dd2a..c434ef8 100644 --- a/apps/auth/src/modules/authentication/controllers/user-auth.controller.ts +++ b/src/auth/controllers/user-auth.controller.ts @@ -10,9 +10,9 @@ import { import { UserAuthService } from '../services/user-auth.service'; import { UserSignUpDto } from '../dtos/user-auth.dto'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; -import { ResponseMessage } from '@app/common/response/response.decorator'; +import { ResponseMessage } from '../../../libs/common/src/response/response.decorator'; import { UserLoginDto } from '../dtos/user-login.dto'; -import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard'; +import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard'; import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos'; @Controller({ diff --git a/src/auth/dtos/index.ts b/src/auth/dtos/index.ts new file mode 100644 index 0000000..df1bcaf --- /dev/null +++ b/src/auth/dtos/index.ts @@ -0,0 +1,4 @@ +export * from './user-auth.dto'; +export * from './user-login.dto'; +export * from './user-otp.dto'; +export * from './user-password.dto'; diff --git a/apps/auth/src/modules/authentication/dtos/user-auth.dto.ts b/src/auth/dtos/user-auth.dto.ts similarity index 70% rename from apps/auth/src/modules/authentication/dtos/user-auth.dto.ts rename to src/auth/dtos/user-auth.dto.ts index 8e77057..729b735 100644 --- a/apps/auth/src/modules/authentication/dtos/user-auth.dto.ts +++ b/src/auth/dtos/user-auth.dto.ts @@ -3,32 +3,32 @@ import { IsEmail, IsNotEmpty, IsString } from 'class-validator'; export class UserSignUpDto { @ApiProperty({ - description:'email', - required:true + description: 'email', + required: true, }) @IsEmail() @IsNotEmpty() public email: string; @ApiProperty({ - description:'password', - required:true + description: 'password', + required: true, }) @IsString() @IsNotEmpty() public password: string; @ApiProperty({ - description:'first name', - required:true + description: 'first name', + required: true, }) @IsString() @IsNotEmpty() public firstName: string; @ApiProperty({ - description:'last name', - required:true + description: 'last name', + required: true, }) @IsString() @IsNotEmpty() diff --git a/apps/auth/src/modules/authentication/dtos/user-login.dto.ts b/src/auth/dtos/user-login.dto.ts similarity index 100% rename from apps/auth/src/modules/authentication/dtos/user-login.dto.ts rename to src/auth/dtos/user-login.dto.ts diff --git a/apps/auth/src/modules/authentication/dtos/user-otp.dto.ts b/src/auth/dtos/user-otp.dto.ts similarity index 83% rename from apps/auth/src/modules/authentication/dtos/user-otp.dto.ts rename to src/auth/dtos/user-otp.dto.ts index d4fad12..bab47c8 100644 --- a/apps/auth/src/modules/authentication/dtos/user-otp.dto.ts +++ b/src/auth/dtos/user-otp.dto.ts @@ -1,4 +1,4 @@ -import { OtpType } from '@app/common/constants/otp-type.enum'; +import { OtpType } from '../../../libs/common/src/constants/otp-type.enum'; import { ApiProperty } from '@nestjs/swagger'; import { IsEmail, IsEnum, IsNotEmpty, IsString } from 'class-validator'; diff --git a/apps/auth/src/modules/authentication/dtos/user-password.dto.ts b/src/auth/dtos/user-password.dto.ts similarity index 100% rename from apps/auth/src/modules/authentication/dtos/user-password.dto.ts rename to src/auth/dtos/user-password.dto.ts diff --git a/apps/auth/src/modules/authentication/services/authentication.service.ts b/src/auth/services/authentication.service.ts similarity index 98% rename from apps/auth/src/modules/authentication/services/authentication.service.ts rename to src/auth/services/authentication.service.ts index dc9e0b2..1d5d580 100644 --- a/apps/auth/src/modules/authentication/services/authentication.service.ts +++ b/src/auth/services/authentication.service.ts @@ -89,7 +89,6 @@ export class AuthenticationService { async getRequestSign( path: string, method: string, - headers: { [k: string]: string } = {}, query: { [k: string]: any } = {}, body: { [k: string]: any } = {}, ) { diff --git a/apps/auth/src/modules/authentication/services/index.ts b/src/auth/services/index.ts similarity index 100% rename from apps/auth/src/modules/authentication/services/index.ts rename to src/auth/services/index.ts diff --git a/apps/auth/src/modules/authentication/services/user-auth.service.ts b/src/auth/services/user-auth.service.ts similarity index 85% rename from apps/auth/src/modules/authentication/services/user-auth.service.ts rename to src/auth/services/user-auth.service.ts index 4f75152..ae8c721 100644 --- a/apps/auth/src/modules/authentication/services/user-auth.service.ts +++ b/src/auth/services/user-auth.service.ts @@ -1,19 +1,19 @@ -import { UserRepository } from '@app/common/modules/user/repositories'; +import { UserRepository } from '../../../libs/common/src/modules/user/repositories'; import { BadRequestException, Injectable, UnauthorizedException, } from '@nestjs/common'; import { UserSignUpDto } from '../dtos/user-auth.dto'; -import { HelperHashService } from '@app/common/helper/services'; +import { HelperHashService } from '../../../libs/common/src/helper/services'; import { UserLoginDto } from '../dtos/user-login.dto'; -import { AuthService } from '@app/common/auth/services/auth.service'; -import { UserSessionRepository } from '@app/common/modules/session/repositories/session.repository'; -import { UserOtpRepository } from '@app/common/modules/user-otp/repositories/user-otp.repository'; +import { AuthService } from '../../../libs/common/src/auth/services/auth.service'; +import { UserSessionRepository } from '../../../libs/common/src/modules/session/repositories/session.repository'; +import { UserOtpRepository } from '../../../libs/common/src/modules/user-otp/repositories/user-otp.repository'; import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos'; -import { EmailService } from '@app/common/util/email.service'; -import { OtpType } from '@app/common/constants/otp-type.enum'; -import { UserEntity } from '@app/common/modules/user/entities/user.entity'; +import { EmailService } from '../../../libs/common/src/util/email.service'; +import { OtpType } from '../../../libs/common/src/constants/otp-type.enum'; +import { UserEntity } from '../../../libs/common/src/modules/user/entities/user.entity'; import { ILoginResponse } from '../constants/login.response.constant'; @Injectable() diff --git a/apps/auth/src/config/app.config.ts b/src/config/app.config.ts similarity index 100% rename from apps/auth/src/config/app.config.ts rename to src/config/app.config.ts diff --git a/apps/auth/src/config/auth.config.ts b/src/config/auth.config.ts similarity index 100% rename from apps/auth/src/config/auth.config.ts rename to src/config/auth.config.ts diff --git a/src/config/index.ts b/src/config/index.ts new file mode 100644 index 0000000..0dfc023 --- /dev/null +++ b/src/config/index.ts @@ -0,0 +1,4 @@ +import AuthConfig from './auth.config'; +import AppConfig from './app.config'; + +export default [AuthConfig, AppConfig]; diff --git a/apps/backend/src/config/jwt.config.ts b/src/config/jwt.config.ts similarity index 98% rename from apps/backend/src/config/jwt.config.ts rename to src/config/jwt.config.ts index a4ff896..36c2f96 100644 --- a/apps/backend/src/config/jwt.config.ts +++ b/src/config/jwt.config.ts @@ -7,5 +7,5 @@ export default registerAs( expire_time: process.env.JWT_EXPIRE_TIME, secret_refresh: process.env.JWT_SECRET_REFRESH, expire_refresh: process.env.JWT_EXPIRE_TIME_REFRESH, - }) + }), ); diff --git a/apps/auth/src/main.ts b/src/main.ts similarity index 79% rename from apps/auth/src/main.ts rename to src/main.ts index 3c841d6..ed08082 100644 --- a/apps/auth/src/main.ts +++ b/src/main.ts @@ -1,8 +1,8 @@ import { NestFactory } from '@nestjs/core'; -import { AuthModule } from './auth.module'; +import { AuthModule } from './app.module'; import rateLimit from 'express-rate-limit'; import helmet from 'helmet'; -import { setupSwaggerAuthentication } from '@app/common/util/user-auth.swagger.utils'; +import { setupSwaggerAuthentication } from '../libs/common/src/util/user-auth.swagger.utils'; import { ValidationPipe } from '@nestjs/common'; async function bootstrap() { @@ -13,7 +13,7 @@ async function bootstrap() { app.getHttpAdapter().getInstance().set('trust proxy', 1); next(); }); - + app.enableCors(); app.use( @@ -30,11 +30,10 @@ async function bootstrap() { ); setupSwaggerAuthentication(app); - - app.useGlobalPipes(new ValidationPipe()); + app.useGlobalPipes(new ValidationPipe()); await app.listen(4001); } -console.log('Starting auth at port 7001...'); +console.log('Starting auth at port 4001...'); bootstrap(); diff --git a/src/users/controllers/index.ts b/src/users/controllers/index.ts new file mode 100644 index 0000000..edd3705 --- /dev/null +++ b/src/users/controllers/index.ts @@ -0,0 +1 @@ +export * from './user.controller'; diff --git a/apps/backend/src/modules/user/controllers/user.controller.ts b/src/users/controllers/user.controller.ts similarity index 65% rename from apps/backend/src/modules/user/controllers/user.controller.ts rename to src/users/controllers/user.controller.ts index 705a748..4620cd0 100644 --- a/apps/backend/src/modules/user/controllers/user.controller.ts +++ b/src/users/controllers/user.controller.ts @@ -1,7 +1,8 @@ -import { Controller, Get, Query } from '@nestjs/common'; +import { Controller, Get, Query, UseGuards } from '@nestjs/common'; import { UserService } from '../services/user.service'; import { UserListDto } from '../dtos/user.list.dto'; -import { ApiTags } from '@nestjs/swagger'; +import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; +import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard'; @ApiTags('User Module') @Controller({ @@ -11,6 +12,8 @@ import { ApiTags } from '@nestjs/swagger'; export class UserController { constructor(private readonly userService: UserService) {} + @ApiBearerAuth() + @UseGuards(JwtAuthGuard) @Get('list') async userList(@Query() userListDto: UserListDto) { try { diff --git a/src/users/dtos/index.ts b/src/users/dtos/index.ts new file mode 100644 index 0000000..46d6f1d --- /dev/null +++ b/src/users/dtos/index.ts @@ -0,0 +1 @@ +export * from './user.list.dto'; diff --git a/apps/backend/src/modules/user/dtos/user.list.dto.ts b/src/users/dtos/user.list.dto.ts similarity index 61% rename from apps/backend/src/modules/user/dtos/user.list.dto.ts rename to src/users/dtos/user.list.dto.ts index da7d79a..327a2ba 100644 --- a/apps/backend/src/modules/user/dtos/user.list.dto.ts +++ b/src/users/dtos/user.list.dto.ts @@ -1,15 +1,20 @@ -import { IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator'; +import { + IsNotEmpty, + IsNumberString, + IsOptional, + IsString, +} from 'class-validator'; export class UserListDto { @IsString() @IsOptional() schema: string; - @IsNumber() + @IsNumberString() @IsNotEmpty() page_no: number; - @IsNumber() + @IsNumberString() @IsNotEmpty() page_size: number; @@ -17,11 +22,11 @@ export class UserListDto { @IsOptional() username: string; - @IsNumber() + @IsNumberString() @IsOptional() start_time: number; - @IsNumber() + @IsNumberString() @IsOptional() end_time: number; } diff --git a/src/users/services/index.ts b/src/users/services/index.ts new file mode 100644 index 0000000..e17ee5c --- /dev/null +++ b/src/users/services/index.ts @@ -0,0 +1 @@ +export * from './user.service'; diff --git a/apps/backend/src/modules/user/services/user.service.ts b/src/users/services/user.service.ts similarity index 100% rename from apps/backend/src/modules/user/services/user.service.ts rename to src/users/services/user.service.ts diff --git a/apps/backend/src/modules/user/user.module.ts b/src/users/user.module.ts similarity index 100% rename from apps/backend/src/modules/user/user.module.ts rename to src/users/user.module.ts