mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
refactor(nestjs): auth module
This commit is contained in:
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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<any>}
|
||||
*/
|
||||
async verifyPayload(payload: JwtPayload): Promise<any> {
|
||||
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,
|
||||
|
||||
@@ -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<boolean>(IS_PUBLIC_KEY, [
|
||||
context.getHandler(),
|
||||
context.getClass(),
|
||||
]);
|
||||
const isPublic = this.reflector.getAllAndOverride<boolean>(
|
||||
IS_PUBLIC_ROUTE,
|
||||
[context.getHandler(), context.getClass()],
|
||||
);
|
||||
if (isPublic) {
|
||||
return true;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<SendResetPasswordMailJobPayload>) {
|
||||
const mail = this.authMailMesssages.sendResetPasswordMessage(
|
||||
job.data.user,
|
||||
job.data.token,
|
||||
);
|
||||
await this.mailTransporter.send(mail);
|
||||
}
|
||||
}
|
||||
|
||||
export interface SendResetPasswordMailJobPayload {
|
||||
user: ModelObject<SystemUser>;
|
||||
token: string;
|
||||
}
|
||||
|
||||
@@ -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<SendSignupVerificationMailJobPayload>) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<typeof Item>,
|
||||
private eventEmitter2: EventEmitter2,
|
||||
private transformerInjectable: TransformerInjectable,
|
||||
@Inject(Item.name)
|
||||
private readonly itemModel: TenantModelProxy<typeof Item>,
|
||||
private readonly eventEmitter2: EventEmitter2,
|
||||
private readonly transformerInjectable: TransformerInjectable,
|
||||
private readonly clsService: ClsService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -17,13 +17,9 @@ export class SubscribeFreeOnSignupCommunity {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
@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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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<boolean>(
|
||||
IS_PUBLIC_ROUTE,
|
||||
[context.getHandler(), context.getClass()],
|
||||
);
|
||||
if (isPublic) {
|
||||
return true;
|
||||
}
|
||||
if (!organizationId) {
|
||||
throw new UnauthorizedException('Organization ID is required.');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Knex } from 'knex';
|
||||
import {
|
||||
ICreateWarehouseDTO,
|
||||
IWarehouseCreatedPayload,
|
||||
IWarehouseCreatePayload,
|
||||
} from '../Warehouse.types';
|
||||
|
||||
@@ -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.
|
||||
|
||||
58
packages/server-nest/test/auth.e2e-spec.ts
Normal file
58
packages/server-nest/test/auth.e2e-spec.ts
Normal file
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user