mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
refactor(nestjs): auth module
This commit is contained in:
@@ -11,13 +11,11 @@ import {
|
|||||||
import { AccountsApplication } from './AccountsApplication.service';
|
import { AccountsApplication } from './AccountsApplication.service';
|
||||||
import { CreateAccountDTO } from './CreateAccount.dto';
|
import { CreateAccountDTO } from './CreateAccount.dto';
|
||||||
import { EditAccountDTO } from './EditAccount.dto';
|
import { EditAccountDTO } from './EditAccount.dto';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types';
|
import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types';
|
||||||
import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('accounts')
|
@Controller('accounts')
|
||||||
@ApiTags('accounts')
|
@ApiTags('accounts')
|
||||||
@PublicRoute()
|
|
||||||
export class AccountsController {
|
export class AccountsController {
|
||||||
constructor(private readonly accountsApplication: AccountsApplication) {}
|
constructor(private readonly accountsApplication: AccountsApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common';
|
import { MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common';
|
||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
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 { join } from 'path';
|
||||||
import { RedisModule } from '@liaoliaots/nestjs-redis';
|
import { RedisModule } from '@liaoliaots/nestjs-redis';
|
||||||
import {
|
import {
|
||||||
@@ -12,24 +12,19 @@ import {
|
|||||||
QueryResolver,
|
QueryResolver,
|
||||||
} from 'nestjs-i18n';
|
} from 'nestjs-i18n';
|
||||||
import { BullModule } from '@nestjs/bullmq';
|
import { BullModule } from '@nestjs/bullmq';
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
|
||||||
import { PassportModule } from '@nestjs/passport';
|
import { PassportModule } from '@nestjs/passport';
|
||||||
import { ClsModule } from 'nestjs-cls';
|
import { ClsModule, ClsService } from 'nestjs-cls';
|
||||||
import { AppController } from './App.controller';
|
import { AppController } from './App.controller';
|
||||||
import { AppService } from './App.service';
|
import { AppService } from './App.service';
|
||||||
import { ItemsModule } from '../Items/items.module';
|
import { ItemsModule } from '../Items/items.module';
|
||||||
import { config } from '../../common/config';
|
import { config } from '../../common/config';
|
||||||
import { SystemDatabaseModule } from '../System/SystemDB/SystemDB.module';
|
import { SystemDatabaseModule } from '../System/SystemDB/SystemDB.module';
|
||||||
import { SystemModelsModule } from '../System/SystemModels/SystemModels.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 { TenancyDatabaseModule } from '../Tenancy/TenancyDB/TenancyDB.module';
|
||||||
import { TenancyModelsModule } from '../Tenancy/TenancyModels/Tenancy.module';
|
import { TenancyModelsModule } from '../Tenancy/TenancyModels/Tenancy.module';
|
||||||
import { LoggerMiddleware } from '@/middleware/logger.middleware';
|
import { LoggerMiddleware } from '@/middleware/logger.middleware';
|
||||||
import { ExcludeNullInterceptor } from '@/interceptors/ExcludeNull.interceptor';
|
import { ExcludeNullInterceptor } from '@/interceptors/ExcludeNull.interceptor';
|
||||||
import { JwtAuthGuard } from '../Auth/Jwt.guard';
|
|
||||||
import { UserIpInterceptor } from '@/interceptors/user-ip.interceptor';
|
import { UserIpInterceptor } from '@/interceptors/user-ip.interceptor';
|
||||||
import { TenancyGlobalMiddleware } from '../Tenancy/TenancyGlobal.middleware';
|
|
||||||
import { TransformerModule } from '../Transformer/Transformer.module';
|
import { TransformerModule } from '../Transformer/Transformer.module';
|
||||||
import { AccountsModule } from '../Accounts/Accounts.module';
|
import { AccountsModule } from '../Accounts/Accounts.module';
|
||||||
import { ExpensesModule } from '../Expenses/Expenses.module';
|
import { ExpensesModule } from '../Expenses/Expenses.module';
|
||||||
@@ -107,10 +102,6 @@ import { AuthModule } from '../Auth/Auth.module';
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
PassportModule,
|
PassportModule,
|
||||||
JwtModule.register({
|
|
||||||
secret: jwtConstants.secret,
|
|
||||||
signOptions: { expiresIn: '60s' },
|
|
||||||
}),
|
|
||||||
BullModule.forRootAsync({
|
BullModule.forRootAsync({
|
||||||
imports: [ConfigModule],
|
imports: [ConfigModule],
|
||||||
useFactory: async (configService: ConfigService) => ({
|
useFactory: async (configService: ConfigService) => ({
|
||||||
@@ -125,9 +116,8 @@ import { AuthModule } from '../Auth/Auth.module';
|
|||||||
global: true,
|
global: true,
|
||||||
middleware: {
|
middleware: {
|
||||||
mount: true,
|
mount: true,
|
||||||
setup: (cls, req: Request, res: Response) => {
|
setup: (cls: ClsService, req: Request, res: Response) => {
|
||||||
cls.set('organizationId', req.headers['organization-id']);
|
cls.set('organizationId', req.headers['organization-id']);
|
||||||
cls.set('userId', 1);
|
|
||||||
},
|
},
|
||||||
generateId: true,
|
generateId: true,
|
||||||
saveReq: true,
|
saveReq: true,
|
||||||
@@ -148,6 +138,7 @@ import { AuthModule } from '../Auth/Auth.module';
|
|||||||
ChromiumlyTenancyModule,
|
ChromiumlyTenancyModule,
|
||||||
TransformerModule,
|
TransformerModule,
|
||||||
MailModule,
|
MailModule,
|
||||||
|
AuthModule,
|
||||||
ItemsModule,
|
ItemsModule,
|
||||||
ItemCategoryModule,
|
ItemCategoryModule,
|
||||||
AccountsModule,
|
AccountsModule,
|
||||||
@@ -194,7 +185,6 @@ import { AuthModule } from '../Auth/Auth.module';
|
|||||||
OrganizationModule,
|
OrganizationModule,
|
||||||
TenantDBManagerModule,
|
TenantDBManagerModule,
|
||||||
PaymentServicesModule,
|
PaymentServicesModule,
|
||||||
AuthModule,
|
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [
|
providers: [
|
||||||
@@ -202,10 +192,6 @@ import { AuthModule } from '../Auth/Auth.module';
|
|||||||
provide: APP_INTERCEPTOR,
|
provide: APP_INTERCEPTOR,
|
||||||
useClass: SerializeInterceptor,
|
useClass: SerializeInterceptor,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
provide: APP_GUARD,
|
|
||||||
useClass: JwtAuthGuard,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
provide: APP_INTERCEPTOR,
|
provide: APP_INTERCEPTOR,
|
||||||
useClass: UserIpInterceptor,
|
useClass: UserIpInterceptor,
|
||||||
@@ -215,7 +201,6 @@ import { AuthModule } from '../Auth/Auth.module';
|
|||||||
useClass: ExcludeNullInterceptor,
|
useClass: ExcludeNullInterceptor,
|
||||||
},
|
},
|
||||||
AppService,
|
AppService,
|
||||||
JwtStrategy,
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {
|
export class AppModule {
|
||||||
@@ -223,9 +208,5 @@ export class AppModule {
|
|||||||
consumer
|
consumer
|
||||||
.apply(LoggerMiddleware)
|
.apply(LoggerMiddleware)
|
||||||
.forRoutes({ path: '*', method: RequestMethod.ALL });
|
.forRoutes({ path: '*', method: RequestMethod.ALL });
|
||||||
|
|
||||||
consumer
|
|
||||||
.apply(TenancyGlobalMiddleware)
|
|
||||||
.forRoutes({ path: '*', method: RequestMethod.ALL });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,10 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
|
||||||
import { JwtService } from '@nestjs/jwt';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppService {
|
export class AppService {
|
||||||
// configService: ConfigService;
|
constructor() {}
|
||||||
|
|
||||||
constructor(
|
|
||||||
private configService: ConfigService,
|
|
||||||
private jwtService: JwtService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
getHello(): string {
|
getHello(): string {
|
||||||
const payload = {};
|
return '';
|
||||||
|
|
||||||
const accessToken = this.jwtService.sign(payload);
|
|
||||||
|
|
||||||
return accessToken;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,3 +17,12 @@ export const ERRORS = {
|
|||||||
SIGNUP_CONFIRM_TOKEN_INVALID: 'SIGNUP_CONFIRM_TOKEN_INVALID',
|
SIGNUP_CONFIRM_TOKEN_INVALID: 'SIGNUP_CONFIRM_TOKEN_INVALID',
|
||||||
USER_ALREADY_VERIFIED: 'USER_ALREADY_VERIFIED',
|
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,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags, ApiOperation, ApiBody, ApiParam } from '@nestjs/swagger';
|
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 { AuthenticationApplication } from './AuthApplication.sevice';
|
||||||
import { AuthSignupDto } from './dtos/AuthSignup.dto';
|
import { AuthSignupDto } from './dtos/AuthSignup.dto';
|
||||||
import { AuthSigninDto } from './dtos/AuthSignin.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 { JwtService } from '@nestjs/jwt';
|
||||||
import { AuthSigninService } from './commands/AuthSignin.service';
|
import { AuthSigninService } from './commands/AuthSignin.service';
|
||||||
|
|
||||||
|
|||||||
@@ -16,24 +16,31 @@ import { AuthenticationMailMesssages } from './AuthMailMessages.esrvice';
|
|||||||
import { LocalStrategy } from './strategies/Local.strategy';
|
import { LocalStrategy } from './strategies/Local.strategy';
|
||||||
import { PassportModule } from '@nestjs/passport';
|
import { PassportModule } from '@nestjs/passport';
|
||||||
import { APP_GUARD } from '@nestjs/core';
|
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)];
|
const models = [RegisterTenancyModel(PasswordReset)];
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [AuthController],
|
controllers: [AuthController],
|
||||||
imports: [
|
imports: [
|
||||||
|
MailModule,
|
||||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||||
JwtModule.register({
|
JwtModule.register({
|
||||||
signOptions: {
|
signOptions: { expiresIn: '1d', algorithm: 'HS384' },
|
||||||
expiresIn: '1d',
|
verifyOptions: { algorithms: ['HS384'] },
|
||||||
algorithm: 'HS384',
|
|
||||||
},
|
|
||||||
verifyOptions: {
|
|
||||||
algorithms: ['HS384'],
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
TenantDBManagerModule,
|
TenantDBManagerModule,
|
||||||
|
BullModule.registerQueue({ name: SendResetPasswordMailQueue }),
|
||||||
|
BullModule.registerQueue({ name: SendSignupVerificationMailQueue }),
|
||||||
...models,
|
...models,
|
||||||
],
|
],
|
||||||
exports: [...models],
|
exports: [...models],
|
||||||
@@ -48,10 +55,13 @@ const models = [RegisterTenancyModel(PasswordReset)];
|
|||||||
AuthSignupService,
|
AuthSignupService,
|
||||||
AuthSigninService,
|
AuthSigninService,
|
||||||
AuthenticationMailMesssages,
|
AuthenticationMailMesssages,
|
||||||
|
SendResetPasswordMailProcessor,
|
||||||
|
SendSignupVerificationMailProcessor,
|
||||||
{
|
{
|
||||||
provide: APP_GUARD,
|
provide: APP_GUARD,
|
||||||
useClass: JwtAuthGuard,
|
useClass: JwtAuthGuard,
|
||||||
},
|
},
|
||||||
|
AuthMailSubscriber,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AuthModule {}
|
export class AuthModule {}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ClsService } from 'nestjs-cls';
|
||||||
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
|
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
|
||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
import { SystemUser } from '@/modules/System/models/SystemUser';
|
import { SystemUser } from '@/modules/System/models/SystemUser';
|
||||||
@@ -10,6 +11,7 @@ export class AuthSigninService {
|
|||||||
@Inject(SystemUser.name)
|
@Inject(SystemUser.name)
|
||||||
private readonly systemUserModel: typeof SystemUser,
|
private readonly systemUserModel: typeof SystemUser,
|
||||||
private readonly jwtService: JwtService,
|
private readonly jwtService: JwtService,
|
||||||
|
private readonly clsService: ClsService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,6 +44,11 @@ export class AuthSigninService {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies the given jwt payload.
|
||||||
|
* @param {JwtPayload} payload
|
||||||
|
* @returns {Promise<any>}
|
||||||
|
*/
|
||||||
async verifyPayload(payload: JwtPayload): Promise<any> {
|
async verifyPayload(payload: JwtPayload): Promise<any> {
|
||||||
let user: SystemUser;
|
let user: SystemUser;
|
||||||
|
|
||||||
@@ -50,6 +57,9 @@ export class AuthSigninService {
|
|||||||
.query()
|
.query()
|
||||||
.findOne({ email: payload.sub })
|
.findOne({ email: payload.sub })
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
this.clsService.set('tenantId', user.tenantId);
|
||||||
|
this.clsService.set('userId', user.id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new UnauthorizedException(
|
throw new UnauthorizedException(
|
||||||
`There isn't any user with email: ${payload.sub}`,
|
`There isn't any user with email: ${payload.sub}`,
|
||||||
@@ -58,6 +68,11 @@ export class AuthSigninService {
|
|||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {SystemUser} user
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
signToken(user: SystemUser): string {
|
signToken(user: SystemUser): string {
|
||||||
const payload = {
|
const payload = {
|
||||||
sub: user.email,
|
sub: user.email,
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
import {
|
import { ExecutionContext, Injectable, SetMetadata } from '@nestjs/common';
|
||||||
ExecutionContext,
|
|
||||||
Injectable,
|
|
||||||
Scope,
|
|
||||||
SetMetadata,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
import { AuthGuard } from '@nestjs/passport';
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
import { ClsService } from 'nestjs-cls';
|
import { ClsService } from 'nestjs-cls';
|
||||||
|
import { IS_PUBLIC_ROUTE } from '../Auth.constants';
|
||||||
|
|
||||||
export const IS_PUBLIC_KEY = 'isPublic';
|
export const PublicRoute = () => SetMetadata(IS_PUBLIC_ROUTE, true);
|
||||||
export const PublicRoute = () => SetMetadata(IS_PUBLIC_KEY, true);
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class JwtAuthGuard extends AuthGuard('jwt') {
|
export class JwtAuthGuard extends AuthGuard('jwt') {
|
||||||
@@ -21,10 +16,10 @@ export class JwtAuthGuard extends AuthGuard('jwt') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canActivate(context: ExecutionContext) {
|
canActivate(context: ExecutionContext) {
|
||||||
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
const isPublic = this.reflector.getAllAndOverride<boolean>(
|
||||||
context.getHandler(),
|
IS_PUBLIC_ROUTE,
|
||||||
context.getClass(),
|
[context.getHandler(), context.getClass()],
|
||||||
]);
|
);
|
||||||
if (isPublic) {
|
if (isPublic) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ import { SystemModel } from '@/modules/System/models/SystemModel';
|
|||||||
export class PasswordReset extends SystemModel {
|
export class PasswordReset extends SystemModel {
|
||||||
readonly email: string;
|
readonly email: string;
|
||||||
readonly token: string;
|
readonly token: string;
|
||||||
|
|
||||||
readonly createdAt: Date;
|
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,
|
Put,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { BankRulesApplication } from './BankRulesApplication';
|
import { BankRulesApplication } from './BankRulesApplication';
|
||||||
import { ICreateBankRuleDTO, IEditBankRuleDTO } from './types';
|
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { BankRule } from './models/BankRule';
|
import { BankRule } from './models/BankRule';
|
||||||
import { CreateBankRuleDto } from './dtos/BankRule.dto';
|
import { CreateBankRuleDto } from './dtos/BankRule.dto';
|
||||||
import { EditBankRuleDto } from './dtos/BankRule.dto';
|
import { EditBankRuleDto } from './dtos/BankRule.dto';
|
||||||
|
|
||||||
@Controller('banking/rules')
|
@Controller('banking/rules')
|
||||||
@ApiTags('bank-rules')
|
@ApiTags('bank-rules')
|
||||||
@PublicRoute()
|
|
||||||
export class BankRulesController {
|
export class BankRulesController {
|
||||||
constructor(private readonly bankRulesApplication: BankRulesApplication) {}
|
constructor(private readonly bankRulesApplication: BankRulesApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import { ModelObject } from 'objection';
|
import { ModelObject } from 'objection';
|
||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
import {
|
import {
|
||||||
IBankRuleEventCreatedPayload,
|
IBankRuleEventCreatedPayload,
|
||||||
IBankRuleEventCreatingPayload,
|
IBankRuleEventCreatingPayload,
|
||||||
ICreateBankRuleDTO,
|
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { UnitOfWork } from '../../Tenancy/TenancyDB/UnitOfWork.service';
|
import { UnitOfWork } from '../../Tenancy/TenancyDB/UnitOfWork.service';
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
||||||
import { events } from '@/common/events/events';
|
import { events } from '@/common/events/events';
|
||||||
import { BankRule } from '../models/BankRule';
|
import { BankRule } from '../models/BankRule';
|
||||||
import { CreateBankRuleDto } from '../dtos/BankRule.dto';
|
import { CreateBankRuleDto } from '../dtos/BankRule.dto';
|
||||||
|
|||||||
@@ -7,15 +7,13 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
Query,
|
Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { BankingTransactionsApplication } from './BankingTransactionsApplication.service';
|
import { BankingTransactionsApplication } from './BankingTransactionsApplication.service';
|
||||||
import { IBankAccountsFilter } from './types/BankingTransactions.types';
|
import { IBankAccountsFilter } from './types/BankingTransactions.types';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
|
||||||
import { CreateBankTransactionDto } from './dtos/CreateBankTransaction.dto';
|
import { CreateBankTransactionDto } from './dtos/CreateBankTransaction.dto';
|
||||||
|
|
||||||
@Controller('banking/transactions')
|
@Controller('banking/transactions')
|
||||||
@ApiTags('banking-transactions')
|
@ApiTags('banking-transactions')
|
||||||
@PublicRoute()
|
|
||||||
export class BankingTransactionsController {
|
export class BankingTransactionsController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly bankingTransactionsApplication: BankingTransactionsApplication,
|
private readonly bankingTransactionsApplication: BankingTransactionsApplication,
|
||||||
|
|||||||
@@ -11,12 +11,10 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { BillsApplication } from './Bills.application';
|
import { BillsApplication } from './Bills.application';
|
||||||
import { IBillsFilter } from './Bills.types';
|
import { IBillsFilter } from './Bills.types';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { CreateBillDto, EditBillDto } from './dtos/Bill.dto';
|
import { CreateBillDto, EditBillDto } from './dtos/Bill.dto';
|
||||||
|
|
||||||
@Controller('bills')
|
@Controller('bills')
|
||||||
@ApiTags('bills')
|
@ApiTags('bills')
|
||||||
@PublicRoute()
|
|
||||||
export class BillsController {
|
export class BillsController {
|
||||||
constructor(private billsApplication: BillsApplication) {}
|
constructor(private billsApplication: BillsApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { BranchesApplication } from './BranchesApplication.service';
|
import { BranchesApplication } from './BranchesApplication.service';
|
||||||
import { CreateBranchDto, EditBranchDto } from './dtos/Branch.dto';
|
import { CreateBranchDto, EditBranchDto } from './dtos/Branch.dto';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('branches')
|
@Controller('branches')
|
||||||
@ApiTags('branches')
|
@ApiTags('branches')
|
||||||
@PublicRoute()
|
|
||||||
export class BranchesController {
|
export class BranchesController {
|
||||||
constructor(private readonly branchesApplication: BranchesApplication) {}
|
constructor(private readonly branchesApplication: BranchesApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,11 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { CreditNoteApplication } from './CreditNoteApplication.service';
|
import { CreditNoteApplication } from './CreditNoteApplication.service';
|
||||||
import { ICreditNotesQueryDTO } from './types/CreditNotes.types';
|
import { ICreditNotesQueryDTO } from './types/CreditNotes.types';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { CreateCreditNoteDto, EditCreditNoteDto } from './dtos/CreditNote.dto';
|
import { CreateCreditNoteDto, EditCreditNoteDto } from './dtos/CreditNote.dto';
|
||||||
|
|
||||||
@Controller('credit-notes')
|
@Controller('credit-notes')
|
||||||
@ApiTags('credit-notes')
|
@ApiTags('credit-notes')
|
||||||
@PublicRoute()
|
|
||||||
export class CreditNotesController {
|
export class CreditNotesController {
|
||||||
/**
|
/**
|
||||||
* @param {CreditNoteApplication} creditNoteApplication - The credit note application service.
|
* @param {CreditNoteApplication} creditNoteApplication - The credit note application service.
|
||||||
|
|||||||
@@ -9,14 +9,12 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { CustomersApplication } from './CustomersApplication.service';
|
import { CustomersApplication } from './CustomersApplication.service';
|
||||||
import { ICustomerOpeningBalanceEditDTO } from './types/Customers.types';
|
import { ICustomerOpeningBalanceEditDTO } from './types/Customers.types';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import { CreateCustomerDto } from './dtos/CreateCustomer.dto';
|
import { CreateCustomerDto } from './dtos/CreateCustomer.dto';
|
||||||
import { EditCustomerDto } from './dtos/EditCustomer.dto';
|
import { EditCustomerDto } from './dtos/EditCustomer.dto';
|
||||||
|
|
||||||
@Controller('customers')
|
@Controller('customers')
|
||||||
@ApiTags('customers')
|
@ApiTags('customers')
|
||||||
@PublicRoute()
|
|
||||||
export class CustomersController {
|
export class CustomersController {
|
||||||
constructor(private customersApplication: CustomersApplication) {}
|
constructor(private customersApplication: CustomersApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,12 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ExpensesApplication } from './ExpensesApplication.service';
|
import { ExpensesApplication } from './ExpensesApplication.service';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { IExpensesFilter } from './Expenses.types';
|
import { IExpensesFilter } from './Expenses.types';
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import { CreateExpenseDto, EditExpenseDto } from './dtos/Expense.dto';
|
import { CreateExpenseDto, EditExpenseDto } from './dtos/Expense.dto';
|
||||||
|
|
||||||
@Controller('expenses')
|
@Controller('expenses')
|
||||||
@ApiTags('expenses')
|
@ApiTags('expenses')
|
||||||
@PublicRoute()
|
|
||||||
export class ExpensesController {
|
export class ExpensesController {
|
||||||
constructor(private readonly expensesApplication: ExpensesApplication) {}
|
constructor(private readonly expensesApplication: ExpensesApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import { IAPAgingSummaryQuery } from './APAgingSummary.types';
|
|||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@Controller('reports/payable-aging-summary')
|
@Controller('reports/payable-aging-summary')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class APAgingSummaryController {
|
export class APAgingSummaryController {
|
||||||
constructor(private readonly APAgingSummaryApp: APAgingSummaryApplication) {}
|
constructor(private readonly APAgingSummaryApp: APAgingSummaryApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ import { Query, Res } from '@nestjs/common';
|
|||||||
import { ARAgingSummaryApplication } from './ARAgingSummaryApplication';
|
import { ARAgingSummaryApplication } from './ARAgingSummaryApplication';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('reports/receivable-aging-summary')
|
@Controller('reports/receivable-aging-summary')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class ARAgingSummaryController {
|
export class ARAgingSummaryController {
|
||||||
constructor(private readonly ARAgingSummaryApp: ARAgingSummaryApplication) {}
|
constructor(private readonly ARAgingSummaryApp: ARAgingSummaryApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
|||||||
import { ICashFlowStatementQuery } from './Cashflow.types';
|
import { ICashFlowStatementQuery } from './Cashflow.types';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { CashflowSheetApplication } from './CashflowSheetApplication';
|
import { CashflowSheetApplication } from './CashflowSheetApplication';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('reports/cashflow-statement')
|
@Controller('reports/cashflow-statement')
|
||||||
@PublicRoute()
|
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
export class CashflowController {
|
export class CashflowController {
|
||||||
constructor(private readonly cashflowSheetApp: CashflowSheetApplication) {}
|
constructor(private readonly cashflowSheetApp: CashflowSheetApplication) {}
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
|||||||
import { ICustomerBalanceSummaryQuery } from './CustomerBalanceSummary.types';
|
import { ICustomerBalanceSummaryQuery } from './CustomerBalanceSummary.types';
|
||||||
import { CustomerBalanceSummaryApplication } from './CustomerBalanceSummaryApplication';
|
import { CustomerBalanceSummaryApplication } from './CustomerBalanceSummaryApplication';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@Controller('/reports/customer-balance-summary')
|
@Controller('/reports/customer-balance-summary')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class CustomerBalanceSummaryController {
|
export class CustomerBalanceSummaryController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly customerBalanceSummaryApp: CustomerBalanceSummaryApplication,
|
private readonly customerBalanceSummaryApp: CustomerBalanceSummaryApplication,
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
|||||||
import { IGeneralLedgerSheetQuery } from './GeneralLedger.types';
|
import { IGeneralLedgerSheetQuery } from './GeneralLedger.types';
|
||||||
import { GeneralLedgerApplication } from './GeneralLedgerApplication';
|
import { GeneralLedgerApplication } from './GeneralLedgerApplication';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@Controller('/reports/general-ledger')
|
@Controller('/reports/general-ledger')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class GeneralLedgerController {
|
export class GeneralLedgerController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly generalLedgerApplication: GeneralLedgerApplication,
|
private readonly generalLedgerApplication: GeneralLedgerApplication,
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ import { InventoryItemDetailsApplication } from './InventoryItemDetailsApplicati
|
|||||||
import { IInventoryDetailsQuery } from './InventoryItemDetails.types';
|
import { IInventoryDetailsQuery } from './InventoryItemDetails.types';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('reports/inventory-item-details')
|
@Controller('reports/inventory-item-details')
|
||||||
@PublicRoute()
|
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
export class InventoryItemDetailsController {
|
export class InventoryItemDetailsController {
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
|||||||
import { InventoryValuationSheetApplication } from './InventoryValuationSheetApplication';
|
import { InventoryValuationSheetApplication } from './InventoryValuationSheetApplication';
|
||||||
import { IInventoryValuationReportQuery } from './InventoryValuationSheet.types';
|
import { IInventoryValuationReportQuery } from './InventoryValuationSheet.types';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@Controller('reports/inventory-valuation')
|
@Controller('reports/inventory-valuation')
|
||||||
@PublicRoute()
|
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
export class InventoryValuationController {
|
export class InventoryValuationController {
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import { Response } from 'express';
|
|||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { JournalSheetApplication } from './JournalSheetApplication';
|
import { JournalSheetApplication } from './JournalSheetApplication';
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@Controller('/reports/journal')
|
@Controller('/reports/journal')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class JournalSheetController {
|
export class JournalSheetController {
|
||||||
constructor(private readonly journalSheetApp: JournalSheetApplication) {}
|
constructor(private readonly journalSheetApp: JournalSheetApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
|||||||
import { IProfitLossSheetQuery } from './ProfitLossSheet.types';
|
import { IProfitLossSheetQuery } from './ProfitLossSheet.types';
|
||||||
import { ProfitLossSheetApplication } from './ProfitLossSheetApplication';
|
import { ProfitLossSheetApplication } from './ProfitLossSheetApplication';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('/reports/profit-loss-sheet')
|
@Controller('/reports/profit-loss-sheet')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class ProfitLossSheetController {
|
export class ProfitLossSheetController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly profitLossSheetApp: ProfitLossSheetApplication,
|
private readonly profitLossSheetApp: ProfitLossSheetApplication,
|
||||||
|
|||||||
@@ -3,16 +3,9 @@ import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
|||||||
import { PurchasesByItemsApplication } from './PurchasesByItemsApplication';
|
import { PurchasesByItemsApplication } from './PurchasesByItemsApplication';
|
||||||
import { IPurchasesByItemsReportQuery } from './types/PurchasesByItems.types';
|
import { IPurchasesByItemsReportQuery } from './types/PurchasesByItems.types';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
|
||||||
ApiOperation,
|
|
||||||
ApiResponse,
|
|
||||||
ApiResponseProperty,
|
|
||||||
ApiTags,
|
|
||||||
} from '@nestjs/swagger';
|
|
||||||
|
|
||||||
@Controller('/reports/purchases-by-items')
|
@Controller('/reports/purchases-by-items')
|
||||||
@PublicRoute()
|
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
export class PurchasesByItemReportController {
|
export class PurchasesByItemReportController {
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ import { SalesTaxLiabilitySummaryQuery } from './SalesTaxLiability.types';
|
|||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { SalesTaxLiabilitySummaryApplication } from './SalesTaxLiabilitySummaryApplication';
|
import { SalesTaxLiabilitySummaryApplication } from './SalesTaxLiabilitySummaryApplication';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('/reports/sales-tax-liability-summary')
|
@Controller('/reports/sales-tax-liability-summary')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class SalesTaxLiabilitySummaryController {
|
export class SalesTaxLiabilitySummaryController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly salesTaxLiabilitySummaryApp: SalesTaxLiabilitySummaryApplication,
|
private readonly salesTaxLiabilitySummaryApp: SalesTaxLiabilitySummaryApplication,
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import { ITransactionsByCustomersFilter } from './TransactionsByCustomer.types';
|
|||||||
import { TransactionsByCustomerApplication } from './TransactionsByCustomersApplication';
|
import { TransactionsByCustomerApplication } from './TransactionsByCustomersApplication';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@Controller('/reports/transactions-by-customers')
|
@Controller('/reports/transactions-by-customers')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class TransactionsByCustomerController {
|
export class TransactionsByCustomerController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly transactionsByCustomersApp: TransactionsByCustomerApplication,
|
private readonly transactionsByCustomersApp: TransactionsByCustomerApplication,
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import { Controller, Get, Query } from '@nestjs/common';
|
import { Controller, Get, Query } from '@nestjs/common';
|
||||||
import { TransactionsByReferenceApplication } from './TransactionsByReferenceApplication';
|
import { TransactionsByReferenceApplication } from './TransactionsByReferenceApplication';
|
||||||
import { ITransactionsByReferenceQuery } from './TransactionsByReference.types';
|
import { ITransactionsByReferenceQuery } from './TransactionsByReference.types';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('reports/transactions-by-reference')
|
@Controller('reports/transactions-by-reference')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class TransactionsByReferenceController {
|
export class TransactionsByReferenceController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly transactionsByReferenceApp: TransactionsByReferenceApplication,
|
private readonly transactionsByReferenceApp: TransactionsByReferenceApplication,
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import { AcceptType } from '@/constants/accept-type';
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { TransactionsByVendorApplication } from './TransactionsByVendorApplication';
|
import { TransactionsByVendorApplication } from './TransactionsByVendorApplication';
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@Controller('/reports/transactions-by-vendors')
|
@Controller('/reports/transactions-by-vendors')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class TransactionsByVendorController {
|
export class TransactionsByVendorController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly transactionsByVendorsApp: TransactionsByVendorApplication,
|
private readonly transactionsByVendorsApp: TransactionsByVendorApplication,
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ import { Response } from 'express';
|
|||||||
import { ITrialBalanceSheetQuery } from './TrialBalanceSheet.types';
|
import { ITrialBalanceSheetQuery } from './TrialBalanceSheet.types';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { TrialBalanceSheetApplication } from './TrialBalanceSheetApplication';
|
import { TrialBalanceSheetApplication } from './TrialBalanceSheetApplication';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@Controller('reports/trial-balance-sheet')
|
@Controller('reports/trial-balance-sheet')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class TrialBalanceSheetController {
|
export class TrialBalanceSheetController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly trialBalanceSheetApp: TrialBalanceSheetApplication,
|
private readonly trialBalanceSheetApp: TrialBalanceSheetApplication,
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import { VendorBalanceSummaryApplication } from './VendorBalanceSummaryApplicati
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@Controller('/reports/vendor-balance-summary')
|
@Controller('/reports/vendor-balance-summary')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@PublicRoute()
|
|
||||||
export class VendorBalanceSummaryController {
|
export class VendorBalanceSummaryController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly vendorBalanceSummaryApp: VendorBalanceSummaryApplication,
|
private readonly vendorBalanceSummaryApp: VendorBalanceSummaryApplication,
|
||||||
|
|||||||
@@ -9,19 +9,14 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InventoryAdjustmentsApplicationService } from './InventoryAdjustmentsApplication.service';
|
import { InventoryAdjustmentsApplicationService } from './InventoryAdjustmentsApplication.service';
|
||||||
import {
|
import { IInventoryAdjustmentsFilter } from './types/InventoryAdjustments.types';
|
||||||
IInventoryAdjustmentsFilter,
|
|
||||||
IQuickInventoryAdjustmentDTO,
|
|
||||||
} from './types/InventoryAdjustments.types';
|
|
||||||
import { InventoryAdjustment } from './models/InventoryAdjustment';
|
import { InventoryAdjustment } from './models/InventoryAdjustment';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { IPaginationMeta } from '@/interfaces/Model';
|
import { IPaginationMeta } from '@/interfaces/Model';
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { CreateQuickInventoryAdjustmentDto } from './dtos/CreateQuickInventoryAdjustment.dto';
|
import { CreateQuickInventoryAdjustmentDto } from './dtos/CreateQuickInventoryAdjustment.dto';
|
||||||
|
|
||||||
@Controller('inventory-adjustments')
|
@Controller('inventory-adjustments')
|
||||||
@ApiTags('inventory-adjustments')
|
@ApiTags('inventory-adjustments')
|
||||||
@PublicRoute()
|
|
||||||
export class InventoryAdjustmentsController {
|
export class InventoryAdjustmentsController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly inventoryAdjustmentsApplicationService: InventoryAdjustmentsApplicationService,
|
private readonly inventoryAdjustmentsApplicationService: InventoryAdjustmentsApplicationService,
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import {
|
|||||||
GetItemCategoriesResponse,
|
GetItemCategoriesResponse,
|
||||||
IItemCategoriesFilter,
|
IItemCategoriesFilter,
|
||||||
} from './ItemCategory.interfaces';
|
} from './ItemCategory.interfaces';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
CreateItemCategoryDto,
|
CreateItemCategoryDto,
|
||||||
@@ -22,7 +21,6 @@ import {
|
|||||||
|
|
||||||
@Controller('item-categories')
|
@Controller('item-categories')
|
||||||
@ApiTags('item-categories')
|
@ApiTags('item-categories')
|
||||||
@PublicRoute()
|
|
||||||
export class ItemCategoryController {
|
export class ItemCategoryController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly itemCategoryApplication: ItemCategoryApplication,
|
private readonly itemCategoryApplication: ItemCategoryApplication,
|
||||||
|
|||||||
@@ -5,13 +5,16 @@ import { events } from '@/common/events/events';
|
|||||||
import { TransformerInjectable } from '../Transformer/TransformerInjectable.service';
|
import { TransformerInjectable } from '../Transformer/TransformerInjectable.service';
|
||||||
import { ItemTransformer } from './Item.transformer';
|
import { ItemTransformer } from './Item.transformer';
|
||||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||||
|
import { ClsService } from 'nestjs-cls';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GetItemService {
|
export class GetItemService {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(Item.name) private itemModel: TenantModelProxy<typeof Item>,
|
@Inject(Item.name)
|
||||||
private eventEmitter2: EventEmitter2,
|
private readonly itemModel: TenantModelProxy<typeof Item>,
|
||||||
private transformerInjectable: TransformerInjectable,
|
private readonly eventEmitter2: EventEmitter2,
|
||||||
|
private readonly transformerInjectable: TransformerInjectable,
|
||||||
|
private readonly clsService: ClsService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { TenantController } from '../Tenancy/Tenant.controller';
|
import { TenantController } from '../Tenancy/Tenant.controller';
|
||||||
import { SubscriptionGuard } from '../Subscription/interceptors/Subscription.guard';
|
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 { ItemsApplicationService } from './ItemsApplication.service';
|
||||||
import {
|
import {
|
||||||
ApiOperation,
|
ApiOperation,
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import {
|
|||||||
Put,
|
Put,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ManualJournalsApplication } from './ManualJournalsApplication.service';
|
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 { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
CreateManualJournalDto,
|
CreateManualJournalDto,
|
||||||
@@ -18,7 +16,6 @@ import {
|
|||||||
|
|
||||||
@Controller('manual-journals')
|
@Controller('manual-journals')
|
||||||
@ApiTags('manual-journals')
|
@ApiTags('manual-journals')
|
||||||
@PublicRoute()
|
|
||||||
export class ManualJournalsController {
|
export class ManualJournalsController {
|
||||||
constructor(private manualJournalsApplication: ManualJournalsApplication) {}
|
constructor(private manualJournalsApplication: ManualJournalsApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,9 @@ import {
|
|||||||
import { GetCurrentOrganizationService } from './queries/GetCurrentOrganization.service';
|
import { GetCurrentOrganizationService } from './queries/GetCurrentOrganization.service';
|
||||||
import { UpdateOrganizationService } from './commands/UpdateOrganization.service';
|
import { UpdateOrganizationService } from './commands/UpdateOrganization.service';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiBody } from '@nestjs/swagger';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@ApiTags('Organization')
|
@ApiTags('Organization')
|
||||||
@Controller('organization')
|
@Controller('organization')
|
||||||
@PublicRoute()
|
|
||||||
export class OrganizationController {
|
export class OrganizationController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly buildOrganizationService: BuildOrganizationService,
|
private readonly buildOrganizationService: BuildOrganizationService,
|
||||||
|
|||||||
@@ -17,12 +17,10 @@ import {
|
|||||||
IPaymentsReceivedFilter,
|
IPaymentsReceivedFilter,
|
||||||
PaymentReceiveMailOptsDTO,
|
PaymentReceiveMailOptsDTO,
|
||||||
} from './types/PaymentReceived.types';
|
} from './types/PaymentReceived.types';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('payments-received')
|
@Controller('payments-received')
|
||||||
@ApiTags('payments-received')
|
@ApiTags('payments-received')
|
||||||
@PublicRoute()
|
|
||||||
export class PaymentReceivesController {
|
export class PaymentReceivesController {
|
||||||
constructor(private paymentReceivesApplication: PaymentReceivesApplication) {}
|
constructor(private paymentReceivesApplication: PaymentReceivesApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -8,19 +8,15 @@ import {
|
|||||||
Req,
|
Req,
|
||||||
Res,
|
Res,
|
||||||
Next,
|
Next,
|
||||||
UsePipes,
|
|
||||||
ValidationPipe,
|
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { Request, Response, NextFunction } from 'express';
|
import { Request, Response, NextFunction } from 'express';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { PaymentServicesApplication } from './PaymentServicesApplication';
|
import { PaymentServicesApplication } from './PaymentServicesApplication';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { EditPaymentMethodDTO } from './types';
|
import { EditPaymentMethodDTO } from './types';
|
||||||
|
|
||||||
@ApiTags('PaymentServices')
|
@ApiTags('PaymentServices')
|
||||||
@Controller('payment-services')
|
@Controller('payment-services')
|
||||||
@PublicRoute()
|
|
||||||
export class PaymentServicesController {
|
export class PaymentServicesController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly paymentServicesApp: PaymentServicesApplication,
|
private readonly paymentServicesApp: PaymentServicesApplication,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
@@ -9,12 +10,9 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { PdfTemplateApplication } from './PdfTemplate.application';
|
import { PdfTemplateApplication } from './PdfTemplate.application';
|
||||||
import { ICreateInvoicePdfTemplateDTO, IEditPdfTemplateDTO } from './types';
|
import { ICreateInvoicePdfTemplateDTO, IEditPdfTemplateDTO } from './types';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
||||||
|
|
||||||
@Controller('pdf-templates')
|
@Controller('pdf-templates')
|
||||||
@ApiTags('pdf-templates')
|
@ApiTags('pdf-templates')
|
||||||
@PublicRoute()
|
|
||||||
export class PdfTemplatesController {
|
export class PdfTemplatesController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly pdfTemplateApplication: PdfTemplateApplication,
|
private readonly pdfTemplateApplication: PdfTemplateApplication,
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { Response, NextFunction } from 'express';
|
import { Response, NextFunction } from 'express';
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { CreateRoleDto, EditRoleDto } from './dtos/Role.dto';
|
import { CreateRoleDto, EditRoleDto } from './dtos/Role.dto';
|
||||||
import { RolesApplication } from './Roles.application';
|
import { RolesApplication } from './Roles.application';
|
||||||
import {
|
import {
|
||||||
@@ -22,11 +21,9 @@ import {
|
|||||||
ApiParam,
|
ApiParam,
|
||||||
ApiBody,
|
ApiBody,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
|
|
||||||
@ApiTags('Roles')
|
@ApiTags('Roles')
|
||||||
@Controller('roles')
|
@Controller('roles')
|
||||||
@PublicRoute()
|
|
||||||
export class RolesController {
|
export class RolesController {
|
||||||
constructor(private readonly rolesApp: RolesApplication) {}
|
constructor(private readonly rolesApp: RolesApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
SaleEstimateMailOptionsDTO,
|
SaleEstimateMailOptionsDTO,
|
||||||
} from './types/SaleEstimates.types';
|
} from './types/SaleEstimates.types';
|
||||||
import { SaleEstimate } from './models/SaleEstimate';
|
import { SaleEstimate } from './models/SaleEstimate';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import {
|
import {
|
||||||
CreateSaleEstimateDto,
|
CreateSaleEstimateDto,
|
||||||
EditSaleEstimateDto,
|
EditSaleEstimateDto,
|
||||||
@@ -25,7 +24,6 @@ import {
|
|||||||
|
|
||||||
@Controller('sale-estimates')
|
@Controller('sale-estimates')
|
||||||
@ApiTags('sale-estimates')
|
@ApiTags('sale-estimates')
|
||||||
@PublicRoute()
|
|
||||||
export class SaleEstimatesController {
|
export class SaleEstimatesController {
|
||||||
/**
|
/**
|
||||||
* @param {SaleEstimatesApplication} saleEstimatesApplication - Sale estimates application.
|
* @param {SaleEstimatesApplication} saleEstimatesApplication - Sale estimates application.
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
SendInvoiceMailDTO,
|
SendInvoiceMailDTO,
|
||||||
} from './SaleInvoice.types';
|
} from './SaleInvoice.types';
|
||||||
import { SaleInvoiceApplication } from './SaleInvoices.application';
|
import { SaleInvoiceApplication } from './SaleInvoices.application';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import {
|
import {
|
||||||
ApiHeader,
|
ApiHeader,
|
||||||
ApiOperation,
|
ApiOperation,
|
||||||
@@ -42,7 +41,6 @@ import {
|
|||||||
description: 'The authentication token',
|
description: 'The authentication token',
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
@PublicRoute()
|
|
||||||
export class SaleInvoicesController {
|
export class SaleInvoicesController {
|
||||||
constructor(private saleInvoiceApplication: SaleInvoiceApplication) {}
|
constructor(private saleInvoiceApplication: SaleInvoiceApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
Put,
|
Put,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { SaleReceiptApplication } from './SaleReceiptApplication.service';
|
import { SaleReceiptApplication } from './SaleReceiptApplication.service';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
CreateSaleReceiptDto,
|
CreateSaleReceiptDto,
|
||||||
@@ -19,7 +18,6 @@ import {
|
|||||||
|
|
||||||
@Controller('sale-receipts')
|
@Controller('sale-receipts')
|
||||||
@ApiTags('sale-receipts')
|
@ApiTags('sale-receipts')
|
||||||
@PublicRoute()
|
|
||||||
export class SaleReceiptsController {
|
export class SaleReceiptsController {
|
||||||
constructor(private saleReceiptApplication: SaleReceiptApplication) {}
|
constructor(private saleReceiptApplication: SaleReceiptApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import { Body, Controller, Get, Post, Put } from '@nestjs/common';
|
import { Body, Controller, Get, Post, Put } from '@nestjs/common';
|
||||||
import { SettingsApplicationService } from './SettingsApplication.service';
|
import { SettingsApplicationService } from './SettingsApplication.service';
|
||||||
import { ISettingsDTO } from './Settings.types';
|
import { ISettingsDTO } from './Settings.types';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('settings')
|
@Controller('settings')
|
||||||
@ApiTags('settings')
|
@ApiTags('settings')
|
||||||
@PublicRoute()
|
|
||||||
export class SettingsController {
|
export class SettingsController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly settingsApplicationService: SettingsApplicationService,
|
private readonly settingsApplicationService: SettingsApplicationService,
|
||||||
|
|||||||
@@ -17,13 +17,9 @@ export class SubscribeFreeOnSignupCommunity {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
@OnEvent(events.auth.signUp)
|
@OnEvent(events.auth.signUp)
|
||||||
async subscribeFreeOnSigupCommunity({
|
async subscribeFreeOnSigupCommunity({ signupDTO, tenant, user }) {
|
||||||
signupDTO,
|
|
||||||
tenant,
|
|
||||||
user,
|
|
||||||
}) {
|
|
||||||
if (this.configService.get('hostedOnBigcapitalCloud')) return null;
|
if (this.configService.get('hostedOnBigcapitalCloud')) return null;
|
||||||
|
|
||||||
await this.subscriptionApp.createNewSubscription('free');
|
// await this.subscriptionApp.createNewSubscription('free');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,11 @@ import {
|
|||||||
Put,
|
Put,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { TaxRatesApplication } from './TaxRate.application';
|
import { TaxRatesApplication } from './TaxRate.application';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import { CreateTaxRateDto, EditTaxRateDto } from './dtos/TaxRate.dto';
|
import { CreateTaxRateDto, EditTaxRateDto } from './dtos/TaxRate.dto';
|
||||||
|
|
||||||
@Controller('tax-rates')
|
@Controller('tax-rates')
|
||||||
@ApiTags('tax-rates')
|
@ApiTags('tax-rates')
|
||||||
@PublicRoute()
|
|
||||||
export class TaxRatesController {
|
export class TaxRatesController {
|
||||||
constructor(private readonly taxRatesApplication: TaxRatesApplication) {}
|
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 { Model } from 'objection';
|
||||||
import { ClsModule } from 'nestjs-cls';
|
import { ClsModule } from 'nestjs-cls';
|
||||||
import { TenantUser } from './models/TenantUser.model';
|
import { TenantUser } from './models/TenantUser.model';
|
||||||
|
import { APP_GUARD } from '@nestjs/core';
|
||||||
|
import { TenancyGlobalGuard } from '../TenancyGlobal.guard';
|
||||||
|
|
||||||
const models = [
|
const models = [
|
||||||
Item,
|
Item,
|
||||||
@@ -106,5 +108,11 @@ const modelProviders = models.map((model) => RegisterTenancyModel(model));
|
|||||||
@Module({
|
@Module({
|
||||||
imports: [...modelProviders],
|
imports: [...modelProviders],
|
||||||
exports: [...modelProviders],
|
exports: [...modelProviders],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: APP_GUARD,
|
||||||
|
useClass: TenancyGlobalGuard,
|
||||||
|
},
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class TenancyModelsModule {}
|
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 { Controller, Put, Get, Body, Param } from '@nestjs/common';
|
||||||
import { TransactionsLockingService } from './commands/CommandTransactionsLockingService';
|
import { TransactionsLockingService } from './commands/CommandTransactionsLockingService';
|
||||||
import { TransactionsLockingGroup } from './types/TransactionsLocking.types';
|
import { TransactionsLockingGroup } from './types/TransactionsLocking.types';
|
||||||
import { ITransactionLockingPartiallyDTO } from './types/TransactionsLocking.types';
|
import { ITransactionLockingPartiallyDTO } from './types/TransactionsLocking.types';
|
||||||
import { QueryTransactionsLocking } from './queries/QueryTransactionsLocking';
|
import { QueryTransactionsLocking } from './queries/QueryTransactionsLocking';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation } from '@nestjs/swagger';
|
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
|
||||||
import {
|
import {
|
||||||
CancelTransactionsLockingDto,
|
CancelTransactionsLockingDto,
|
||||||
TransactionsLockingDto,
|
TransactionsLockingDto,
|
||||||
@@ -13,7 +12,6 @@ import {
|
|||||||
|
|
||||||
@Controller('transactions-locking')
|
@Controller('transactions-locking')
|
||||||
@ApiTags('Transactions Locking')
|
@ApiTags('Transactions Locking')
|
||||||
@PublicRoute()
|
|
||||||
export class TransactionsLockingController {
|
export class TransactionsLockingController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly transactionsLockingService: TransactionsLockingService,
|
private readonly transactionsLockingService: TransactionsLockingService,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { VendorCreditsApplicationService } from './VendorCreditsApplication.service';
|
import { VendorCreditsApplicationService } from './VendorCreditsApplication.service';
|
||||||
import { IVendorCreditsQueryDTO } from './types/VendorCredit.types';
|
import { IVendorCreditsQueryDTO } from './types/VendorCredit.types';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
CreateVendorCreditDto,
|
CreateVendorCreditDto,
|
||||||
@@ -19,7 +18,6 @@ import {
|
|||||||
|
|
||||||
@Controller('vendor-credits')
|
@Controller('vendor-credits')
|
||||||
@ApiTags('vendor-credits')
|
@ApiTags('vendor-credits')
|
||||||
@PublicRoute()
|
|
||||||
export class VendorCreditsController {
|
export class VendorCreditsController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly vendorCreditsApplication: VendorCreditsApplicationService,
|
private readonly vendorCreditsApplication: VendorCreditsApplicationService,
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
import { Body, Controller, Delete, Param, Post } from '@nestjs/common';
|
import { Body, Controller, Delete, Param, Post } from '@nestjs/common';
|
||||||
import { VendorCreditsRefundApplication } from './VendorCreditsRefund.application';
|
import { VendorCreditsRefundApplication } from './VendorCreditsRefund.application';
|
||||||
import { IRefundVendorCreditDTO } from './types/VendorCreditRefund.types';
|
|
||||||
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import { RefundVendorCreditDto } from './dtos/RefundVendorCredit.dto';
|
import { RefundVendorCreditDto } from './dtos/RefundVendorCredit.dto';
|
||||||
|
|
||||||
@Controller('vendor-credits')
|
@Controller('vendor-credits')
|
||||||
@ApiTags('vendor-credits-refunds')
|
@ApiTags('vendor-credits-refunds')
|
||||||
@PublicRoute()
|
|
||||||
export class VendorCreditsRefundController {
|
export class VendorCreditsRefundController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly vendorCreditsRefundApplication: VendorCreditsRefundApplication,
|
private readonly vendorCreditsRefundApplication: VendorCreditsRefundApplication,
|
||||||
|
|||||||
@@ -13,14 +13,12 @@ import {
|
|||||||
IVendorOpeningBalanceEditDTO,
|
IVendorOpeningBalanceEditDTO,
|
||||||
IVendorsFilter,
|
IVendorsFilter,
|
||||||
} from './types/Vendors.types';
|
} from './types/Vendors.types';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import { CreateVendorDto } from './dtos/CreateVendor.dto';
|
import { CreateVendorDto } from './dtos/CreateVendor.dto';
|
||||||
import { EditVendorDto } from './dtos/EditVendor.dto';
|
import { EditVendorDto } from './dtos/EditVendor.dto';
|
||||||
|
|
||||||
@Controller('vendors')
|
@Controller('vendors')
|
||||||
@ApiTags('vendors')
|
@ApiTags('vendors')
|
||||||
@PublicRoute()
|
|
||||||
export class VendorsController {
|
export class VendorsController {
|
||||||
constructor(private vendorsApplication: VendorsApplication) {}
|
constructor(private vendorsApplication: VendorsApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -88,13 +88,11 @@ export interface IWarehouseDeletedPayload {
|
|||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
export interface IWarehouseCreatePayload {
|
export interface IWarehouseCreatePayload {
|
||||||
// tenantId: number;
|
|
||||||
warehouseDTO: ICreateWarehouseDTO;
|
warehouseDTO: ICreateWarehouseDTO;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWarehouseCreatedPayload {
|
export interface IWarehouseCreatedPayload {
|
||||||
// tenantId: number;
|
|
||||||
warehouse: IWarehouse;
|
warehouse: IWarehouse;
|
||||||
warehouseDTO: ICreateWarehouseDTO;
|
warehouseDTO: ICreateWarehouseDTO;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
|
|||||||
@@ -8,14 +8,11 @@ import {
|
|||||||
Put,
|
Put,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { WarehousesApplication } from './WarehousesApplication.service';
|
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 { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import { CreateWarehouseDto, EditWarehouseDto } from './dtos/Warehouse.dto';
|
import { CreateWarehouseDto, EditWarehouseDto } from './dtos/Warehouse.dto';
|
||||||
|
|
||||||
@Controller('warehouses')
|
@Controller('warehouses')
|
||||||
@ApiTags('warehouses')
|
@ApiTags('warehouses')
|
||||||
@PublicRoute()
|
|
||||||
export class WarehousesController {
|
export class WarehousesController {
|
||||||
constructor(private warehousesApplication: WarehousesApplication) {}
|
constructor(private warehousesApplication: WarehousesApplication) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import {
|
import {
|
||||||
ICreateWarehouseDTO,
|
|
||||||
IWarehouseCreatedPayload,
|
IWarehouseCreatedPayload,
|
||||||
IWarehouseCreatePayload,
|
IWarehouseCreatePayload,
|
||||||
} from '../Warehouse.types';
|
} from '../Warehouse.types';
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { WarehouseTransferApplication } from './WarehouseTransferApplication';
|
import { WarehouseTransferApplication } from './WarehouseTransferApplication';
|
||||||
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
|
||||||
import {
|
import {
|
||||||
CreateWarehouseTransferDto,
|
CreateWarehouseTransferDto,
|
||||||
EditWarehouseTransferDto,
|
EditWarehouseTransferDto,
|
||||||
@@ -19,7 +18,6 @@ import {
|
|||||||
|
|
||||||
@Controller('warehouse-transfers')
|
@Controller('warehouse-transfers')
|
||||||
@ApiTags('warehouse-transfers')
|
@ApiTags('warehouse-transfers')
|
||||||
@PublicRoute()
|
|
||||||
export class WarehouseTransfersController {
|
export class WarehouseTransfersController {
|
||||||
/**
|
/**
|
||||||
* @param {WarehouseTransferApplication} warehouseTransferApplication - Warehouse transfer application.
|
* @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