mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
refactor(nestjs): transaction locking
This commit is contained in:
@@ -22,7 +22,7 @@ export class ValidateBranchExistance {
|
|||||||
public validateTransactionBranchWhenActive = async (
|
public validateTransactionBranchWhenActive = async (
|
||||||
branchId: number | null,
|
branchId: number | null,
|
||||||
) => {
|
) => {
|
||||||
const isActive = this.branchesSettings.isMultiBranchesActive();
|
const isActive = await this.branchesSettings.isMultiBranchesActive();
|
||||||
|
|
||||||
// Can't continue if the multi-warehouses feature is inactive.
|
// Can't continue if the multi-warehouses feature is inactive.
|
||||||
if (!isActive) return;
|
if (!isActive) return;
|
||||||
|
|||||||
@@ -119,8 +119,8 @@ export class MetableStore implements IMetableStore {
|
|||||||
value: newValue,
|
value: newValue,
|
||||||
key,
|
key,
|
||||||
...extraColumns,
|
...extraColumns,
|
||||||
|
group: extraColumns?.group || 'default',
|
||||||
_markAsInserted: true,
|
_markAsInserted: true,
|
||||||
group: 'default',
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
import { Type } from 'class-transformer';
|
||||||
import { IsString } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
import { IsNotEmpty } from 'class-validator';
|
import { IsNotEmpty } from 'class-validator';
|
||||||
import { IsDate } from 'class-validator';
|
import { IsDate } from 'class-validator';
|
||||||
|
|
||||||
export class TransactionsLockingDto {
|
export class TransactionsLockingDto {
|
||||||
|
@IsString()
|
||||||
|
module: string;
|
||||||
|
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
lockToDate: Date;
|
lockToDate: Date;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { TransactionsLockingGroup } from '../types/TransactionsLocking.types';
|
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { TransactionsLockingGuard } from './TransactionsLockingGuard';
|
|
||||||
import { MomentInput } from 'moment';
|
import { MomentInput } from 'moment';
|
||||||
|
import { TransactionsLockingGroup } from '../types/TransactionsLocking.types';
|
||||||
|
import { TransactionsLockingGuard } from './TransactionsLockingGuard';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PurchasesTransactionLockingGuard {
|
export class PurchasesTransactionLockingGuard {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { TransactionsLockingGroup } from '../types/TransactionsLocking.types';
|
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { TransactionsLockingGuard } from './TransactionsLockingGuard';
|
|
||||||
import { MomentInput } from 'moment';
|
import { MomentInput } from 'moment';
|
||||||
|
import { TransactionsLockingGroup } from '../types/TransactionsLocking.types';
|
||||||
|
import { TransactionsLockingGuard } from './TransactionsLockingGuard';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SalesTransactionLockingGuard {
|
export class SalesTransactionLockingGuard {
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ export class TransactionsLockingGuard {
|
|||||||
) => {
|
) => {
|
||||||
const { lockToDate } =
|
const { lockToDate } =
|
||||||
await this.transactionsLockingRepo.getTransactionsLocking(lockingGroup);
|
await this.transactionsLockingRepo.getTransactionsLocking(lockingGroup);
|
||||||
throw new ServiceError(ERRORS.TRANSACTIONS_DATE_LOCKED, null, {
|
|
||||||
|
throw new ServiceError(ERRORS.TRANSACTIONS_DATE_LOCKED, 'Transactions locked', {
|
||||||
lockedToDate: lockToDate,
|
lockedToDate: lockToDate,
|
||||||
formattedLockedToDate: moment(lockToDate).format('YYYY/MM/DD'),
|
formattedLockedToDate: moment(lockToDate).format('YYYY/MM/DD'),
|
||||||
});
|
});
|
||||||
@@ -88,14 +89,12 @@ export class TransactionsLockingGuard {
|
|||||||
const lockingType =
|
const lockingType =
|
||||||
await this.transactionsLockingRepo.getTransactionsLockingType();
|
await this.transactionsLockingRepo.getTransactionsLockingType();
|
||||||
|
|
||||||
//
|
|
||||||
if (lockingType === TransactionsLockingGroup.All) {
|
if (lockingType === TransactionsLockingGroup.All) {
|
||||||
return this.validateTransactionsLocking(
|
return this.validateTransactionsLocking(
|
||||||
transactionDate,
|
transactionDate,
|
||||||
TransactionsLockingGroup.All,
|
TransactionsLockingGroup.All,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
return this.validateTransactionsLocking(transactionDate, moduleType);
|
return this.validateTransactionsLocking(transactionDate, moduleType);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,11 @@ export enum TransactionsLockingType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ITransactionsLockingPartialUnlocked {
|
export interface ITransactionsLockingPartialUnlocked {
|
||||||
tenantId: number;
|
|
||||||
module: TransactionsLockingGroup;
|
module: TransactionsLockingGroup;
|
||||||
transactionLockingDTO: ITransactionsLockingAllDTO;
|
transactionLockingDTO: ITransactionsLockingAllDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITransactionsLockingCanceled {
|
export interface ITransactionsLockingCanceled {
|
||||||
tenantId: number;
|
|
||||||
module: TransactionsLockingGroup;
|
module: TransactionsLockingGroup;
|
||||||
cancelLockingDTO: ICancelTransactionsLockingDTO;
|
cancelLockingDTO: ICancelTransactionsLockingDTO;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,26 +64,22 @@ export interface IEditWarehouseTransferDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IWarehouseEditPayload {
|
export interface IWarehouseEditPayload {
|
||||||
tenantId: number;
|
|
||||||
warehouseId: number;
|
warehouseId: number;
|
||||||
warehouseDTO: IEditWarehouseDTO;
|
warehouseDTO: IEditWarehouseDTO;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWarehouseEditedPayload {
|
export interface IWarehouseEditedPayload {
|
||||||
tenantId: number;
|
|
||||||
warehouse: IWarehouse;
|
warehouse: IWarehouse;
|
||||||
warehouseDTO: IEditWarehouseDTO;
|
warehouseDTO: IEditWarehouseDTO;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWarehouseDeletePayload {
|
export interface IWarehouseDeletePayload {
|
||||||
// tenantId: number;
|
|
||||||
warehouseId: number;
|
warehouseId: number;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
export interface IWarehouseDeletedPayload {
|
export interface IWarehouseDeletedPayload {
|
||||||
tenantId: number;
|
|
||||||
warehouseId: number;
|
warehouseId: number;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
@@ -101,7 +97,6 @@ export interface IWarehouseCreatedPayload {
|
|||||||
export interface IWarehouseTransferCreate {
|
export interface IWarehouseTransferCreate {
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
warehouseTransferDTO: ICreateWarehouseTransferDTO;
|
warehouseTransferDTO: ICreateWarehouseTransferDTO;
|
||||||
tenantId: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWarehouseTransferCreated {
|
export interface IWarehouseTransferCreated {
|
||||||
@@ -146,10 +141,8 @@ export interface IItemWarehouseQuantityChange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IWarehousesActivatePayload {
|
export interface IWarehousesActivatePayload {
|
||||||
// tenantId: number;
|
|
||||||
}
|
}
|
||||||
export interface IWarehousesActivatedPayload {
|
export interface IWarehousesActivatedPayload {
|
||||||
// tenantId: number;
|
|
||||||
primaryWarehouse: Warehouse;
|
primaryWarehouse: Warehouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ describe.only('Transactions Locking (e2e)', () => {
|
|||||||
return request(app.getHttpServer())
|
return request(app.getHttpServer())
|
||||||
.put('/transactions-locking/lock')
|
.put('/transactions-locking/lock')
|
||||||
.set('organization-id', orgainzationId)
|
.set('organization-id', orgainzationId)
|
||||||
|
.set('Authorization', AuthorizationHeader)
|
||||||
.send({
|
.send({
|
||||||
module: 'all',
|
module: 'all',
|
||||||
lock_to_date: '2025-01-01',
|
lock_to_date: '2025-01-01',
|
||||||
|
|||||||
Reference in New Issue
Block a user