mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 23:30:32 +00:00
refactor(nestjs): auth module
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
# App
|
||||||
|
APP_JWT_SECRET=123123
|
||||||
|
|
||||||
# Mail
|
# Mail
|
||||||
MAIL_HOST=
|
MAIL_HOST=
|
||||||
MAIL_USERNAME=
|
MAIL_USERNAME=
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
# App
|
||||||
|
APP_JWT_SECRET=123123
|
||||||
|
|
||||||
# Mail
|
# Mail
|
||||||
MAIL_HOST=
|
MAIL_HOST=
|
||||||
MAIL_USERNAME=
|
MAIL_USERNAME=
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import posthog from './posthog';
|
|||||||
import stripePayment from './stripe-payment';
|
import stripePayment from './stripe-payment';
|
||||||
import signupConfirmation from './signup-confirmation';
|
import signupConfirmation from './signup-confirmation';
|
||||||
import signupRestrictions from './signup-restrictions';
|
import signupRestrictions from './signup-restrictions';
|
||||||
|
import jwt from './jwt';
|
||||||
|
|
||||||
export const config = [
|
export const config = [
|
||||||
systemDatabase,
|
systemDatabase,
|
||||||
@@ -24,4 +25,5 @@ export const config = [
|
|||||||
stripePayment,
|
stripePayment,
|
||||||
signupConfirmation,
|
signupConfirmation,
|
||||||
signupRestrictions,
|
signupRestrictions,
|
||||||
|
jwt,
|
||||||
];
|
];
|
||||||
|
|||||||
5
packages/server-nest/src/common/config/jwt.ts
Normal file
5
packages/server-nest/src/common/config/jwt.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { registerAs } from '@nestjs/config';
|
||||||
|
|
||||||
|
export default registerAs('jwt', () => ({
|
||||||
|
secret: process.env.APP_JWT_SECRET || '123123',
|
||||||
|
}));
|
||||||
@@ -11,7 +11,7 @@ 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/Jwt.guard';
|
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';
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,37 @@
|
|||||||
import { Body, Controller, Param, Post, Request } from '@nestjs/common';
|
// @ts-nocheck
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Param,
|
||||||
|
Post,
|
||||||
|
Request,
|
||||||
|
UseGuards,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { ApiTags, ApiOperation, ApiBody, ApiParam } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiBody, ApiParam } from '@nestjs/swagger';
|
||||||
import { PublicRoute } from './Jwt.guard';
|
import { JwtAuthGuard, PublicRoute } from './guards/Jwt.local';
|
||||||
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 { JwtService } from '@nestjs/jwt';
|
||||||
|
import { AuthSigninService } from './commands/AuthSignin.service';
|
||||||
|
|
||||||
@ApiTags('Auth')
|
@ApiTags('Auth')
|
||||||
@Controller('/auth')
|
@Controller('/auth')
|
||||||
@PublicRoute()
|
@PublicRoute()
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
constructor(private readonly authApp: AuthenticationApplication) {}
|
constructor(
|
||||||
|
private readonly authApp: AuthenticationApplication,
|
||||||
|
private readonly authSignin: AuthSigninService,
|
||||||
|
) {}
|
||||||
|
|
||||||
@Post('/signin')
|
@Post('/signin')
|
||||||
|
@UseGuards(LocalAuthGuard)
|
||||||
@ApiOperation({ summary: 'Sign in a user' })
|
@ApiOperation({ summary: 'Sign in a user' })
|
||||||
@ApiBody({ type: AuthSigninDto })
|
@ApiBody({ type: AuthSigninDto })
|
||||||
signin(@Request() req: Request, @Body() signinDto: AuthSigninDto) {
|
signin(@Request() req: Request, @Body() signinDto: AuthSigninDto) {
|
||||||
return this.authApp.signIn(signinDto);
|
const { user } = req;
|
||||||
|
return { access_token: this.authSignin.signToken(user) };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/signup')
|
@Post('/signup')
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ import { SystemUser } from '../System/models/SystemUser';
|
|||||||
import { TenantModel } from '../System/models/TenantModel';
|
import { TenantModel } from '../System/models/TenantModel';
|
||||||
import { AuthSignupDto } from './dtos/AuthSignup.dto';
|
import { AuthSignupDto } from './dtos/AuthSignup.dto';
|
||||||
|
|
||||||
|
export interface JwtPayload {
|
||||||
|
sub: string;
|
||||||
|
iat: number;
|
||||||
|
exp: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IAuthSignedInEventPayload {}
|
export interface IAuthSignedInEventPayload {}
|
||||||
export interface IAuthSigningInEventPayload {}
|
export interface IAuthSigningInEventPayload {}
|
||||||
export interface IAuthSignInPOJO {}
|
export interface IAuthSignInPOJO {}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AuthService } from './AuthService';
|
|
||||||
import { AuthController } from './Auth.controller';
|
import { AuthController } from './Auth.controller';
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
import { JwtStrategy } from './Jwt.strategy';
|
import { JwtStrategy } from './strategies/Jwt.strategy';
|
||||||
import { AuthenticationApplication } from './AuthApplication.sevice';
|
import { AuthenticationApplication } from './AuthApplication.sevice';
|
||||||
import { AuthSendResetPasswordService } from './commands/AuthSendResetPassword.service';
|
import { AuthSendResetPasswordService } from './commands/AuthSendResetPassword.service';
|
||||||
import { AuthResetPasswordService } from './commands/AuthResetPassword.service';
|
import { AuthResetPasswordService } from './commands/AuthResetPassword.service';
|
||||||
@@ -14,22 +13,32 @@ import { RegisterTenancyModel } from '../Tenancy/TenancyModels/Tenancy.module';
|
|||||||
import { PasswordReset } from './models/PasswordReset';
|
import { PasswordReset } from './models/PasswordReset';
|
||||||
import { TenantDBManagerModule } from '../TenantDBManager/TenantDBManager.module';
|
import { TenantDBManagerModule } from '../TenantDBManager/TenantDBManager.module';
|
||||||
import { AuthenticationMailMesssages } from './AuthMailMessages.esrvice';
|
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';
|
||||||
|
|
||||||
const models = [RegisterTenancyModel(PasswordReset)];
|
const models = [RegisterTenancyModel(PasswordReset)];
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [AuthController],
|
controllers: [AuthController],
|
||||||
imports: [
|
imports: [
|
||||||
|
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||||
JwtModule.register({
|
JwtModule.register({
|
||||||
secret: 'asdfasdfasdf',
|
signOptions: {
|
||||||
signOptions: { expiresIn: '60s' },
|
expiresIn: '1d',
|
||||||
|
algorithm: 'HS384',
|
||||||
|
},
|
||||||
|
verifyOptions: {
|
||||||
|
algorithms: ['HS384'],
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
TenantDBManagerModule,
|
TenantDBManagerModule,
|
||||||
...models,
|
...models,
|
||||||
],
|
],
|
||||||
exports: [...models],
|
exports: [...models],
|
||||||
providers: [
|
providers: [
|
||||||
AuthService,
|
LocalStrategy,
|
||||||
JwtStrategy,
|
JwtStrategy,
|
||||||
AuthenticationApplication,
|
AuthenticationApplication,
|
||||||
AuthSendResetPasswordService,
|
AuthSendResetPasswordService,
|
||||||
@@ -39,6 +48,10 @@ const models = [RegisterTenancyModel(PasswordReset)];
|
|||||||
AuthSignupService,
|
AuthSignupService,
|
||||||
AuthSigninService,
|
AuthSigninService,
|
||||||
AuthenticationMailMesssages,
|
AuthenticationMailMesssages,
|
||||||
|
{
|
||||||
|
provide: APP_GUARD,
|
||||||
|
useClass: JwtAuthGuard,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AuthModule {}
|
export class AuthModule {}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ export class AuthenticationApplication {
|
|||||||
* @param {string} email - Email address.
|
* @param {string} email - Email address.
|
||||||
* @param {string} password - Password.
|
* @param {string} password - Password.
|
||||||
*/
|
*/
|
||||||
public async signIn(signinDto: AuthSigninDto) {
|
public async signIn(email: string, password: string) {
|
||||||
return this.authSigninService.signIn(signinDto);
|
return this.authSigninService.signin(email, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
|
||||||
import { SystemUser } from '@/modules/System/models/SystemUser';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AuthService {
|
|
||||||
constructor(
|
|
||||||
@Inject(SystemUser.name)
|
|
||||||
private readonly systemUserModel: typeof SystemUser,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async validateUser(username: string, pass: string): Promise<any> {
|
|
||||||
const user = await this.systemUserModel
|
|
||||||
.query()
|
|
||||||
.findOne({ email: username });
|
|
||||||
|
|
||||||
if (user && user.password === pass) {
|
|
||||||
const { password, ...result } = user;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
||||||
import { PassportStrategy } from '@nestjs/passport';
|
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { jwtConstants } from './Auth.constants';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
||||||
constructor() {
|
|
||||||
super({
|
|
||||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
||||||
ignoreExpiration: false,
|
|
||||||
secretOrKey: jwtConstants.secret,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async validate(payload: any) {
|
|
||||||
return { userId: payload.sub, username: payload.username };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +1,67 @@
|
|||||||
import { SystemUser } from '@/modules/System/models/SystemUser';
|
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
|
||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
import { AuthSigninDto } from '../dtos/AuthSignin.dto';
|
import { SystemUser } from '@/modules/System/models/SystemUser';
|
||||||
|
import { ModelObject } from 'objection';
|
||||||
|
import { JwtPayload } from '../Auth.interfaces';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthSigninService {
|
export class AuthSigninService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly jwtService: JwtService,
|
|
||||||
|
|
||||||
@Inject(SystemUser.name)
|
@Inject(SystemUser.name)
|
||||||
private readonly systemUserModel: typeof SystemUser,
|
private readonly systemUserModel: typeof SystemUser,
|
||||||
|
private readonly jwtService: JwtService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private async validate() {}
|
/**
|
||||||
|
* Validates the given email and password.
|
||||||
|
* @param {string} email - Signin email address.
|
||||||
|
* @param {string} password - Signin password.
|
||||||
|
* @returns {Promise<ModelObject<SystemUser>>}
|
||||||
|
*/
|
||||||
|
async signin(
|
||||||
|
email: string,
|
||||||
|
password: string,
|
||||||
|
): Promise<ModelObject<SystemUser>> {
|
||||||
|
let user: SystemUser;
|
||||||
|
|
||||||
private getUserByEmail(email: string) {
|
try {
|
||||||
return this.systemUserModel.query().findOne({ email });
|
user = await this.systemUserModel
|
||||||
|
.query()
|
||||||
|
.findOne({ email })
|
||||||
|
.throwIfNotFound();
|
||||||
|
} catch (err) {
|
||||||
|
throw new UnauthorizedException(
|
||||||
|
`There isn't any user with email: ${email}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!(await user.checkPassword(password))) {
|
||||||
|
throw new UnauthorizedException(
|
||||||
|
`Wrong password for user with email: ${email}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async signIn(signinDto: AuthSigninDto) {}
|
async verifyPayload(payload: JwtPayload): Promise<any> {
|
||||||
|
let user: SystemUser;
|
||||||
|
|
||||||
|
try {
|
||||||
|
user = await this.systemUserModel
|
||||||
|
.query()
|
||||||
|
.findOne({ email: payload.sub })
|
||||||
|
.throwIfNotFound();
|
||||||
|
} catch (error) {
|
||||||
|
throw new UnauthorizedException(
|
||||||
|
`There isn't any user with email: ${payload.sub}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
signToken(user: SystemUser): string {
|
||||||
|
const payload = {
|
||||||
|
sub: user.email,
|
||||||
|
};
|
||||||
|
return this.jwtService.sign(payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export class JwtAuthGuard extends AuthGuard('jwt') {
|
|||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
canActivate(context: ExecutionContext) {
|
canActivate(context: ExecutionContext) {
|
||||||
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
||||||
context.getHandler(),
|
context.getHandler(),
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { Injectable, ExecutionContext } from '@nestjs/common';
|
||||||
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class LocalAuthGuard extends AuthGuard('local') {}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { PassportStrategy } from '@nestjs/passport';
|
||||||
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||||
|
import { AuthSigninService } from '../commands/AuthSignin.service';
|
||||||
|
import { JwtPayload } from '../Auth.interfaces';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
||||||
|
constructor(
|
||||||
|
private readonly authSigninService: AuthSigninService,
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
) {
|
||||||
|
super({
|
||||||
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||||
|
ignoreExpiration: false,
|
||||||
|
secretOrKey: configService.get('jwt.secret'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
validate(payload: JwtPayload) {
|
||||||
|
return this.authSigninService.verifyPayload(payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { PassportStrategy } from '@nestjs/passport';
|
||||||
|
import { Strategy } from 'passport-local';
|
||||||
|
import { AuthSigninService } from '../commands/AuthSignin.service';
|
||||||
|
import { ModelObject } from 'objection';
|
||||||
|
import { SystemUser } from '../../System/models/SystemUser';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class LocalStrategy extends PassportStrategy(Strategy, 'local') {
|
||||||
|
constructor(private readonly authSigninService: AuthSigninService) {
|
||||||
|
super({
|
||||||
|
usernameField: 'email',
|
||||||
|
passReqToCallback: false,
|
||||||
|
session: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
validate(email: string, password: string): Promise<ModelObject<SystemUser>> {
|
||||||
|
return this.authSigninService.signin(email, password);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { BankRulesApplication } from './BankRulesApplication';
|
import { BankRulesApplication } from './BankRulesApplication';
|
||||||
import { ICreateBankRuleDTO, IEditBankRuleDTO } from './types';
|
import { ICreateBankRuleDTO, IEditBankRuleDTO } from './types';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
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';
|
||||||
|
|||||||
@@ -8,11 +8,8 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { BankingTransactionsApplication } from './BankingTransactionsApplication.service';
|
import { BankingTransactionsApplication } from './BankingTransactionsApplication.service';
|
||||||
import {
|
import { IBankAccountsFilter } from './types/BankingTransactions.types';
|
||||||
IBankAccountsFilter,
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
ICashflowNewCommandDTO,
|
|
||||||
} from './types/BankingTransactions.types';
|
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { CreateBankTransactionDto } from './dtos/CreateBankTransaction.dto';
|
import { CreateBankTransactionDto } from './dtos/CreateBankTransaction.dto';
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ 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/Jwt.guard';
|
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')
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
|
ArrayMinSize,
|
||||||
IsArray,
|
IsArray,
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
IsDate,
|
IsDate,
|
||||||
@@ -81,7 +82,7 @@ export class CommandBillDto {
|
|||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => BillEntryDto)
|
@Type(() => BillEntryDto)
|
||||||
@MinLength(1)
|
@ArrayMinSize(1)
|
||||||
entries: BillEntryDto[];
|
entries: BillEntryDto[];
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ 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/Jwt.guard';
|
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')
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ 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/Jwt.guard';
|
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';
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ 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/Jwt.guard';
|
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';
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ExpensesApplication } from './ExpensesApplication.service';
|
import { ExpensesApplication } from './ExpensesApplication.service';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
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';
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@Controller('reports/payable-aging-summary')
|
@Controller('reports/payable-aging-summary')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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/Jwt.guard';
|
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')
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ 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/Jwt.guard';
|
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')
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@Controller('/reports/customer-balance-summary')
|
@Controller('/reports/customer-balance-summary')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@Controller('/reports/general-ledger')
|
@Controller('/reports/general-ledger')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ 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/Jwt.guard';
|
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')
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@Controller('reports/inventory-valuation')
|
@Controller('reports/inventory-valuation')
|
||||||
@PublicRoute()
|
@PublicRoute()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@Controller('/reports/journal')
|
@Controller('/reports/journal')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ 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/Jwt.guard';
|
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')
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
||||||
import {
|
import {
|
||||||
ApiOperation,
|
ApiOperation,
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ 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/Jwt.guard';
|
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')
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@Controller('/reports/transactions-by-customers')
|
@Controller('/reports/transactions-by-customers')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
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/Jwt.guard';
|
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')
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@Controller('/reports/transactions-by-vendors')
|
@Controller('/reports/transactions-by-vendors')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
import {
|
import { Controller, Get, Headers, Query, Res } from '@nestjs/common';
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Headers,
|
|
||||||
Query,
|
|
||||||
Res,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
import { Response } from 'express';
|
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/Jwt.guard';
|
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@Controller('reports/trial-balance-sheet')
|
@Controller('reports/trial-balance-sheet')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
@@ -35,9 +29,8 @@ export class TrialBalanceSheetController {
|
|||||||
};
|
};
|
||||||
// Retrieves in json table format.
|
// Retrieves in json table format.
|
||||||
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
|
if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) {
|
||||||
const { table, meta, query } = await this.trialBalanceSheetApp.table(
|
const { table, meta, query } =
|
||||||
filter,
|
await this.trialBalanceSheetApp.table(filter);
|
||||||
);
|
|
||||||
return res.status(200).send({ table, meta, query });
|
return res.status(200).send({ table, meta, query });
|
||||||
// Retrieves in xlsx format
|
// Retrieves in xlsx format
|
||||||
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
|
} else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) {
|
||||||
@@ -66,9 +59,8 @@ export class TrialBalanceSheetController {
|
|||||||
res.send(pdfContent);
|
res.send(pdfContent);
|
||||||
// Retrieves in json format.
|
// Retrieves in json format.
|
||||||
} else {
|
} else {
|
||||||
const { data, query, meta } = await this.trialBalanceSheetApp.sheet(
|
const { data, query, meta } =
|
||||||
filter,
|
await this.trialBalanceSheetApp.sheet(filter);
|
||||||
);
|
|
||||||
return res.status(200).send({ data, query, meta });
|
return res.status(200).send({ data, query, meta });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '@/modules/Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@Controller('/reports/vendor-balance-summary')
|
@Controller('/reports/vendor-balance-summary')
|
||||||
@ApiTags('reports')
|
@ApiTags('reports')
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
IQuickInventoryAdjustmentDTO,
|
IQuickInventoryAdjustmentDTO,
|
||||||
} from './types/InventoryAdjustments.types';
|
} from './types/InventoryAdjustments.types';
|
||||||
import { InventoryAdjustment } from './models/InventoryAdjustment';
|
import { InventoryAdjustment } from './models/InventoryAdjustment';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
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';
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
GetItemCategoriesResponse,
|
GetItemCategoriesResponse,
|
||||||
IItemCategoriesFilter,
|
IItemCategoriesFilter,
|
||||||
} from './ItemCategory.interfaces';
|
} from './ItemCategory.interfaces';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
CreateItemCategoryDto,
|
CreateItemCategoryDto,
|
||||||
|
|||||||
@@ -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 { PublicRoute } from '../Auth/Jwt.guard';
|
import { JwtAuthGuard, PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import { ItemsApplicationService } from './ItemsApplication.service';
|
import { ItemsApplicationService } from './ItemsApplication.service';
|
||||||
import {
|
import {
|
||||||
ApiOperation,
|
ApiOperation,
|
||||||
@@ -22,13 +22,11 @@ import {
|
|||||||
ApiTags,
|
ApiTags,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { IItemsFilter } from './types/Items.types';
|
import { IItemsFilter } from './types/Items.types';
|
||||||
import { IItemDTO } from '@/interfaces/Item';
|
|
||||||
import { CreateItemDto, EditItemDto } from './dtos/Item.dto';
|
import { CreateItemDto, EditItemDto } from './dtos/Item.dto';
|
||||||
|
|
||||||
@Controller('/items')
|
@Controller('/items')
|
||||||
@UseGuards(SubscriptionGuard)
|
@UseGuards(SubscriptionGuard)
|
||||||
@ApiTags('items')
|
@ApiTags('items')
|
||||||
@PublicRoute()
|
|
||||||
export class ItemsController extends TenantController {
|
export class ItemsController extends TenantController {
|
||||||
constructor(private readonly itemsApplication: ItemsApplicationService) {
|
constructor(private readonly itemsApplication: ItemsApplicationService) {
|
||||||
super();
|
super();
|
||||||
@@ -112,6 +110,7 @@ export class ItemsController extends TenantController {
|
|||||||
* @returns The updated item id.
|
* @returns The updated item id.
|
||||||
*/
|
*/
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
|
@UseGuards(JwtAuthGuard)
|
||||||
@ApiOperation({ summary: 'Edit the given item (product or service).' })
|
@ApiOperation({ summary: 'Edit the given item (product or service).' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -9,9 +9,12 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ManualJournalsApplication } from './ManualJournalsApplication.service';
|
import { ManualJournalsApplication } from './ManualJournalsApplication.service';
|
||||||
import { IManualJournalDTO } from './types/ManualJournals.types';
|
import { IManualJournalDTO } from './types/ManualJournals.types';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { CreateManualJournalDto, EditManualJournalDto } from './dtos/ManualJournal.dto';
|
import {
|
||||||
|
CreateManualJournalDto,
|
||||||
|
EditManualJournalDto,
|
||||||
|
} from './dtos/ManualJournal.dto';
|
||||||
|
|
||||||
@Controller('manual-journals')
|
@Controller('manual-journals')
|
||||||
@ApiTags('manual-journals')
|
@ApiTags('manual-journals')
|
||||||
@@ -40,7 +43,7 @@ export class ManualJournalsController {
|
|||||||
})
|
})
|
||||||
public editManualJournal(
|
public editManualJournal(
|
||||||
@Param('id') manualJournalId: number,
|
@Param('id') manualJournalId: number,
|
||||||
@Body() manualJournalDTO: EditManualJournalDto
|
@Body() manualJournalDTO: EditManualJournalDto,
|
||||||
) {
|
) {
|
||||||
return this.manualJournalsApplication.editManualJournal(
|
return this.manualJournalsApplication.editManualJournal(
|
||||||
manualJournalId,
|
manualJournalId,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@ApiTags('Organization')
|
@ApiTags('Organization')
|
||||||
@Controller('organization')
|
@Controller('organization')
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
IPaymentsReceivedFilter,
|
IPaymentsReceivedFilter,
|
||||||
PaymentReceiveMailOptsDTO,
|
PaymentReceiveMailOptsDTO,
|
||||||
} from './types/PaymentReceived.types';
|
} from './types/PaymentReceived.types';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
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')
|
||||||
@@ -108,7 +108,8 @@ export class PaymentReceivesController {
|
|||||||
@ApiOperation({ summary: 'Retrieves the payment received invoices.' })
|
@ApiOperation({ summary: 'Retrieves the payment received invoices.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
description: 'The payment received invoices have been successfully retrieved.',
|
description:
|
||||||
|
'The payment received invoices have been successfully retrieved.',
|
||||||
})
|
})
|
||||||
public getPaymentReceiveInvoices(
|
public getPaymentReceiveInvoices(
|
||||||
@Param('id', ParseIntPipe) paymentReceiveId: number,
|
@Param('id', ParseIntPipe) paymentReceiveId: number,
|
||||||
@@ -122,7 +123,8 @@ export class PaymentReceivesController {
|
|||||||
@ApiOperation({ summary: 'Retrieves the payment received details.' })
|
@ApiOperation({ summary: 'Retrieves the payment received details.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
description: 'The payment received details have been successfully retrieved.',
|
description:
|
||||||
|
'The payment received details have been successfully retrieved.',
|
||||||
})
|
})
|
||||||
public getPaymentReceive(
|
public getPaymentReceive(
|
||||||
@Param('id', ParseIntPipe) paymentReceiveId: number,
|
@Param('id', ParseIntPipe) paymentReceiveId: number,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
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/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import { EditPaymentMethodDTO } from './types';
|
import { EditPaymentMethodDTO } from './types';
|
||||||
|
|
||||||
@ApiTags('PaymentServices')
|
@ApiTags('PaymentServices')
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('pdf-templates')
|
@Controller('pdf-templates')
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
ApiParam,
|
ApiParam,
|
||||||
ApiBody,
|
ApiBody,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
|
|
||||||
@ApiTags('Roles')
|
@ApiTags('Roles')
|
||||||
@Controller('roles')
|
@Controller('roles')
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import {
|
import {
|
||||||
CreateSaleEstimateDto,
|
CreateSaleEstimateDto,
|
||||||
EditSaleEstimateDto,
|
EditSaleEstimateDto,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
SendInvoiceMailDTO,
|
SendInvoiceMailDTO,
|
||||||
} from './SaleInvoice.types';
|
} from './SaleInvoice.types';
|
||||||
import { SaleInvoiceApplication } from './SaleInvoices.application';
|
import { SaleInvoiceApplication } from './SaleInvoices.application';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import {
|
import {
|
||||||
ApiHeader,
|
ApiHeader,
|
||||||
ApiOperation,
|
ApiOperation,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
Put,
|
Put,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { SaleReceiptApplication } from './SaleReceiptApplication.service';
|
import { SaleReceiptApplication } from './SaleReceiptApplication.service';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
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,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
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/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('settings')
|
@Controller('settings')
|
||||||
|
|||||||
@@ -26,21 +26,21 @@ export class SubscriptionGuard implements CanActivate {
|
|||||||
context: ExecutionContext,
|
context: ExecutionContext,
|
||||||
subscriptionSlug: string = 'main', // Default value
|
subscriptionSlug: string = 'main', // Default value
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const tenant = await this.tenancyContext.getTenant();
|
// const tenant = await this.tenancyContext.getTenant();
|
||||||
const subscription = await this.planSubscriptionModel
|
// const subscription = await this.planSubscriptionModel
|
||||||
.query()
|
// .query()
|
||||||
.findOne('slug', subscriptionSlug)
|
// .findOne('slug', subscriptionSlug)
|
||||||
.where('tenant_id', tenant.id);
|
// .where('tenant_id', tenant.id);
|
||||||
|
|
||||||
if (!subscription) {
|
// if (!subscription) {
|
||||||
throw new UnauthorizedException('Tenant has no subscription.');
|
// throw new UnauthorizedException('Tenant has no subscription.');
|
||||||
}
|
// }
|
||||||
|
|
||||||
const isSubscriptionInactive = subscription.inactive();
|
// const isSubscriptionInactive = subscription.inactive();
|
||||||
|
|
||||||
if (isSubscriptionInactive) {
|
// if (isSubscriptionInactive) {
|
||||||
throw new UnauthorizedException('Organization subscription is inactive.');
|
// throw new UnauthorizedException('Organization subscription is inactive.');
|
||||||
}
|
// }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
import * as bcrypt from 'bcrypt';
|
||||||
import { BaseModel } from '@/models/Model';
|
import { BaseModel } from '@/models/Model';
|
||||||
|
|
||||||
export class SystemUser extends BaseModel {
|
export class SystemUser extends BaseModel {
|
||||||
public readonly firstName: string;
|
public readonly firstName: string;
|
||||||
public readonly lastName: string;
|
public readonly lastName: string;
|
||||||
public readonly email: string;
|
public readonly email: string;
|
||||||
public readonly password: string;
|
public password: string;
|
||||||
|
|
||||||
public readonly active: boolean;
|
public readonly active: boolean;
|
||||||
public readonly tenantId: number;
|
public readonly tenantId: number;
|
||||||
@@ -15,4 +16,15 @@ export class SystemUser extends BaseModel {
|
|||||||
static get tableName() {
|
static get tableName() {
|
||||||
return 'users';
|
return 'users';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async hashPassword(): Promise<void> {
|
||||||
|
const salt = await bcrypt.genSalt();
|
||||||
|
if (!/^\$2[abxy]?\$\d+\$/.test(this.password)) {
|
||||||
|
this.password = await bcrypt.hash(this.password, salt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkPassword(plainPassword: string): Promise<boolean> {
|
||||||
|
return await bcrypt.compare(plainPassword, this.password);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
Put,
|
Put,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { TaxRatesApplication } from './TaxRate.application';
|
import { TaxRatesApplication } from './TaxRate.application';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
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';
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { TransactionsLockingService } from './commands/CommandTransactionsLockin
|
|||||||
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/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import { ApiOperation } from '@nestjs/swagger';
|
import { ApiOperation } from '@nestjs/swagger';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
CreateVendorCreditDto,
|
CreateVendorCreditDto,
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
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 { IRefundVendorCreditDTO } from './types/VendorCreditRefund.types';
|
||||||
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
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';
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
IVendorOpeningBalanceEditDTO,
|
IVendorOpeningBalanceEditDTO,
|
||||||
IVendorsFilter,
|
IVendorsFilter,
|
||||||
} from './types/Vendors.types';
|
} from './types/Vendors.types';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
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';
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { WarehousesApplication } from './WarehousesApplication.service';
|
import { WarehousesApplication } from './WarehousesApplication.service';
|
||||||
import { ICreateWarehouseDTO, IEditWarehouseDTO } from './Warehouse.types';
|
import { ICreateWarehouseDTO, IEditWarehouseDTO } from './Warehouse.types';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
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';
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ 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/Jwt.guard';
|
import { PublicRoute } from '../Auth/guards/Jwt.local';
|
||||||
import {
|
import {
|
||||||
CreateWarehouseTransferDto,
|
CreateWarehouseTransferDto,
|
||||||
EditWarehouseTransferDto,
|
EditWarehouseTransferDto,
|
||||||
|
|||||||
Reference in New Issue
Block a user