refactor(nestjs): transaction locking

This commit is contained in:
Ahmed Bouhuolia
2025-04-07 13:35:02 +02:00
parent 443fbdd89e
commit 4febc4e502
9 changed files with 14 additions and 18 deletions

View File

@@ -1,9 +1,14 @@
import { Type } from 'class-transformer';
import { IsString } from 'class-validator';
import { IsNotEmpty } from 'class-validator';
import { IsDate } from 'class-validator';
export class TransactionsLockingDto {
@IsString()
module: string;
@IsDate()
@Type(() => Date)
@IsNotEmpty()
lockToDate: Date;

View File

@@ -1,7 +1,7 @@
import { TransactionsLockingGroup } from '../types/TransactionsLocking.types';
import { Injectable } from '@nestjs/common';
import { TransactionsLockingGuard } from './TransactionsLockingGuard';
import { MomentInput } from 'moment';
import { TransactionsLockingGroup } from '../types/TransactionsLocking.types';
import { TransactionsLockingGuard } from './TransactionsLockingGuard';
@Injectable()
export class PurchasesTransactionLockingGuard {

View File

@@ -1,7 +1,7 @@
import { TransactionsLockingGroup } from '../types/TransactionsLocking.types';
import { Injectable } from '@nestjs/common';
import { TransactionsLockingGuard } from './TransactionsLockingGuard';
import { MomentInput } from 'moment';
import { TransactionsLockingGroup } from '../types/TransactionsLocking.types';
import { TransactionsLockingGuard } from './TransactionsLockingGuard';
@Injectable()
export class SalesTransactionLockingGuard {

View File

@@ -70,7 +70,8 @@ export class TransactionsLockingGuard {
) => {
const { lockToDate } =
await this.transactionsLockingRepo.getTransactionsLocking(lockingGroup);
throw new ServiceError(ERRORS.TRANSACTIONS_DATE_LOCKED, null, {
throw new ServiceError(ERRORS.TRANSACTIONS_DATE_LOCKED, 'Transactions locked', {
lockedToDate: lockToDate,
formattedLockedToDate: moment(lockToDate).format('YYYY/MM/DD'),
});
@@ -88,14 +89,12 @@ export class TransactionsLockingGuard {
const lockingType =
await this.transactionsLockingRepo.getTransactionsLockingType();
//
if (lockingType === TransactionsLockingGroup.All) {
return this.validateTransactionsLocking(
transactionDate,
TransactionsLockingGroup.All,
);
}
//
return this.validateTransactionsLocking(transactionDate, moduleType);
};
}

View File

@@ -19,13 +19,11 @@ export enum TransactionsLockingType {
}
export interface ITransactionsLockingPartialUnlocked {
tenantId: number;
module: TransactionsLockingGroup;
transactionLockingDTO: ITransactionsLockingAllDTO;
}
export interface ITransactionsLockingCanceled {
tenantId: number;
module: TransactionsLockingGroup;
cancelLockingDTO: ICancelTransactionsLockingDTO;
}