diff --git a/packages/server-nest/src/modules/Accounts/Accounts.controller.ts b/packages/server-nest/src/modules/Accounts/Accounts.controller.ts index e18f25de8..d38613986 100644 --- a/packages/server-nest/src/modules/Accounts/Accounts.controller.ts +++ b/packages/server-nest/src/modules/Accounts/Accounts.controller.ts @@ -11,13 +11,11 @@ import { import { AccountsApplication } from './AccountsApplication.service'; import { CreateAccountDTO } from './CreateAccount.dto'; import { EditAccountDTO } from './EditAccount.dto'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types'; import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('accounts') @ApiTags('accounts') -@PublicRoute() export class AccountsController { constructor(private readonly accountsApplication: AccountsApplication) {} diff --git a/packages/server-nest/src/modules/App/App.module.ts b/packages/server-nest/src/modules/App/App.module.ts index 9b0086111..a5ab3e410 100644 --- a/packages/server-nest/src/modules/App/App.module.ts +++ b/packages/server-nest/src/modules/App/App.module.ts @@ -1,7 +1,7 @@ import { MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { EventEmitterModule } from '@nestjs/event-emitter'; -import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core'; +import { APP_INTERCEPTOR } from '@nestjs/core'; import { join } from 'path'; import { RedisModule } from '@liaoliaots/nestjs-redis'; import { @@ -12,24 +12,19 @@ import { QueryResolver, } from 'nestjs-i18n'; import { BullModule } from '@nestjs/bullmq'; -import { JwtModule } from '@nestjs/jwt'; import { PassportModule } from '@nestjs/passport'; -import { ClsModule } from 'nestjs-cls'; +import { ClsModule, ClsService } from 'nestjs-cls'; import { AppController } from './App.controller'; import { AppService } from './App.service'; import { ItemsModule } from '../Items/items.module'; import { config } from '../../common/config'; import { SystemDatabaseModule } from '../System/SystemDB/SystemDB.module'; import { SystemModelsModule } from '../System/SystemModels/SystemModels.module'; -import { JwtStrategy } from '../Auth/Jwt.strategy'; -import { jwtConstants } from '../Auth/Auth.constants'; import { TenancyDatabaseModule } from '../Tenancy/TenancyDB/TenancyDB.module'; import { TenancyModelsModule } from '../Tenancy/TenancyModels/Tenancy.module'; import { LoggerMiddleware } from '@/middleware/logger.middleware'; import { ExcludeNullInterceptor } from '@/interceptors/ExcludeNull.interceptor'; -import { JwtAuthGuard } from '../Auth/Jwt.guard'; import { UserIpInterceptor } from '@/interceptors/user-ip.interceptor'; -import { TenancyGlobalMiddleware } from '../Tenancy/TenancyGlobal.middleware'; import { TransformerModule } from '../Transformer/Transformer.module'; import { AccountsModule } from '../Accounts/Accounts.module'; import { ExpensesModule } from '../Expenses/Expenses.module'; @@ -107,10 +102,6 @@ import { AuthModule } from '../Auth/Auth.module'; ], }), PassportModule, - JwtModule.register({ - secret: jwtConstants.secret, - signOptions: { expiresIn: '60s' }, - }), BullModule.forRootAsync({ imports: [ConfigModule], useFactory: async (configService: ConfigService) => ({ @@ -125,9 +116,8 @@ import { AuthModule } from '../Auth/Auth.module'; global: true, middleware: { mount: true, - setup: (cls, req: Request, res: Response) => { + setup: (cls: ClsService, req: Request, res: Response) => { cls.set('organizationId', req.headers['organization-id']); - cls.set('userId', 1); }, generateId: true, saveReq: true, @@ -148,6 +138,7 @@ import { AuthModule } from '../Auth/Auth.module'; ChromiumlyTenancyModule, TransformerModule, MailModule, + AuthModule, ItemsModule, ItemCategoryModule, AccountsModule, @@ -194,7 +185,6 @@ import { AuthModule } from '../Auth/Auth.module'; OrganizationModule, TenantDBManagerModule, PaymentServicesModule, - AuthModule, ], controllers: [AppController], providers: [ @@ -202,10 +192,6 @@ import { AuthModule } from '../Auth/Auth.module'; provide: APP_INTERCEPTOR, useClass: SerializeInterceptor, }, - { - provide: APP_GUARD, - useClass: JwtAuthGuard, - }, { provide: APP_INTERCEPTOR, useClass: UserIpInterceptor, @@ -215,7 +201,6 @@ import { AuthModule } from '../Auth/Auth.module'; useClass: ExcludeNullInterceptor, }, AppService, - JwtStrategy, ], }) export class AppModule { @@ -223,9 +208,5 @@ export class AppModule { consumer .apply(LoggerMiddleware) .forRoutes({ path: '*', method: RequestMethod.ALL }); - - consumer - .apply(TenancyGlobalMiddleware) - .forRoutes({ path: '*', method: RequestMethod.ALL }); } } diff --git a/packages/server-nest/src/modules/App/App.service.ts b/packages/server-nest/src/modules/App/App.service.ts index 9456b62c9..532f8d648 100644 --- a/packages/server-nest/src/modules/App/App.service.ts +++ b/packages/server-nest/src/modules/App/App.service.ts @@ -1,21 +1,10 @@ import { Injectable } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; -import { JwtService } from '@nestjs/jwt'; @Injectable() export class AppService { - // configService: ConfigService; - - constructor( - private configService: ConfigService, - private jwtService: JwtService, - ) {} + constructor() {} getHello(): string { - const payload = {}; - - const accessToken = this.jwtService.sign(payload); - - return accessToken; + return ''; } } diff --git a/packages/server-nest/src/modules/Auth/Auth.constants.ts b/packages/server-nest/src/modules/Auth/Auth.constants.ts index 6cb14c9a7..d888387c4 100644 --- a/packages/server-nest/src/modules/Auth/Auth.constants.ts +++ b/packages/server-nest/src/modules/Auth/Auth.constants.ts @@ -17,3 +17,12 @@ export const ERRORS = { SIGNUP_CONFIRM_TOKEN_INVALID: 'SIGNUP_CONFIRM_TOKEN_INVALID', USER_ALREADY_VERIFIED: 'USER_ALREADY_VERIFIED', }; + +export const IS_PUBLIC_ROUTE = 'isPublic'; + +export const SendResetPasswordMailQueue = 'SendResetPasswordMailQueue'; +export const SendResetPasswordMailJob = 'SendResetPasswordMailJob'; + +export const SendSignupVerificationMailQueue = + 'SendSignupVerificationMailQueue'; +export const SendSignupVerificationMailJob = 'SendSignupVerificationMailJob'; diff --git a/packages/server-nest/src/modules/Auth/Auth.controller.ts b/packages/server-nest/src/modules/Auth/Auth.controller.ts index 296906ced..1223327bd 100644 --- a/packages/server-nest/src/modules/Auth/Auth.controller.ts +++ b/packages/server-nest/src/modules/Auth/Auth.controller.ts @@ -8,11 +8,11 @@ import { UseGuards, } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiBody, ApiParam } from '@nestjs/swagger'; -import { JwtAuthGuard, PublicRoute } from './guards/Jwt.local'; +import { JwtAuthGuard, PublicRoute } from './guards/jwt.guard'; import { AuthenticationApplication } from './AuthApplication.sevice'; import { AuthSignupDto } from './dtos/AuthSignup.dto'; import { AuthSigninDto } from './dtos/AuthSignin.dto'; -import { LocalAuthGuard } from './guards/Local.guard'; +import { LocalAuthGuard } from './guards/local.guard'; import { JwtService } from '@nestjs/jwt'; import { AuthSigninService } from './commands/AuthSignin.service'; diff --git a/packages/server-nest/src/modules/Auth/Auth.module.ts b/packages/server-nest/src/modules/Auth/Auth.module.ts index 431dfc3b2..235656459 100644 --- a/packages/server-nest/src/modules/Auth/Auth.module.ts +++ b/packages/server-nest/src/modules/Auth/Auth.module.ts @@ -16,24 +16,31 @@ import { AuthenticationMailMesssages } from './AuthMailMessages.esrvice'; import { LocalStrategy } from './strategies/Local.strategy'; import { PassportModule } from '@nestjs/passport'; import { APP_GUARD } from '@nestjs/core'; -import { JwtAuthGuard } from './guards/Jwt.local'; +import { JwtAuthGuard } from './guards/jwt.guard'; +import { AuthMailSubscriber } from './Subscribers/AuthMail.subscriber'; +import { BullModule } from '@nestjs/bullmq'; +import { + SendResetPasswordMailQueue, + SendSignupVerificationMailQueue, +} from './Auth.constants'; +import { SendResetPasswordMailProcessor } from './processors/SendResetPasswordMail.processor'; +import { SendSignupVerificationMailProcessor } from './processors/SendSignupVerificationMail.processor'; +import { MailModule } from '../Mail/Mail.module'; const models = [RegisterTenancyModel(PasswordReset)]; @Module({ controllers: [AuthController], imports: [ + MailModule, PassportModule.register({ defaultStrategy: 'jwt' }), JwtModule.register({ - signOptions: { - expiresIn: '1d', - algorithm: 'HS384', - }, - verifyOptions: { - algorithms: ['HS384'], - }, + signOptions: { expiresIn: '1d', algorithm: 'HS384' }, + verifyOptions: { algorithms: ['HS384'] }, }), TenantDBManagerModule, + BullModule.registerQueue({ name: SendResetPasswordMailQueue }), + BullModule.registerQueue({ name: SendSignupVerificationMailQueue }), ...models, ], exports: [...models], @@ -48,10 +55,13 @@ const models = [RegisterTenancyModel(PasswordReset)]; AuthSignupService, AuthSigninService, AuthenticationMailMesssages, + SendResetPasswordMailProcessor, + SendSignupVerificationMailProcessor, { provide: APP_GUARD, useClass: JwtAuthGuard, }, + AuthMailSubscriber, ], }) export class AuthModule {} diff --git a/packages/server-nest/src/modules/Auth/commands/AuthSignin.service.ts b/packages/server-nest/src/modules/Auth/commands/AuthSignin.service.ts index c6cec91bb..0ca89fe6f 100644 --- a/packages/server-nest/src/modules/Auth/commands/AuthSignin.service.ts +++ b/packages/server-nest/src/modules/Auth/commands/AuthSignin.service.ts @@ -1,3 +1,4 @@ +import { ClsService } from 'nestjs-cls'; import { Inject, Injectable, UnauthorizedException } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { SystemUser } from '@/modules/System/models/SystemUser'; @@ -10,6 +11,7 @@ export class AuthSigninService { @Inject(SystemUser.name) private readonly systemUserModel: typeof SystemUser, private readonly jwtService: JwtService, + private readonly clsService: ClsService, ) {} /** @@ -42,6 +44,11 @@ export class AuthSigninService { return user; } + /** + * Verifies the given jwt payload. + * @param {JwtPayload} payload + * @returns {Promise} + */ async verifyPayload(payload: JwtPayload): Promise { let user: SystemUser; @@ -50,6 +57,9 @@ export class AuthSigninService { .query() .findOne({ email: payload.sub }) .throwIfNotFound(); + + this.clsService.set('tenantId', user.tenantId); + this.clsService.set('userId', user.id); } catch (error) { throw new UnauthorizedException( `There isn't any user with email: ${payload.sub}`, @@ -58,6 +68,11 @@ export class AuthSigninService { return payload; } + /** + * + * @param {SystemUser} user + * @returns {string} + */ signToken(user: SystemUser): string { const payload = { sub: user.email, diff --git a/packages/server-nest/src/modules/Auth/guards/Jwt.local.ts b/packages/server-nest/src/modules/Auth/guards/jwt.guard.ts similarity index 56% rename from packages/server-nest/src/modules/Auth/guards/Jwt.local.ts rename to packages/server-nest/src/modules/Auth/guards/jwt.guard.ts index b9e008f0b..00abe879b 100644 --- a/packages/server-nest/src/modules/Auth/guards/Jwt.local.ts +++ b/packages/server-nest/src/modules/Auth/guards/jwt.guard.ts @@ -1,15 +1,10 @@ -import { - ExecutionContext, - Injectable, - Scope, - SetMetadata, -} from '@nestjs/common'; +import { ExecutionContext, Injectable, SetMetadata } from '@nestjs/common'; import { Reflector } from '@nestjs/core'; import { AuthGuard } from '@nestjs/passport'; import { ClsService } from 'nestjs-cls'; +import { IS_PUBLIC_ROUTE } from '../Auth.constants'; -export const IS_PUBLIC_KEY = 'isPublic'; -export const PublicRoute = () => SetMetadata(IS_PUBLIC_KEY, true); +export const PublicRoute = () => SetMetadata(IS_PUBLIC_ROUTE, true); @Injectable() export class JwtAuthGuard extends AuthGuard('jwt') { @@ -21,10 +16,10 @@ export class JwtAuthGuard extends AuthGuard('jwt') { } canActivate(context: ExecutionContext) { - const isPublic = this.reflector.getAllAndOverride(IS_PUBLIC_KEY, [ - context.getHandler(), - context.getClass(), - ]); + const isPublic = this.reflector.getAllAndOverride( + IS_PUBLIC_ROUTE, + [context.getHandler(), context.getClass()], + ); if (isPublic) { return true; } diff --git a/packages/server-nest/src/modules/Auth/models/PasswordReset.ts b/packages/server-nest/src/modules/Auth/models/PasswordReset.ts index a996153a1..824a7c6f4 100644 --- a/packages/server-nest/src/modules/Auth/models/PasswordReset.ts +++ b/packages/server-nest/src/modules/Auth/models/PasswordReset.ts @@ -3,7 +3,6 @@ import { SystemModel } from '@/modules/System/models/SystemModel'; export class PasswordReset extends SystemModel { readonly email: string; readonly token: string; - readonly createdAt: Date; /** diff --git a/packages/server-nest/src/modules/Auth/processors/SendResetPasswordMail.processor.ts b/packages/server-nest/src/modules/Auth/processors/SendResetPasswordMail.processor.ts index e69de29bb..c4918e97e 100644 --- a/packages/server-nest/src/modules/Auth/processors/SendResetPasswordMail.processor.ts +++ b/packages/server-nest/src/modules/Auth/processors/SendResetPasswordMail.processor.ts @@ -0,0 +1,39 @@ +import { Processor, WorkerHost } from '@nestjs/bullmq'; +import { Scope } from '@nestjs/common'; +import { + SendResetPasswordMailJob, + SendResetPasswordMailQueue, +} from '../Auth.constants'; +import { Process } from '@nestjs/bull'; +import { Job } from 'bullmq'; +import { AuthenticationMailMesssages } from '../AuthMailMessages.esrvice'; +import { MailTransporter } from '@/modules/Mail/MailTransporter.service'; +import { ModelObject } from 'objection'; +import { SystemUser } from '@/modules/System/models/SystemUser'; + +@Processor({ + name: SendResetPasswordMailQueue, + scope: Scope.REQUEST, +}) +export class SendResetPasswordMailProcessor extends WorkerHost { + constructor( + private readonly authMailMesssages: AuthenticationMailMesssages, + private readonly mailTransporter: MailTransporter, + ) { + super(); + } + + @Process(SendResetPasswordMailJob) + async process(job: Job) { + const mail = this.authMailMesssages.sendResetPasswordMessage( + job.data.user, + job.data.token, + ); + await this.mailTransporter.send(mail); + } +} + +export interface SendResetPasswordMailJobPayload { + user: ModelObject; + token: string; +} diff --git a/packages/server-nest/src/modules/Auth/processors/SendSignupVerificationMail.processor.ts b/packages/server-nest/src/modules/Auth/processors/SendSignupVerificationMail.processor.ts index e69de29bb..3abe9b8e6 100644 --- a/packages/server-nest/src/modules/Auth/processors/SendSignupVerificationMail.processor.ts +++ b/packages/server-nest/src/modules/Auth/processors/SendSignupVerificationMail.processor.ts @@ -0,0 +1,40 @@ +import { Scope } from '@nestjs/common'; +import { Job } from 'bullmq'; +import { Process } from '@nestjs/bull'; +import { Processor, WorkerHost } from '@nestjs/bullmq'; +import { + SendSignupVerificationMailJob, + SendSignupVerificationMailQueue, +} from '../Auth.constants'; +import { MailTransporter } from '@/modules/Mail/MailTransporter.service'; +import { AuthenticationMailMesssages } from '../AuthMailMessages.esrvice'; + +@Processor({ + name: SendSignupVerificationMailQueue, + scope: Scope.REQUEST, +}) +export class SendSignupVerificationMailProcessor extends WorkerHost { + constructor( + private readonly authMailMesssages: AuthenticationMailMesssages, + private readonly mailTransporter: MailTransporter, + ) { + super(); + } + + @Process(SendSignupVerificationMailJob) + async process(job: Job) { + console.log('triggerd'); + const mail = this.authMailMesssages.sendSignupVerificationMail( + job.data.email, + job.data.fullName, + job.data.token, + ); + await this.mailTransporter.send(mail); + } +} + +export interface SendSignupVerificationMailJobPayload { + email: string; + fullName: string; + token: string; +} diff --git a/packages/server-nest/src/modules/Auth/subscribers/AuthMail.subscriber.ts b/packages/server-nest/src/modules/Auth/subscribers/AuthMail.subscriber.ts new file mode 100644 index 000000000..8af9cbc8f --- /dev/null +++ b/packages/server-nest/src/modules/Auth/subscribers/AuthMail.subscriber.ts @@ -0,0 +1,68 @@ +import { Injectable } from '@nestjs/common'; +import { events } from '@/common/events/events'; +import { OnEvent } from '@nestjs/event-emitter'; +import { + IAuthSendedResetPassword, + IAuthSignedUpEventPayload, +} from '../Auth.interfaces'; +import { Queue } from 'bullmq'; +import { InjectQueue } from '@nestjs/bullmq'; +import { SendResetPasswordMailJobPayload } from '../processors/SendResetPasswordMail.processor'; +import { + SendResetPasswordMailJob, + SendResetPasswordMailQueue, + SendSignupVerificationMailJob, + SendSignupVerificationMailQueue, +} from '../Auth.constants'; +import { SendSignupVerificationMailJobPayload } from '../processors/SendSignupVerificationMail.processor'; + +@Injectable() +export class AuthMailSubscriber { + constructor( + @InjectQueue(SendResetPasswordMailQueue) + private readonly sendResetPasswordMailQueue: Queue, + + @InjectQueue(SendSignupVerificationMailQueue) + private readonly sendSignupVerificationMailQueue: Queue, + ) {} + + /** + * @param {IAuthSignedUpEventPayload} payload + */ + @OnEvent(events.auth.signUp) + async handleSignupSendVerificationMail(payload: IAuthSignedUpEventPayload) { + try { + const job = await this.sendSignupVerificationMailQueue.add( + SendSignupVerificationMailJob, + { + email: payload.user.email, + fullName: payload.user.firstName, + token: payload.user.verifyToken, + } as SendSignupVerificationMailJobPayload, + { + delay: 0, + }, + ); + console.log(job); + } catch (error) { + console.log(error); + } + } + + /** + * @param {IAuthSendedResetPassword} payload + */ + @OnEvent(events.auth.sendResetPassword) + async handleSendResetPasswordMail(payload: IAuthSendedResetPassword) { + await this.sendResetPasswordMailQueue.add( + SendResetPasswordMailJob, + { + user: payload.user, + token: payload.token, + } as SendResetPasswordMailJobPayload, + { + delay: 0, + }, + ); + } +} diff --git a/packages/server-nest/src/modules/BankRules/BankRules.controller.ts b/packages/server-nest/src/modules/BankRules/BankRules.controller.ts index 0fe3e8027..127c58dd7 100644 --- a/packages/server-nest/src/modules/BankRules/BankRules.controller.ts +++ b/packages/server-nest/src/modules/BankRules/BankRules.controller.ts @@ -9,15 +9,12 @@ import { Put, } from '@nestjs/common'; import { BankRulesApplication } from './BankRulesApplication'; -import { ICreateBankRuleDTO, IEditBankRuleDTO } from './types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { BankRule } from './models/BankRule'; import { CreateBankRuleDto } from './dtos/BankRule.dto'; import { EditBankRuleDto } from './dtos/BankRule.dto'; @Controller('banking/rules') @ApiTags('bank-rules') -@PublicRoute() export class BankRulesController { constructor(private readonly bankRulesApplication: BankRulesApplication) {} diff --git a/packages/server-nest/src/modules/BankRules/commands/CreateBankRule.service.ts b/packages/server-nest/src/modules/BankRules/commands/CreateBankRule.service.ts index a7bf7c584..7ea7abbd5 100644 --- a/packages/server-nest/src/modules/BankRules/commands/CreateBankRule.service.ts +++ b/packages/server-nest/src/modules/BankRules/commands/CreateBankRule.service.ts @@ -1,13 +1,12 @@ import { ModelObject } from 'objection'; import { Knex } from 'knex'; import { Inject, Injectable } from '@nestjs/common'; +import { EventEmitter2 } from '@nestjs/event-emitter'; import { IBankRuleEventCreatedPayload, IBankRuleEventCreatingPayload, - ICreateBankRuleDTO, } from '../types'; import { UnitOfWork } from '../../Tenancy/TenancyDB/UnitOfWork.service'; -import { EventEmitter2 } from '@nestjs/event-emitter'; import { events } from '@/common/events/events'; import { BankRule } from '../models/BankRule'; import { CreateBankRuleDto } from '../dtos/BankRule.dto'; diff --git a/packages/server-nest/src/modules/BankingTransactions/BankingTransactions.controller.ts b/packages/server-nest/src/modules/BankingTransactions/BankingTransactions.controller.ts index bb5b6cbb3..fc1ba8c83 100644 --- a/packages/server-nest/src/modules/BankingTransactions/BankingTransactions.controller.ts +++ b/packages/server-nest/src/modules/BankingTransactions/BankingTransactions.controller.ts @@ -7,15 +7,13 @@ import { Post, Query, } from '@nestjs/common'; +import { ApiTags } from '@nestjs/swagger'; import { BankingTransactionsApplication } from './BankingTransactionsApplication.service'; import { IBankAccountsFilter } from './types/BankingTransactions.types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; -import { ApiTags } from '@nestjs/swagger'; import { CreateBankTransactionDto } from './dtos/CreateBankTransaction.dto'; @Controller('banking/transactions') @ApiTags('banking-transactions') -@PublicRoute() export class BankingTransactionsController { constructor( private readonly bankingTransactionsApplication: BankingTransactionsApplication, diff --git a/packages/server-nest/src/modules/Bills/Bills.controller.ts b/packages/server-nest/src/modules/Bills/Bills.controller.ts index 07af52370..ac38703fa 100644 --- a/packages/server-nest/src/modules/Bills/Bills.controller.ts +++ b/packages/server-nest/src/modules/Bills/Bills.controller.ts @@ -11,12 +11,10 @@ import { } from '@nestjs/common'; import { BillsApplication } from './Bills.application'; import { IBillsFilter } from './Bills.types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { CreateBillDto, EditBillDto } from './dtos/Bill.dto'; @Controller('bills') @ApiTags('bills') -@PublicRoute() export class BillsController { constructor(private billsApplication: BillsApplication) {} diff --git a/packages/server-nest/src/modules/Branches/Branches.controller.ts b/packages/server-nest/src/modules/Branches/Branches.controller.ts index 4d9dc11a1..81e2fc9fe 100644 --- a/packages/server-nest/src/modules/Branches/Branches.controller.ts +++ b/packages/server-nest/src/modules/Branches/Branches.controller.ts @@ -9,12 +9,10 @@ import { } from '@nestjs/common'; import { BranchesApplication } from './BranchesApplication.service'; import { CreateBranchDto, EditBranchDto } from './dtos/Branch.dto'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('branches') @ApiTags('branches') -@PublicRoute() export class BranchesController { constructor(private readonly branchesApplication: BranchesApplication) {} diff --git a/packages/server-nest/src/modules/CreditNotes/CreditNotes.controller.ts b/packages/server-nest/src/modules/CreditNotes/CreditNotes.controller.ts index 370beb717..b86853bd0 100644 --- a/packages/server-nest/src/modules/CreditNotes/CreditNotes.controller.ts +++ b/packages/server-nest/src/modules/CreditNotes/CreditNotes.controller.ts @@ -10,13 +10,11 @@ import { } from '@nestjs/common'; import { CreditNoteApplication } from './CreditNoteApplication.service'; import { ICreditNotesQueryDTO } from './types/CreditNotes.types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiTags } from '@nestjs/swagger'; import { CreateCreditNoteDto, EditCreditNoteDto } from './dtos/CreditNote.dto'; @Controller('credit-notes') @ApiTags('credit-notes') -@PublicRoute() export class CreditNotesController { /** * @param {CreditNoteApplication} creditNoteApplication - The credit note application service. diff --git a/packages/server-nest/src/modules/Customers/Customers.controller.ts b/packages/server-nest/src/modules/Customers/Customers.controller.ts index 7a26dcf49..a0789e451 100644 --- a/packages/server-nest/src/modules/Customers/Customers.controller.ts +++ b/packages/server-nest/src/modules/Customers/Customers.controller.ts @@ -9,14 +9,12 @@ import { } from '@nestjs/common'; import { CustomersApplication } from './CustomersApplication.service'; import { ICustomerOpeningBalanceEditDTO } from './types/Customers.types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { CreateCustomerDto } from './dtos/CreateCustomer.dto'; import { EditCustomerDto } from './dtos/EditCustomer.dto'; @Controller('customers') @ApiTags('customers') -@PublicRoute() export class CustomersController { constructor(private customersApplication: CustomersApplication) {} diff --git a/packages/server-nest/src/modules/Expenses/Expenses.controller.ts b/packages/server-nest/src/modules/Expenses/Expenses.controller.ts index c180a8938..1a84199a5 100644 --- a/packages/server-nest/src/modules/Expenses/Expenses.controller.ts +++ b/packages/server-nest/src/modules/Expenses/Expenses.controller.ts @@ -9,14 +9,12 @@ import { Query, } from '@nestjs/common'; import { ExpensesApplication } from './ExpensesApplication.service'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { IExpensesFilter } from './Expenses.types'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { CreateExpenseDto, EditExpenseDto } from './dtos/Expense.dto'; @Controller('expenses') @ApiTags('expenses') -@PublicRoute() export class ExpensesController { constructor(private readonly expensesApplication: ExpensesApplication) {} diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts index 9d5cbdd1b..572eeb981 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts @@ -4,11 +4,9 @@ import { IAPAgingSummaryQuery } from './APAgingSummary.types'; import { AcceptType } from '@/constants/accept-type'; import { Response } from 'express'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; @Controller('reports/payable-aging-summary') @ApiTags('reports') -@PublicRoute() export class APAgingSummaryController { constructor(private readonly APAgingSummaryApp: APAgingSummaryApplication) {} diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts index 8711857ed..15a85c656 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts @@ -4,12 +4,10 @@ import { Query, Res } from '@nestjs/common'; import { ARAgingSummaryApplication } from './ARAgingSummaryApplication'; import { AcceptType } from '@/constants/accept-type'; import { Response } from 'express'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; @Controller('reports/receivable-aging-summary') @ApiTags('reports') -@PublicRoute() export class ARAgingSummaryController { constructor(private readonly ARAgingSummaryApp: ARAgingSummaryApplication) {} diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts index 488c8cfe1..7be695523 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts @@ -3,11 +3,9 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common'; import { ICashFlowStatementQuery } from './Cashflow.types'; import { AcceptType } from '@/constants/accept-type'; import { CashflowSheetApplication } from './CashflowSheetApplication'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('reports/cashflow-statement') -@PublicRoute() @ApiTags('reports') export class CashflowController { constructor(private readonly cashflowSheetApp: CashflowSheetApplication) {} diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts index 9ecadfbbe..dd29559ce 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts @@ -4,11 +4,9 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common'; import { ICustomerBalanceSummaryQuery } from './CustomerBalanceSummary.types'; import { CustomerBalanceSummaryApplication } from './CustomerBalanceSummaryApplication'; import { AcceptType } from '@/constants/accept-type'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; @Controller('/reports/customer-balance-summary') @ApiTags('reports') -@PublicRoute() export class CustomerBalanceSummaryController { constructor( private readonly customerBalanceSummaryApp: CustomerBalanceSummaryApplication, diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts index f7d23b054..ff954e1d7 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts @@ -4,11 +4,9 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common'; import { IGeneralLedgerSheetQuery } from './GeneralLedger.types'; import { GeneralLedgerApplication } from './GeneralLedgerApplication'; import { AcceptType } from '@/constants/accept-type'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; @Controller('/reports/general-ledger') @ApiTags('reports') -@PublicRoute() export class GeneralLedgerController { constructor( private readonly generalLedgerApplication: GeneralLedgerApplication, diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts index 9955e2359..9689ae747 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts @@ -3,11 +3,9 @@ import { InventoryItemDetailsApplication } from './InventoryItemDetailsApplicati import { IInventoryDetailsQuery } from './InventoryItemDetails.types'; import { AcceptType } from '@/constants/accept-type'; import { Response } from 'express'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; @Controller('reports/inventory-item-details') -@PublicRoute() @ApiTags('reports') export class InventoryItemDetailsController { constructor( diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts index 64f18186e..2dbb9eff7 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts @@ -4,10 +4,8 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common'; import { InventoryValuationSheetApplication } from './InventoryValuationSheetApplication'; import { IInventoryValuationReportQuery } from './InventoryValuationSheet.types'; import { AcceptType } from '@/constants/accept-type'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; @Controller('reports/inventory-valuation') -@PublicRoute() @ApiTags('reports') export class InventoryValuationController { constructor( diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts index f57d46d66..e62e1ae40 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts @@ -4,11 +4,9 @@ import { Response } from 'express'; import { AcceptType } from '@/constants/accept-type'; import { JournalSheetApplication } from './JournalSheetApplication'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; @Controller('/reports/journal') @ApiTags('reports') -@PublicRoute() export class JournalSheetController { constructor(private readonly journalSheetApp: JournalSheetApplication) {} diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts index de2c0d833..0865ccd40 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts @@ -3,12 +3,10 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common'; import { IProfitLossSheetQuery } from './ProfitLossSheet.types'; import { ProfitLossSheetApplication } from './ProfitLossSheetApplication'; import { AcceptType } from '@/constants/accept-type'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('/reports/profit-loss-sheet') @ApiTags('reports') -@PublicRoute() export class ProfitLossSheetController { constructor( private readonly profitLossSheetApp: ProfitLossSheetApplication, diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts index 3af0aad26..f19d4f534 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts @@ -3,16 +3,9 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common'; import { PurchasesByItemsApplication } from './PurchasesByItemsApplication'; import { IPurchasesByItemsReportQuery } from './types/PurchasesByItems.types'; import { AcceptType } from '@/constants/accept-type'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; -import { - ApiOperation, - ApiResponse, - ApiResponseProperty, - ApiTags, -} from '@nestjs/swagger'; +import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('/reports/purchases-by-items') -@PublicRoute() @ApiTags('reports') export class PurchasesByItemReportController { constructor( diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts index f551855f8..0788a32bb 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts @@ -3,12 +3,10 @@ import { SalesTaxLiabilitySummaryQuery } from './SalesTaxLiability.types'; import { AcceptType } from '@/constants/accept-type'; import { SalesTaxLiabilitySummaryApplication } from './SalesTaxLiabilitySummaryApplication'; import { Response } from 'express'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('/reports/sales-tax-liability-summary') @ApiTags('reports') -@PublicRoute() export class SalesTaxLiabilitySummaryController { constructor( private readonly salesTaxLiabilitySummaryApp: SalesTaxLiabilitySummaryApplication, diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts index 6bafa7686..14852bd05 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts @@ -4,11 +4,9 @@ import { ITransactionsByCustomersFilter } from './TransactionsByCustomer.types'; import { TransactionsByCustomerApplication } from './TransactionsByCustomersApplication'; import { AcceptType } from '@/constants/accept-type'; import { Response } from 'express'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; @Controller('/reports/transactions-by-customers') @ApiTags('reports') -@PublicRoute() export class TransactionsByCustomerController { constructor( private readonly transactionsByCustomersApp: TransactionsByCustomerApplication, diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReference.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReference.controller.ts index f0566f8c3..7b252082f 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReference.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByReference/TransactionsByReference.controller.ts @@ -1,12 +1,10 @@ import { Controller, Get, Query } from '@nestjs/common'; import { TransactionsByReferenceApplication } from './TransactionsByReferenceApplication'; import { ITransactionsByReferenceQuery } from './TransactionsByReference.types'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('reports/transactions-by-reference') @ApiTags('reports') -@PublicRoute() export class TransactionsByReferenceController { constructor( private readonly transactionsByReferenceApp: TransactionsByReferenceApplication, diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts index 3b02ba1e0..8fbb782fc 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts @@ -4,11 +4,9 @@ import { AcceptType } from '@/constants/accept-type'; import { Response } from 'express'; import { TransactionsByVendorApplication } from './TransactionsByVendorApplication'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; @Controller('/reports/transactions-by-vendors') @ApiTags('reports') -@PublicRoute() export class TransactionsByVendorController { constructor( private readonly transactionsByVendorsApp: TransactionsByVendorApplication, diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts index 1aec2e805..af83cf9b4 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts @@ -5,11 +5,9 @@ import { Response } from 'express'; import { ITrialBalanceSheetQuery } from './TrialBalanceSheet.types'; import { AcceptType } from '@/constants/accept-type'; import { TrialBalanceSheetApplication } from './TrialBalanceSheetApplication'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; @Controller('reports/trial-balance-sheet') @ApiTags('reports') -@PublicRoute() export class TrialBalanceSheetController { constructor( private readonly trialBalanceSheetApp: TrialBalanceSheetApplication, diff --git a/packages/server-nest/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts b/packages/server-nest/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts index 45bd55e7b..34a4c2431 100644 --- a/packages/server-nest/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts +++ b/packages/server-nest/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts @@ -4,11 +4,9 @@ import { VendorBalanceSummaryApplication } from './VendorBalanceSummaryApplicati import { Response } from 'express'; import { AcceptType } from '@/constants/accept-type'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { PublicRoute } from '@/modules/Auth/guards/Jwt.local'; @Controller('/reports/vendor-balance-summary') @ApiTags('reports') -@PublicRoute() export class VendorBalanceSummaryController { constructor( private readonly vendorBalanceSummaryApp: VendorBalanceSummaryApplication, diff --git a/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.controller.ts b/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.controller.ts index 9a16d9935..8d66a5f86 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.controller.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.controller.ts @@ -9,19 +9,14 @@ import { Query, } from '@nestjs/common'; import { InventoryAdjustmentsApplicationService } from './InventoryAdjustmentsApplication.service'; -import { - IInventoryAdjustmentsFilter, - IQuickInventoryAdjustmentDTO, -} from './types/InventoryAdjustments.types'; +import { IInventoryAdjustmentsFilter } from './types/InventoryAdjustments.types'; import { InventoryAdjustment } from './models/InventoryAdjustment'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { IPaginationMeta } from '@/interfaces/Model'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { CreateQuickInventoryAdjustmentDto } from './dtos/CreateQuickInventoryAdjustment.dto'; @Controller('inventory-adjustments') @ApiTags('inventory-adjustments') -@PublicRoute() export class InventoryAdjustmentsController { constructor( private readonly inventoryAdjustmentsApplicationService: InventoryAdjustmentsApplicationService, diff --git a/packages/server-nest/src/modules/ItemCategories/ItemCategory.controller.ts b/packages/server-nest/src/modules/ItemCategories/ItemCategory.controller.ts index 8b1967ba7..7d0bfa326 100644 --- a/packages/server-nest/src/modules/ItemCategories/ItemCategory.controller.ts +++ b/packages/server-nest/src/modules/ItemCategories/ItemCategory.controller.ts @@ -13,7 +13,6 @@ import { GetItemCategoriesResponse, IItemCategoriesFilter, } from './ItemCategory.interfaces'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { CreateItemCategoryDto, @@ -22,7 +21,6 @@ import { @Controller('item-categories') @ApiTags('item-categories') -@PublicRoute() export class ItemCategoryController { constructor( private readonly itemCategoryApplication: ItemCategoryApplication, diff --git a/packages/server-nest/src/modules/Items/GetItem.service.ts b/packages/server-nest/src/modules/Items/GetItem.service.ts index b815aa2c2..d035cc0ac 100644 --- a/packages/server-nest/src/modules/Items/GetItem.service.ts +++ b/packages/server-nest/src/modules/Items/GetItem.service.ts @@ -5,13 +5,16 @@ import { events } from '@/common/events/events'; import { TransformerInjectable } from '../Transformer/TransformerInjectable.service'; import { ItemTransformer } from './Item.transformer'; import { TenantModelProxy } from '../System/models/TenantBaseModel'; +import { ClsService } from 'nestjs-cls'; @Injectable() export class GetItemService { constructor( - @Inject(Item.name) private itemModel: TenantModelProxy, - private eventEmitter2: EventEmitter2, - private transformerInjectable: TransformerInjectable, + @Inject(Item.name) + private readonly itemModel: TenantModelProxy, + private readonly eventEmitter2: EventEmitter2, + private readonly transformerInjectable: TransformerInjectable, + private readonly clsService: ClsService, ) {} /** diff --git a/packages/server-nest/src/modules/Items/Item.controller.ts b/packages/server-nest/src/modules/Items/Item.controller.ts index b97573f67..18aa661f7 100644 --- a/packages/server-nest/src/modules/Items/Item.controller.ts +++ b/packages/server-nest/src/modules/Items/Item.controller.ts @@ -12,7 +12,7 @@ import { } from '@nestjs/common'; import { TenantController } from '../Tenancy/Tenant.controller'; import { SubscriptionGuard } from '../Subscription/interceptors/Subscription.guard'; -import { JwtAuthGuard, PublicRoute } from '../Auth/guards/Jwt.local'; +import { JwtAuthGuard } from '../Auth/guards/jwt.guard'; import { ItemsApplicationService } from './ItemsApplication.service'; import { ApiOperation, diff --git a/packages/server-nest/src/modules/ManualJournals/ManualJournals.controller.ts b/packages/server-nest/src/modules/ManualJournals/ManualJournals.controller.ts index 3de18c3cb..4a1d57405 100644 --- a/packages/server-nest/src/modules/ManualJournals/ManualJournals.controller.ts +++ b/packages/server-nest/src/modules/ManualJournals/ManualJournals.controller.ts @@ -8,8 +8,6 @@ import { Put, } from '@nestjs/common'; import { ManualJournalsApplication } from './ManualJournalsApplication.service'; -import { IManualJournalDTO } from './types/ManualJournals.types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger'; import { CreateManualJournalDto, @@ -18,7 +16,6 @@ import { @Controller('manual-journals') @ApiTags('manual-journals') -@PublicRoute() export class ManualJournalsController { constructor(private manualJournalsApplication: ManualJournalsApplication) {} diff --git a/packages/server-nest/src/modules/Organization/Organization.controller.ts b/packages/server-nest/src/modules/Organization/Organization.controller.ts index f6b92b77c..5721f6248 100644 --- a/packages/server-nest/src/modules/Organization/Organization.controller.ts +++ b/packages/server-nest/src/modules/Organization/Organization.controller.ts @@ -17,11 +17,9 @@ import { import { GetCurrentOrganizationService } from './queries/GetCurrentOrganization.service'; import { UpdateOrganizationService } from './commands/UpdateOrganization.service'; import { ApiTags, ApiOperation, ApiResponse, ApiBody } from '@nestjs/swagger'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; @ApiTags('Organization') @Controller('organization') -@PublicRoute() export class OrganizationController { constructor( private readonly buildOrganizationService: BuildOrganizationService, diff --git a/packages/server-nest/src/modules/PaymentReceived/PaymentsReceived.controller.ts b/packages/server-nest/src/modules/PaymentReceived/PaymentsReceived.controller.ts index c70318ea6..17be37e58 100644 --- a/packages/server-nest/src/modules/PaymentReceived/PaymentsReceived.controller.ts +++ b/packages/server-nest/src/modules/PaymentReceived/PaymentsReceived.controller.ts @@ -17,12 +17,10 @@ import { IPaymentsReceivedFilter, PaymentReceiveMailOptsDTO, } from './types/PaymentReceived.types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('payments-received') @ApiTags('payments-received') -@PublicRoute() export class PaymentReceivesController { constructor(private paymentReceivesApplication: PaymentReceivesApplication) {} diff --git a/packages/server-nest/src/modules/PaymentServices/PaymentServices.controller.ts b/packages/server-nest/src/modules/PaymentServices/PaymentServices.controller.ts index 466153485..c760681ef 100644 --- a/packages/server-nest/src/modules/PaymentServices/PaymentServices.controller.ts +++ b/packages/server-nest/src/modules/PaymentServices/PaymentServices.controller.ts @@ -8,19 +8,15 @@ import { Req, Res, Next, - UsePipes, - ValidationPipe, HttpStatus, } from '@nestjs/common'; import { Request, Response, NextFunction } from 'express'; import { ApiTags } from '@nestjs/swagger'; import { PaymentServicesApplication } from './PaymentServicesApplication'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { EditPaymentMethodDTO } from './types'; @ApiTags('PaymentServices') @Controller('payment-services') -@PublicRoute() export class PaymentServicesController { constructor( private readonly paymentServicesApp: PaymentServicesApplication, diff --git a/packages/server-nest/src/modules/PdfTemplate/PdfTemplates.controller.ts b/packages/server-nest/src/modules/PdfTemplate/PdfTemplates.controller.ts index 9ee69ea93..58b19e08b 100644 --- a/packages/server-nest/src/modules/PdfTemplate/PdfTemplates.controller.ts +++ b/packages/server-nest/src/modules/PdfTemplate/PdfTemplates.controller.ts @@ -1,3 +1,4 @@ +import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { Body, Controller, @@ -9,12 +10,9 @@ import { } from '@nestjs/common'; import { PdfTemplateApplication } from './PdfTemplate.application'; import { ICreateInvoicePdfTemplateDTO, IEditPdfTemplateDTO } from './types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; -import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('pdf-templates') @ApiTags('pdf-templates') -@PublicRoute() export class PdfTemplatesController { constructor( private readonly pdfTemplateApplication: PdfTemplateApplication, diff --git a/packages/server-nest/src/modules/Roles/Roles.controller.ts b/packages/server-nest/src/modules/Roles/Roles.controller.ts index ac2c7a7d1..6a61bf358 100644 --- a/packages/server-nest/src/modules/Roles/Roles.controller.ts +++ b/packages/server-nest/src/modules/Roles/Roles.controller.ts @@ -12,7 +12,6 @@ import { ParseIntPipe, } from '@nestjs/common'; import { Response, NextFunction } from 'express'; -import { Injectable } from '@nestjs/common'; import { CreateRoleDto, EditRoleDto } from './dtos/Role.dto'; import { RolesApplication } from './Roles.application'; import { @@ -22,11 +21,9 @@ import { ApiParam, ApiBody, } from '@nestjs/swagger'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; @ApiTags('Roles') @Controller('roles') -@PublicRoute() export class RolesController { constructor(private readonly rolesApp: RolesApplication) {} diff --git a/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.controller.ts b/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.controller.ts index e4241a8c3..ca2ebef0a 100644 --- a/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.controller.ts +++ b/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.controller.ts @@ -17,7 +17,6 @@ import { SaleEstimateMailOptionsDTO, } from './types/SaleEstimates.types'; import { SaleEstimate } from './models/SaleEstimate'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { CreateSaleEstimateDto, EditSaleEstimateDto, @@ -25,7 +24,6 @@ import { @Controller('sale-estimates') @ApiTags('sale-estimates') -@PublicRoute() export class SaleEstimatesController { /** * @param {SaleEstimatesApplication} saleEstimatesApplication - Sale estimates application. diff --git a/packages/server-nest/src/modules/SaleInvoices/SaleInvoices.controller.ts b/packages/server-nest/src/modules/SaleInvoices/SaleInvoices.controller.ts index caf8fb62d..5589ebdf5 100644 --- a/packages/server-nest/src/modules/SaleInvoices/SaleInvoices.controller.ts +++ b/packages/server-nest/src/modules/SaleInvoices/SaleInvoices.controller.ts @@ -17,7 +17,6 @@ import { SendInvoiceMailDTO, } from './SaleInvoice.types'; import { SaleInvoiceApplication } from './SaleInvoices.application'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiHeader, ApiOperation, @@ -42,7 +41,6 @@ import { description: 'The authentication token', required: true, }) -@PublicRoute() export class SaleInvoicesController { constructor(private saleInvoiceApplication: SaleInvoiceApplication) {} diff --git a/packages/server-nest/src/modules/SaleReceipts/SaleReceipts.controller.ts b/packages/server-nest/src/modules/SaleReceipts/SaleReceipts.controller.ts index 61d32b332..b122ff558 100644 --- a/packages/server-nest/src/modules/SaleReceipts/SaleReceipts.controller.ts +++ b/packages/server-nest/src/modules/SaleReceipts/SaleReceipts.controller.ts @@ -10,7 +10,6 @@ import { Put, } from '@nestjs/common'; import { SaleReceiptApplication } from './SaleReceiptApplication.service'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'; import { CreateSaleReceiptDto, @@ -19,7 +18,6 @@ import { @Controller('sale-receipts') @ApiTags('sale-receipts') -@PublicRoute() export class SaleReceiptsController { constructor(private saleReceiptApplication: SaleReceiptApplication) {} diff --git a/packages/server-nest/src/modules/Settings/Settings.controller.ts b/packages/server-nest/src/modules/Settings/Settings.controller.ts index da29ce0d5..fd91fba33 100644 --- a/packages/server-nest/src/modules/Settings/Settings.controller.ts +++ b/packages/server-nest/src/modules/Settings/Settings.controller.ts @@ -1,12 +1,10 @@ import { Body, Controller, Get, Post, Put } from '@nestjs/common'; import { SettingsApplicationService } from './SettingsApplication.service'; import { ISettingsDTO } from './Settings.types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; @Controller('settings') @ApiTags('settings') -@PublicRoute() export class SettingsController { constructor( private readonly settingsApplicationService: SettingsApplicationService, diff --git a/packages/server-nest/src/modules/Subscription/subscribers/SubscribeFreeOnSignupCommunity.ts b/packages/server-nest/src/modules/Subscription/subscribers/SubscribeFreeOnSignupCommunity.ts index 1aad78b12..0faddde21 100644 --- a/packages/server-nest/src/modules/Subscription/subscribers/SubscribeFreeOnSignupCommunity.ts +++ b/packages/server-nest/src/modules/Subscription/subscribers/SubscribeFreeOnSignupCommunity.ts @@ -17,13 +17,9 @@ export class SubscribeFreeOnSignupCommunity { * @returns {Promise} */ @OnEvent(events.auth.signUp) - async subscribeFreeOnSigupCommunity({ - signupDTO, - tenant, - user, - }) { + async subscribeFreeOnSigupCommunity({ signupDTO, tenant, user }) { if (this.configService.get('hostedOnBigcapitalCloud')) return null; - await this.subscriptionApp.createNewSubscription('free'); + // await this.subscriptionApp.createNewSubscription('free'); } } diff --git a/packages/server-nest/src/modules/TaxRates/TaxRate.controller.ts b/packages/server-nest/src/modules/TaxRates/TaxRate.controller.ts index 588398288..3d360e6b8 100644 --- a/packages/server-nest/src/modules/TaxRates/TaxRate.controller.ts +++ b/packages/server-nest/src/modules/TaxRates/TaxRate.controller.ts @@ -8,13 +8,11 @@ import { Put, } from '@nestjs/common'; import { TaxRatesApplication } from './TaxRate.application'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { CreateTaxRateDto, EditTaxRateDto } from './dtos/TaxRate.dto'; @Controller('tax-rates') @ApiTags('tax-rates') -@PublicRoute() export class TaxRatesController { constructor(private readonly taxRatesApplication: TaxRatesApplication) {} diff --git a/packages/server-nest/src/modules/Tenancy/TenancyGlobal.guard.ts b/packages/server-nest/src/modules/Tenancy/TenancyGlobal.guard.ts new file mode 100644 index 000000000..acee9bda9 --- /dev/null +++ b/packages/server-nest/src/modules/Tenancy/TenancyGlobal.guard.ts @@ -0,0 +1,35 @@ +import { + Injectable, + CanActivate, + ExecutionContext, + UnauthorizedException, +} from '@nestjs/common'; +import { Reflector } from '@nestjs/core'; +import { IS_PUBLIC_ROUTE } from '../Auth/Auth.constants'; + +@Injectable() +export class TenancyGlobalGuard implements CanActivate { + constructor(private reflector: Reflector) {} + + /** + * Validates the organization ID in the request headers. + * @param {ExecutionContext} context + * @returns {boolean} + */ + canActivate(context: ExecutionContext): boolean { + const request = context.switchToHttp().getRequest(); + const organizationId = request.headers['organization-id']; + + const isPublic = this.reflector.getAllAndOverride( + IS_PUBLIC_ROUTE, + [context.getHandler(), context.getClass()], + ); + if (isPublic) { + return true; + } + if (!organizationId) { + throw new UnauthorizedException('Organization ID is required.'); + } + return true; + } +} diff --git a/packages/server-nest/src/modules/Tenancy/TenancyModels/Tenancy.module.ts b/packages/server-nest/src/modules/Tenancy/TenancyModels/Tenancy.module.ts index 66f3e1b40..50badda8d 100644 --- a/packages/server-nest/src/modules/Tenancy/TenancyModels/Tenancy.module.ts +++ b/packages/server-nest/src/modules/Tenancy/TenancyModels/Tenancy.module.ts @@ -40,6 +40,8 @@ import { PaymentReceived } from '@/modules/PaymentReceived/models/PaymentReceive import { Model } from 'objection'; import { ClsModule } from 'nestjs-cls'; import { TenantUser } from './models/TenantUser.model'; +import { APP_GUARD } from '@nestjs/core'; +import { TenancyGlobalGuard } from '../TenancyGlobal.guard'; const models = [ Item, @@ -106,5 +108,11 @@ const modelProviders = models.map((model) => RegisterTenancyModel(model)); @Module({ imports: [...modelProviders], exports: [...modelProviders], + providers: [ + { + provide: APP_GUARD, + useClass: TenancyGlobalGuard, + }, + ], }) export class TenancyModelsModule {} diff --git a/packages/server-nest/src/modules/TransactionsLocking/TransactionsLocking.controller.ts b/packages/server-nest/src/modules/TransactionsLocking/TransactionsLocking.controller.ts index 4da17606a..0e605ae1d 100644 --- a/packages/server-nest/src/modules/TransactionsLocking/TransactionsLocking.controller.ts +++ b/packages/server-nest/src/modules/TransactionsLocking/TransactionsLocking.controller.ts @@ -1,11 +1,10 @@ +import { ApiOperation } from '@nestjs/swagger'; +import { ApiTags } from '@nestjs/swagger'; import { Controller, Put, Get, Body, Param } from '@nestjs/common'; import { TransactionsLockingService } from './commands/CommandTransactionsLockingService'; import { TransactionsLockingGroup } from './types/TransactionsLocking.types'; import { ITransactionLockingPartiallyDTO } from './types/TransactionsLocking.types'; import { QueryTransactionsLocking } from './queries/QueryTransactionsLocking'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; -import { ApiOperation } from '@nestjs/swagger'; -import { ApiTags } from '@nestjs/swagger'; import { CancelTransactionsLockingDto, TransactionsLockingDto, @@ -13,7 +12,6 @@ import { @Controller('transactions-locking') @ApiTags('Transactions Locking') -@PublicRoute() export class TransactionsLockingController { constructor( private readonly transactionsLockingService: TransactionsLockingService, diff --git a/packages/server-nest/src/modules/VendorCredit/VendorCredits.controller.ts b/packages/server-nest/src/modules/VendorCredit/VendorCredits.controller.ts index a2dda11f4..99c8b7a4c 100644 --- a/packages/server-nest/src/modules/VendorCredit/VendorCredits.controller.ts +++ b/packages/server-nest/src/modules/VendorCredit/VendorCredits.controller.ts @@ -10,7 +10,6 @@ import { } from '@nestjs/common'; import { VendorCreditsApplicationService } from './VendorCreditsApplication.service'; import { IVendorCreditsQueryDTO } from './types/VendorCredit.types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { CreateVendorCreditDto, @@ -19,7 +18,6 @@ import { @Controller('vendor-credits') @ApiTags('vendor-credits') -@PublicRoute() export class VendorCreditsController { constructor( private readonly vendorCreditsApplication: VendorCreditsApplicationService, diff --git a/packages/server-nest/src/modules/VendorCreditsRefund/VendorCreditsRefund.controller.ts b/packages/server-nest/src/modules/VendorCreditsRefund/VendorCreditsRefund.controller.ts index 6d914e6b1..292c2db88 100644 --- a/packages/server-nest/src/modules/VendorCreditsRefund/VendorCreditsRefund.controller.ts +++ b/packages/server-nest/src/modules/VendorCreditsRefund/VendorCreditsRefund.controller.ts @@ -1,14 +1,11 @@ import { Body, Controller, Delete, Param, Post } from '@nestjs/common'; import { VendorCreditsRefundApplication } from './VendorCreditsRefund.application'; -import { IRefundVendorCreditDTO } from './types/VendorCreditRefund.types'; import { RefundVendorCredit } from './models/RefundVendorCredit'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { RefundVendorCreditDto } from './dtos/RefundVendorCredit.dto'; @Controller('vendor-credits') @ApiTags('vendor-credits-refunds') -@PublicRoute() export class VendorCreditsRefundController { constructor( private readonly vendorCreditsRefundApplication: VendorCreditsRefundApplication, diff --git a/packages/server-nest/src/modules/Vendors/Vendors.controller.ts b/packages/server-nest/src/modules/Vendors/Vendors.controller.ts index 464512e66..2c56d2fd3 100644 --- a/packages/server-nest/src/modules/Vendors/Vendors.controller.ts +++ b/packages/server-nest/src/modules/Vendors/Vendors.controller.ts @@ -13,14 +13,12 @@ import { IVendorOpeningBalanceEditDTO, IVendorsFilter, } from './types/Vendors.types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { CreateVendorDto } from './dtos/CreateVendor.dto'; import { EditVendorDto } from './dtos/EditVendor.dto'; @Controller('vendors') @ApiTags('vendors') -@PublicRoute() export class VendorsController { constructor(private vendorsApplication: VendorsApplication) {} diff --git a/packages/server-nest/src/modules/Warehouses/Warehouse.types.ts b/packages/server-nest/src/modules/Warehouses/Warehouse.types.ts index 95d96e877..02b2f4bf9 100644 --- a/packages/server-nest/src/modules/Warehouses/Warehouse.types.ts +++ b/packages/server-nest/src/modules/Warehouses/Warehouse.types.ts @@ -88,13 +88,11 @@ export interface IWarehouseDeletedPayload { trx: Knex.Transaction; } export interface IWarehouseCreatePayload { - // tenantId: number; warehouseDTO: ICreateWarehouseDTO; trx: Knex.Transaction; } export interface IWarehouseCreatedPayload { - // tenantId: number; warehouse: IWarehouse; warehouseDTO: ICreateWarehouseDTO; trx: Knex.Transaction; diff --git a/packages/server-nest/src/modules/Warehouses/Warehouses.controller.ts b/packages/server-nest/src/modules/Warehouses/Warehouses.controller.ts index e7ee892f7..65d88f02a 100644 --- a/packages/server-nest/src/modules/Warehouses/Warehouses.controller.ts +++ b/packages/server-nest/src/modules/Warehouses/Warehouses.controller.ts @@ -8,14 +8,11 @@ import { Put, } from '@nestjs/common'; import { WarehousesApplication } from './WarehousesApplication.service'; -import { ICreateWarehouseDTO, IEditWarehouseDTO } from './Warehouse.types'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { CreateWarehouseDto, EditWarehouseDto } from './dtos/Warehouse.dto'; @Controller('warehouses') @ApiTags('warehouses') -@PublicRoute() export class WarehousesController { constructor(private warehousesApplication: WarehousesApplication) {} diff --git a/packages/server-nest/src/modules/Warehouses/commands/CreateWarehouse.service.ts b/packages/server-nest/src/modules/Warehouses/commands/CreateWarehouse.service.ts index 17e2d31e9..eeb23d6d4 100644 --- a/packages/server-nest/src/modules/Warehouses/commands/CreateWarehouse.service.ts +++ b/packages/server-nest/src/modules/Warehouses/commands/CreateWarehouse.service.ts @@ -1,7 +1,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { Knex } from 'knex'; import { - ICreateWarehouseDTO, IWarehouseCreatedPayload, IWarehouseCreatePayload, } from '../Warehouse.types'; diff --git a/packages/server-nest/src/modules/WarehousesTransfers/WarehouseTransfers.controller.ts b/packages/server-nest/src/modules/WarehousesTransfers/WarehouseTransfers.controller.ts index 535b766e5..0237af4ae 100644 --- a/packages/server-nest/src/modules/WarehousesTransfers/WarehouseTransfers.controller.ts +++ b/packages/server-nest/src/modules/WarehousesTransfers/WarehouseTransfers.controller.ts @@ -11,7 +11,6 @@ import { } from '@nestjs/common'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { WarehouseTransferApplication } from './WarehouseTransferApplication'; -import { PublicRoute } from '../Auth/guards/Jwt.local'; import { CreateWarehouseTransferDto, EditWarehouseTransferDto, @@ -19,7 +18,6 @@ import { @Controller('warehouse-transfers') @ApiTags('warehouse-transfers') -@PublicRoute() export class WarehouseTransfersController { /** * @param {WarehouseTransferApplication} warehouseTransferApplication - Warehouse transfer application. diff --git a/packages/server-nest/test/auth.e2e-spec.ts b/packages/server-nest/test/auth.e2e-spec.ts new file mode 100644 index 000000000..fad080775 --- /dev/null +++ b/packages/server-nest/test/auth.e2e-spec.ts @@ -0,0 +1,58 @@ +import * as request from 'supertest'; +import { faker } from '@faker-js/faker'; +import { app } from './init-app-test'; + +describe('Authentication (e2e)', () => { + beforeAll(async () => {}); + + it('should signup success', () => { + return request(app.getHttpServer()) + .post('/auth/signup') + .send({ + firstName: faker.person.firstName(), + lastName: faker.person.lastName(), + email: faker.internet.email(), + password: '123123123', + }) + .expect(201); + }); + + it('should signin success', () => { + const signupBody = { + firstName: faker.person.firstName(), + lastName: faker.person.lastName(), + email: faker.internet.email(), + password: '123123123', + }; + const response = request(app.getHttpServer()) + .post('/auth/signup') + .send(signupBody); + + request(app.getHttpServer()) + .post('/auth/signin') + .send({ + email: signupBody.email, + password: signupBody.password, + }) + .expect(201); + }); + + it('should send reset password success', () => { + const signupBody = { + firstName: faker.person.firstName(), + lastName: faker.person.lastName(), + email: faker.internet.email(), + password: '123123123', + }; + const signupResponse = request(app.getHttpServer()) + .post('/auth/signup') + .send(signupBody); + + request(app.getHttpServer()) + .post('/auth/send_reset_password') + .send({ + email: signupBody.email, + }) + .expect(201); + }); +});