From 770d6eb0d333a7b840b6354633d168099cd1e502 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Sun, 26 Jan 2025 13:22:05 +0100 Subject: [PATCH] refactor: rename folder shared and others improvements --- eslint.config.mjs | 6 +-- package.json | 1 + pnpm-lock.yaml | 17 ++++++++ .../hashing/bcrypt.service.spec.ts | 0 .../hashing/bcrypt.service.ts | 0 .../hashing/hashing.service.spec.ts | 0 .../hashing/hashing.service.ts | 0 .../logger/logger.service.ts | 0 .../mailer/mailer.constants.ts | 0 .../mailer/mailer.module.ts | 0 .../mailer/mailer.service.spec.ts | 0 .../mailer/mailer.service.ts | 0 .../plugins/register-fastify.plugins.ts | 33 +++++++++++++++ src/{shared => common}/utils/utils.module.ts | 0 .../utils/utils.service.spec.ts | 0 src/{shared => common}/utils/utils.service.ts | 0 .../configure-auth-swagger-docs.helper.ts | 6 +-- src/helpers/configure-swagger-docs.helper.ts | 6 +-- .../change-password/change-password.module.ts | 6 +-- .../change-password.service.spec.ts | 2 +- .../change-password.service.ts | 4 +- .../forgot-password/forgot-password.module.ts | 8 ++-- .../forgot-password.service.spec.ts | 6 +-- .../forgot-password.service.ts | 8 ++-- src/iam/iam.module.ts | 2 +- src/iam/login/login.module.ts | 4 +- src/iam/login/login.service.spec.ts | 2 +- src/iam/login/login.service.ts | 2 +- src/iam/register/register.controller.spec.ts | 2 +- src/iam/register/register.module.ts | 6 +-- src/iam/register/register.service.spec.ts | 4 +- src/iam/register/register.service.ts | 6 +-- src/main.ts | 42 ++++++++++--------- .../users.typeorm.repository.ts | 2 +- .../repositories/users.repository.provider.ts | 2 +- src/users/users.module.ts | 6 +-- src/users/users.service.spec.ts | 4 +- .../change-password.e2e-spec.ts | 2 +- .../forgot-password.e2e-spec.ts | 2 +- test/register/register.e2e-spec.ts | 4 +- test/users/users.e2e-spec.ts | 2 +- 41 files changed, 124 insertions(+), 73 deletions(-) rename src/{shared => common}/hashing/bcrypt.service.spec.ts (100%) rename src/{shared => common}/hashing/bcrypt.service.ts (100%) rename src/{shared => common}/hashing/hashing.service.spec.ts (100%) rename src/{shared => common}/hashing/hashing.service.ts (100%) rename src/{shared => common}/logger/logger.service.ts (100%) rename src/{shared => common}/mailer/mailer.constants.ts (100%) rename src/{shared => common}/mailer/mailer.module.ts (100%) rename src/{shared => common}/mailer/mailer.service.spec.ts (100%) rename src/{shared => common}/mailer/mailer.service.ts (100%) create mode 100644 src/common/plugins/register-fastify.plugins.ts rename src/{shared => common}/utils/utils.module.ts (100%) rename src/{shared => common}/utils/utils.service.spec.ts (100%) rename src/{shared => common}/utils/utils.service.ts (100%) diff --git a/eslint.config.mjs b/eslint.config.mjs index dd73ab56..8cca7f4c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -30,14 +30,14 @@ export default tseslint.config( '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-floating-promises': 'off', '@typescript-eslint/no-require-imports': 'off', - '@typescript-eslint/no-unsafe-argument': 'warn', + '@typescript-eslint/no-unsafe-argument': 'off', '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/no-unsafe-return': 'off', - '@typescript-eslint/no-unsafe-assignment': 'warn', + '@typescript-eslint/no-unsafe-assignment': 'off', '@typescript-eslint/no-unsafe-call': 'warn', '@typescript-eslint/no-unsafe-member-access': 'warn', '@typescript-eslint/require-await': 'warn', - '@typescript-eslint/no-unused-vars': 'warn', + '@typescript-eslint/no-unused-vars': 'warn' }, }, ); diff --git a/package.json b/package.json index 75dcc085..71202191 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@fastify/cors": "^10.0.2", + "@fastify/helmet": "^13.0.1", "@fastify/rate-limit": "^10.2.2", "@fastify/static": "^8.0.4", "@nestjs/common": "^11.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9b7c6ff2..95302186 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ importers: '@fastify/cors': specifier: ^10.0.2 version: 10.0.2 + '@fastify/helmet': + specifier: ^13.0.1 + version: 13.0.1 '@fastify/rate-limit': specifier: ^10.2.2 version: 10.2.2 @@ -494,6 +497,9 @@ packages: '@fastify/forwarded@3.0.0': resolution: {integrity: sha512-kJExsp4JCms7ipzg7SJ3y8DwmePaELHxKYtg+tZow+k0znUTf3cb+npgyqm8+ATZOdmfgfydIebPDWM172wfyA==} + '@fastify/helmet@13.0.1': + resolution: {integrity: sha512-i+ifqazG3d0HwHL3zuZdg6B/WPc9Ee6kVfGpwGho4nxm0UaK1htss0zq+1rVhOoAorZlCgTZ3/i4S58hUGkkoA==} + '@fastify/merge-json-schemas@0.2.1': resolution: {integrity: sha512-OA3KGBCy6KtIvLf8DINC5880o5iBlDX4SxzLQS8HorJAbqluzLRn80UXU0bxZn7UOFhFgpRJDasfwn9nG4FG4A==} @@ -2034,6 +2040,10 @@ packages: resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} engines: {node: '>= 0.4'} + helmet@8.0.0: + resolution: {integrity: sha512-VyusHLEIIO5mjQPUI1wpOAEu+wl6Q0998jzTxqUYGE45xCIcAxy3MsbEK/yyJUJ3ADeMoB6MornPH6GMWAf+Pw==} + engines: {node: '>=18.0.0'} + help-me@5.0.0: resolution: {integrity: sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==} @@ -4123,6 +4133,11 @@ snapshots: '@fastify/forwarded@3.0.0': {} + '@fastify/helmet@13.0.1': + dependencies: + fastify-plugin: 5.0.1 + helmet: 8.0.0 + '@fastify/merge-json-schemas@0.2.1': dependencies: dequal: 2.0.3 @@ -5942,6 +5957,8 @@ snapshots: dependencies: function-bind: 1.1.2 + helmet@8.0.0: {} + help-me@5.0.0: {} hexoid@2.0.0: {} diff --git a/src/shared/hashing/bcrypt.service.spec.ts b/src/common/hashing/bcrypt.service.spec.ts similarity index 100% rename from src/shared/hashing/bcrypt.service.spec.ts rename to src/common/hashing/bcrypt.service.spec.ts diff --git a/src/shared/hashing/bcrypt.service.ts b/src/common/hashing/bcrypt.service.ts similarity index 100% rename from src/shared/hashing/bcrypt.service.ts rename to src/common/hashing/bcrypt.service.ts diff --git a/src/shared/hashing/hashing.service.spec.ts b/src/common/hashing/hashing.service.spec.ts similarity index 100% rename from src/shared/hashing/hashing.service.spec.ts rename to src/common/hashing/hashing.service.spec.ts diff --git a/src/shared/hashing/hashing.service.ts b/src/common/hashing/hashing.service.ts similarity index 100% rename from src/shared/hashing/hashing.service.ts rename to src/common/hashing/hashing.service.ts diff --git a/src/shared/logger/logger.service.ts b/src/common/logger/logger.service.ts similarity index 100% rename from src/shared/logger/logger.service.ts rename to src/common/logger/logger.service.ts diff --git a/src/shared/mailer/mailer.constants.ts b/src/common/mailer/mailer.constants.ts similarity index 100% rename from src/shared/mailer/mailer.constants.ts rename to src/common/mailer/mailer.constants.ts diff --git a/src/shared/mailer/mailer.module.ts b/src/common/mailer/mailer.module.ts similarity index 100% rename from src/shared/mailer/mailer.module.ts rename to src/common/mailer/mailer.module.ts diff --git a/src/shared/mailer/mailer.service.spec.ts b/src/common/mailer/mailer.service.spec.ts similarity index 100% rename from src/shared/mailer/mailer.service.spec.ts rename to src/common/mailer/mailer.service.spec.ts diff --git a/src/shared/mailer/mailer.service.ts b/src/common/mailer/mailer.service.ts similarity index 100% rename from src/shared/mailer/mailer.service.ts rename to src/common/mailer/mailer.service.ts diff --git a/src/common/plugins/register-fastify.plugins.ts b/src/common/plugins/register-fastify.plugins.ts new file mode 100644 index 00000000..ed8e7b26 --- /dev/null +++ b/src/common/plugins/register-fastify.plugins.ts @@ -0,0 +1,33 @@ +import { NestFastifyApplication } from '@nestjs/platform-fastify'; + +export async function registerFastifyPlugins(app: NestFastifyApplication) { + + await app.register(require('@fastify/cors'), { + origin: true || [process.env.ENDPOINT_URL_CORS], + methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', + allowedHeaders: + 'Content-Type, Accept, Access-Control-Allow-Origin, Access-Control-Allow-Methods', + credentials: true, + }); + + await app.register(require('@fastify/rate-limit'), { + max: 100, + timeWindow: '1 minute', + }); + + await app.register(require('@fastify/helmet'), { + crossOriginResourcePolicy: true, + contentSecurityPolicy: false, + referrerPolicy: { + policy: 'same-origin', + }, + hsts: { + maxAge: 31536000, // 1 year + includeSubDomains: true, // Optional: Include subdomains + preload: true, // Optional: Indicate to browsers to preload HSTS + }, + frameguard: { + action: 'deny', + }, + }); +} diff --git a/src/shared/utils/utils.module.ts b/src/common/utils/utils.module.ts similarity index 100% rename from src/shared/utils/utils.module.ts rename to src/common/utils/utils.module.ts diff --git a/src/shared/utils/utils.service.spec.ts b/src/common/utils/utils.service.spec.ts similarity index 100% rename from src/shared/utils/utils.service.spec.ts rename to src/common/utils/utils.service.spec.ts diff --git a/src/shared/utils/utils.service.ts b/src/common/utils/utils.service.ts similarity index 100% rename from src/shared/utils/utils.service.ts rename to src/common/utils/utils.service.ts diff --git a/src/helpers/configure-auth-swagger-docs.helper.ts b/src/helpers/configure-auth-swagger-docs.helper.ts index 2fc6102f..711d7bae 100644 --- a/src/helpers/configure-auth-swagger-docs.helper.ts +++ b/src/helpers/configure-auth-swagger-docs.helper.ts @@ -37,16 +37,16 @@ export function configureAuthSwaggerDocs( if (!req.headers.authorization) { return unauthorizedResponse(); } - + const credentials = parseAuthHeader(req.headers.authorization); - + if ( credentials?.user !== apiDocumentationCredentials.user || credentials?.password !== apiDocumentationCredentials.password ) { return unauthorizedResponse(); } - + next(); }); } diff --git a/src/helpers/configure-swagger-docs.helper.ts b/src/helpers/configure-swagger-docs.helper.ts index 7d9986fc..e841ac87 100644 --- a/src/helpers/configure-swagger-docs.helper.ts +++ b/src/helpers/configure-swagger-docs.helper.ts @@ -1,14 +1,12 @@ import { INestApplication } from '@nestjs/common'; -import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import { ConfigService } from '@nestjs/config'; +import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; export function configureSwaggerDocs( app: INestApplication, configService: ConfigService, ) { - if ( - configService.get('NODE_ENV') !== 'production' - ) { + if (configService.get('NODE_ENV') !== 'production') { const config = new DocumentBuilder() .setTitle('API') .setDescription('The API description') diff --git a/src/iam/change-password/change-password.module.ts b/src/iam/change-password/change-password.module.ts index 80df68ef..259371f8 100644 --- a/src/iam/change-password/change-password.module.ts +++ b/src/iam/change-password/change-password.module.ts @@ -4,9 +4,9 @@ import { ChangePasswordService } from './change-password.service'; import { TypeOrmModule } from '@nestjs/typeorm'; import { Users } from '../../users/models/users.model'; import { UsersService } from '../../users/users.service'; -import { MailerModule } from '../../shared/mailer/mailer.module'; -import { BcryptService } from '../../shared/hashing/bcrypt.service'; -import { HashingService } from '../../shared/hashing/hashing.service'; +import { MailerModule } from '../../common/mailer/mailer.module'; +import { BcryptService } from '../../common/hashing/bcrypt.service'; +import { HashingService } from '../../common/hashing/hashing.service'; import { APP_GUARD } from '@nestjs/core'; import { AuthenticationGuard } from '../login/guards/authentication/authentication.guard'; import { AccessTokenGuard } from '../login/guards/access-token/access-token.guard'; diff --git a/src/iam/change-password/change-password.service.spec.ts b/src/iam/change-password/change-password.service.spec.ts index 0c8b7771..78ff0db0 100644 --- a/src/iam/change-password/change-password.service.spec.ts +++ b/src/iam/change-password/change-password.service.spec.ts @@ -4,7 +4,7 @@ import { getRepositoryToken } from '@nestjs/typeorm'; import { Users } from '../../users/models/users.model'; import { Repository } from 'typeorm'; import { UsersService } from '../../users/users.service'; -import { MailerService } from '../../shared/mailer/mailer.service'; +import { MailerService } from '../../common/mailer/mailer.service'; import { ConfigService } from '@nestjs/config'; const changePasswordUser = { diff --git a/src/iam/change-password/change-password.service.ts b/src/iam/change-password/change-password.service.ts index b322790b..32a46151 100644 --- a/src/iam/change-password/change-password.service.ts +++ b/src/iam/change-password/change-password.service.ts @@ -1,8 +1,8 @@ import { Injectable, Logger } from '@nestjs/common'; import { UsersService } from '../../users/users.service'; import { ChangePasswordDto } from './dto/change-password.dto'; -import { MailerService } from '../../shared/mailer/mailer.service'; -import { changePasswordEmail } from '../../shared/mailer/mailer.constants'; +import { MailerService } from '../../common/mailer/mailer.service'; +import { changePasswordEmail } from '../../common/mailer/mailer.constants'; @Injectable() export class ChangePasswordService { diff --git a/src/iam/forgot-password/forgot-password.module.ts b/src/iam/forgot-password/forgot-password.module.ts index 6f9acd89..aabc7732 100644 --- a/src/iam/forgot-password/forgot-password.module.ts +++ b/src/iam/forgot-password/forgot-password.module.ts @@ -2,10 +2,10 @@ import { Module } from '@nestjs/common'; import { ForgotPasswordService } from './forgot-password.service'; import { ForgotPasswordController } from './forgot-password.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { BcryptService } from '../../shared/hashing/bcrypt.service'; -import { HashingService } from '../../shared/hashing/hashing.service'; -import { MailerModule } from '../../shared/mailer/mailer.module'; -import { UtilsModule } from '../../shared/utils/utils.module'; +import { BcryptService } from '../../common/hashing/bcrypt.service'; +import { HashingService } from '../../common/hashing/hashing.service'; +import { MailerModule } from '../../common/mailer/mailer.module'; +import { UtilsModule } from '../../common/utils/utils.module'; import { Users } from '../../users/models/users.model'; import { provideUsersRepository } from '../../users/repositories/users.repository.provider'; import { UsersService } from '../../users/users.service'; diff --git a/src/iam/forgot-password/forgot-password.service.spec.ts b/src/iam/forgot-password/forgot-password.service.spec.ts index 773521e7..fb7a8a33 100644 --- a/src/iam/forgot-password/forgot-password.service.spec.ts +++ b/src/iam/forgot-password/forgot-password.service.spec.ts @@ -2,10 +2,10 @@ import { Test, TestingModule } from '@nestjs/testing'; import { getRepositoryToken } from '@nestjs/typeorm'; import { Users } from '../../users/models/users.model'; import { ForgotPasswordService } from './forgot-password.service'; -import { MailerService } from '../../shared/mailer/mailer.service'; -import { UtilsService } from '../../shared/utils/utils.service'; +import { MailerService } from '../../common/mailer/mailer.service'; +import { UtilsService } from '../../common/utils/utils.service'; import { ConfigService } from '@nestjs/config'; -import { HashingService } from '../../shared/hashing/hashing.service'; +import { HashingService } from '../../common/hashing/hashing.service'; import { Repository } from 'typeorm'; import { UsersService } from '../../users/users.service'; diff --git a/src/iam/forgot-password/forgot-password.service.ts b/src/iam/forgot-password/forgot-password.service.ts index f947bd97..fd98c446 100644 --- a/src/iam/forgot-password/forgot-password.service.ts +++ b/src/iam/forgot-password/forgot-password.service.ts @@ -3,10 +3,10 @@ import { Repository } from 'typeorm'; import { InjectRepository } from '@nestjs/typeorm'; import { Users } from '../../users/models/users.model'; import { ForgotPasswordDto } from './dto/forgot-password.dto'; -import { MailerService } from '../../shared/mailer/mailer.service'; -import { UtilsService } from '../../shared/utils/utils.service'; -import { HashingService } from '../../shared/hashing/hashing.service'; -import { forgotPasswordEmail } from '../../shared/mailer/mailer.constants'; +import { MailerService } from '../../common/mailer/mailer.service'; +import { UtilsService } from '../../common/utils/utils.service'; +import { HashingService } from '../../common/hashing/hashing.service'; +import { forgotPasswordEmail } from '../../common/mailer/mailer.constants'; @Injectable() export class ForgotPasswordService { diff --git a/src/iam/iam.module.ts b/src/iam/iam.module.ts index 47f59408..4b020e05 100644 --- a/src/iam/iam.module.ts +++ b/src/iam/iam.module.ts @@ -1,6 +1,6 @@ import { Module } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; -import { UtilsModule } from '../shared/utils/utils.module'; +import { UtilsModule } from '../common/utils/utils.module'; import { UsersModule } from '../users/users.module'; import { ChangePasswordModule } from './change-password/change-password.module'; import { ForgotPasswordModule } from './forgot-password/forgot-password.module'; diff --git a/src/iam/login/login.module.ts b/src/iam/login/login.module.ts index 3db6142f..1c3a4404 100644 --- a/src/iam/login/login.module.ts +++ b/src/iam/login/login.module.ts @@ -6,8 +6,8 @@ import { Users } from '../../users/models/users.model'; import { JwtModule } from '@nestjs/jwt'; import { UsersService } from '../../users/users.service'; import { ConfigModule } from '@nestjs/config'; -import { HashingService } from '../../shared/hashing/hashing.service'; -import { BcryptService } from '../../shared/hashing/bcrypt.service'; +import { HashingService } from '../../common/hashing/hashing.service'; +import { BcryptService } from '../../common/hashing/bcrypt.service'; import { APP_GUARD } from '@nestjs/core'; import { AuthenticationGuard } from './guards/authentication/authentication.guard'; import { AccessTokenGuard } from './guards/access-token/access-token.guard'; diff --git a/src/iam/login/login.service.spec.ts b/src/iam/login/login.service.spec.ts index 3655200f..165441df 100644 --- a/src/iam/login/login.service.spec.ts +++ b/src/iam/login/login.service.spec.ts @@ -1,7 +1,7 @@ import { ConfigModule, ConfigService, ConfigType } from '@nestjs/config'; import { JwtService } from '@nestjs/jwt'; import { Test, TestingModule } from '@nestjs/testing'; -import { HashingService } from '../../shared/hashing/hashing.service'; +import { HashingService } from '../../common/hashing/hashing.service'; import { LoginService } from './login.service'; import { UsersService } from '../../users/users.service'; import { Users } from '../../users/models/users.model'; diff --git a/src/iam/login/login.service.ts b/src/iam/login/login.service.ts index 7081fc0e..c4940999 100644 --- a/src/iam/login/login.service.ts +++ b/src/iam/login/login.service.ts @@ -10,7 +10,7 @@ import { UsersService } from '../../users/users.service'; import { AccountsUsers } from '../../users/interfaces/accounts-users.interface'; import { LoginDto } from './dto/login.dto'; import { ConfigType } from '@nestjs/config'; -import { HashingService } from '../../shared/hashing/hashing.service'; +import { HashingService } from '../../common/hashing/hashing.service'; import { JWTPayload } from './interfaces/jwt-payload.interface'; import { RefreshTokenDto } from './dto/refresh-token.dto'; import { Users } from '../../users/models/users.model'; diff --git a/src/iam/register/register.controller.spec.ts b/src/iam/register/register.controller.spec.ts index 2521dfad..cb3143a0 100644 --- a/src/iam/register/register.controller.spec.ts +++ b/src/iam/register/register.controller.spec.ts @@ -2,7 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { RegisterController } from './register.controller'; import { RegisterService } from './register.service'; import { UsersService } from '../../users/users.service'; -import { MailerService } from '../../shared/mailer/mailer.service'; +import { MailerService } from '../../common/mailer/mailer.service'; import { ConfigService } from '@nestjs/config'; import { RegisterUserDto } from './dto/register-user.dto'; import { BadRequestException } from '@nestjs/common'; diff --git a/src/iam/register/register.module.ts b/src/iam/register/register.module.ts index b84cf6be..94d8021f 100644 --- a/src/iam/register/register.module.ts +++ b/src/iam/register/register.module.ts @@ -1,8 +1,8 @@ import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { BcryptService } from '../../shared/hashing/bcrypt.service'; -import { HashingService } from '../../shared/hashing/hashing.service'; -import { MailerModule } from '../../shared/mailer/mailer.module'; +import { BcryptService } from '../../common/hashing/bcrypt.service'; +import { HashingService } from '../../common/hashing/hashing.service'; +import { MailerModule } from '../../common/mailer/mailer.module'; import { Users } from '../../users/models/users.model'; import { UsersService } from '../../users/users.service'; import { RegisterController } from './register.controller'; diff --git a/src/iam/register/register.service.spec.ts b/src/iam/register/register.service.spec.ts index c5e7e22a..e87ab1bf 100644 --- a/src/iam/register/register.service.spec.ts +++ b/src/iam/register/register.service.spec.ts @@ -4,8 +4,8 @@ import { RegisterService } from './register.service'; import { Users } from '../../users/models/users.model'; import { getRepositoryToken } from '@nestjs/typeorm'; import { RegisterUserDto } from './dto/register-user.dto'; -import { HashingService } from '../../shared/hashing/hashing.service'; -import { MailerService } from '../../shared/mailer/mailer.service'; +import { HashingService } from '../../common/hashing/hashing.service'; +import { MailerService } from '../../common/mailer/mailer.service'; import { ConfigService } from '@nestjs/config'; import { Repository } from 'typeorm'; diff --git a/src/iam/register/register.service.ts b/src/iam/register/register.service.ts index 0ca1eabf..3fd7bee7 100644 --- a/src/iam/register/register.service.ts +++ b/src/iam/register/register.service.ts @@ -1,10 +1,10 @@ import { Injectable, Logger } from '@nestjs/common'; -import { HashingService } from '../../shared/hashing/hashing.service'; -import { MailerService } from '../../shared/mailer/mailer.service'; +import { HashingService } from '../../common/hashing/hashing.service'; +import { MailerService } from '../../common/mailer/mailer.service'; import { AccountsUsers } from '../../users/interfaces/accounts-users.interface'; import { UsersService } from '../../users/users.service'; import { RegisterUserDto } from './dto/register-user.dto'; -import { registrationEmail } from '../../shared/mailer/mailer.constants'; +import { registrationEmail } from '../../common/mailer/mailer.constants'; @Injectable() export class RegisterService { diff --git a/src/main.ts b/src/main.ts index 1fba6e5a..42c46e13 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,29 +1,34 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; -import { Logger, ValidationPipe } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; +import { ConsoleLogger, Logger, ValidationPipe } from '@nestjs/common'; import { configureSwaggerDocs } from './helpers/configure-swagger-docs.helper'; import { configureAuthSwaggerDocs } from './helpers/configure-auth-swagger-docs.helper'; -import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'; +import { + FastifyAdapter, + NestFastifyApplication +} from '@nestjs/platform-fastify'; +import { registerFastifyPlugins } from './common/plugins/register-fastify.plugins'; +import { ConfigService } from '@nestjs/config'; async function bootstrap() { const fastifyAdapter = new FastifyAdapter(); - const app = - await NestFactory.create(AppModule, fastifyAdapter); + const app = await NestFactory.create( + AppModule, + fastifyAdapter, + { + logger: new ConsoleLogger({ + json: true, + colors: true, + }), + }, + ); const configService = app.get(ConfigService); - await fastifyAdapter.register(require('@fastify/cors'), { - origin: true || [configService.get('ENDPOINT_URL_CORS')], - methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', - allowedHeaders: - 'Content-Type, Accept, Access-Control-Allow-Origin, Access-Control-Allow-Methods', - credentials: true, - }); - - await fastifyAdapter.register(require('@fastify/rate-limit'), { - max: 100, - timeWindow: '1 minute', - }); + // Plugins for Fastify + registerFastifyPlugins(app); + // Swagger Configurations + configureAuthSwaggerDocs(app, configService); + configureSwaggerDocs(app, configService); app.setGlobalPrefix('api'); app.useGlobalPipes( @@ -37,9 +42,6 @@ async function bootstrap() { }), ); - configureAuthSwaggerDocs(app, configService); - configureSwaggerDocs(app, configService); - const port = configService.get('SERVER_PORT') || 3000; await app.listen(port, '0.0.0.0'); if (configService.get('NODE_ENV') !== 'production') { diff --git a/src/users/repositories/implementations/users.typeorm.repository.ts b/src/users/repositories/implementations/users.typeorm.repository.ts index 8026d67f..7161d8c4 100644 --- a/src/users/repositories/implementations/users.typeorm.repository.ts +++ b/src/users/repositories/implementations/users.typeorm.repository.ts @@ -4,7 +4,7 @@ import { Repository, UpdateResult } from 'typeorm'; import { UserProfileDto } from '../../../users/dto/user-profile.dto'; import { UserUpdateDto } from '../../../users/dto/user-update.dto'; import { UserDto } from '../../../users/dto/user.dto'; -import { HashingService } from '../../../shared/hashing/hashing.service'; +import { HashingService } from '../../../common/hashing/hashing.service'; import { AccountsUsers } from '../../../users/interfaces/accounts-users.interface'; export class UsersTypeOrmRepository implements UsersRepository { diff --git a/src/users/repositories/users.repository.provider.ts b/src/users/repositories/users.repository.provider.ts index e0310cfb..43342891 100644 --- a/src/users/repositories/users.repository.provider.ts +++ b/src/users/repositories/users.repository.provider.ts @@ -6,7 +6,7 @@ import { Repository } from 'typeorm'; import { USERS_REPOSITORY_TOKEN } from './users.repository.interface'; import { UsersTypeOrmRepository } from './implementations/users.typeorm.repository'; import { Users } from '../models/users.model'; -import { HashingService } from '../../shared/hashing/hashing.service'; +import { HashingService } from '../../common/hashing/hashing.service'; import { ConfigService } from '@nestjs/config'; import { config } from 'dotenv'; diff --git a/src/users/users.module.ts b/src/users/users.module.ts index 013211f1..8ac06b8e 100644 --- a/src/users/users.module.ts +++ b/src/users/users.module.ts @@ -3,9 +3,9 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { Users } from './models/users.model'; import { UsersService } from './users.service'; import { UsersController } from './users.controller'; -import { MailerModule } from '../shared/mailer/mailer.module'; -import { BcryptService } from '../shared/hashing/bcrypt.service'; -import { HashingService } from '../shared/hashing/hashing.service'; +import { MailerModule } from '../common/mailer/mailer.module'; +import { BcryptService } from '../common/hashing/bcrypt.service'; +import { HashingService } from '../common/hashing/hashing.service'; import { provideUsersRepository } from './repositories/users.repository.provider'; @Module({ diff --git a/src/users/users.service.spec.ts b/src/users/users.service.spec.ts index 0367fb3d..2c01fe7b 100644 --- a/src/users/users.service.spec.ts +++ b/src/users/users.service.spec.ts @@ -1,7 +1,7 @@ import { HttpException, NotFoundException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { BcryptService } from '../shared/hashing/bcrypt.service'; -import { HashingService } from '../shared/hashing/hashing.service'; +import { BcryptService } from '../common/hashing/bcrypt.service'; +import { HashingService } from '../common/hashing/hashing.service'; import { UserDto } from './dto/user.dto'; import { UsersService } from './users.service'; import { UsersTypeOrmRepository } from './repositories/implementations/users.typeorm.repository'; diff --git a/test/change-password/change-password.e2e-spec.ts b/test/change-password/change-password.e2e-spec.ts index f45cc2da..ad3b2253 100644 --- a/test/change-password/change-password.e2e-spec.ts +++ b/test/change-password/change-password.e2e-spec.ts @@ -1,7 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import * as request from 'supertest'; import { AppModule } from './../../src/app.module'; -import { MailerService } from '../../src/shared/mailer/mailer.service'; +import { MailerService } from '../../src/common/mailer/mailer.service'; import { BadRequestException, HttpStatus, diff --git a/test/forgot-password/forgot-password.e2e-spec.ts b/test/forgot-password/forgot-password.e2e-spec.ts index 74f0bb84..3295a963 100644 --- a/test/forgot-password/forgot-password.e2e-spec.ts +++ b/test/forgot-password/forgot-password.e2e-spec.ts @@ -1,7 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import * as request from 'supertest'; import { AppModule } from './../../src/app.module'; -import { MailerService } from '../../src/shared/mailer/mailer.service'; +import { MailerService } from '../../src/common/mailer/mailer.service'; import { BadRequestException, HttpStatus, diff --git a/test/register/register.e2e-spec.ts b/test/register/register.e2e-spec.ts index 7ec51335..b67905e1 100644 --- a/test/register/register.e2e-spec.ts +++ b/test/register/register.e2e-spec.ts @@ -1,14 +1,14 @@ import { Test, TestingModule } from '@nestjs/testing'; import * as request from 'supertest'; import { AppModule } from './../../src/app.module'; -import { MailerService } from '../../src/shared/mailer/mailer.service'; +import { MailerService } from '../../src/common/mailer/mailer.service'; import { BadRequestException, HttpStatus, ValidationPipe, } from '@nestjs/common'; import { UserDto } from '../../src/users/dto/user.dto'; -import { HashingService } from '../../src/shared/hashing/hashing.service'; +import { HashingService } from '../../src/common/hashing/hashing.service'; import { FastifyAdapter, NestFastifyApplication, diff --git a/test/users/users.e2e-spec.ts b/test/users/users.e2e-spec.ts index ab7d77ea..423d3623 100644 --- a/test/users/users.e2e-spec.ts +++ b/test/users/users.e2e-spec.ts @@ -1,7 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import * as request from 'supertest'; import { AppModule } from './../../src/app.module'; -import { MailerService } from '../../src/shared/mailer/mailer.service'; +import { MailerService } from '../../src/common/mailer/mailer.service'; import { HttpStatus, ValidationPipe } from '@nestjs/common'; import { AccessTokenGuard } from '../../src/iam/login/guards/access-token/access-token.guard'; import {