mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
refactor(nestjs): transaction locking
This commit is contained in:
@@ -22,7 +22,7 @@ export class ValidateBranchExistance {
|
||||
public validateTransactionBranchWhenActive = async (
|
||||
branchId: number | null,
|
||||
) => {
|
||||
const isActive = this.branchesSettings.isMultiBranchesActive();
|
||||
const isActive = await this.branchesSettings.isMultiBranchesActive();
|
||||
|
||||
// Can't continue if the multi-warehouses feature is inactive.
|
||||
if (!isActive) return;
|
||||
|
||||
@@ -119,8 +119,8 @@ export class MetableStore implements IMetableStore {
|
||||
value: newValue,
|
||||
key,
|
||||
...extraColumns,
|
||||
group: extraColumns?.group || 'default',
|
||||
_markAsInserted: true,
|
||||
group: 'default',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -64,26 +64,22 @@ export interface IEditWarehouseTransferDTO {
|
||||
}
|
||||
|
||||
export interface IWarehouseEditPayload {
|
||||
tenantId: number;
|
||||
warehouseId: number;
|
||||
warehouseDTO: IEditWarehouseDTO;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface IWarehouseEditedPayload {
|
||||
tenantId: number;
|
||||
warehouse: IWarehouse;
|
||||
warehouseDTO: IEditWarehouseDTO;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
export interface IWarehouseDeletePayload {
|
||||
// tenantId: number;
|
||||
warehouseId: number;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
export interface IWarehouseDeletedPayload {
|
||||
tenantId: number;
|
||||
warehouseId: number;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
@@ -101,7 +97,6 @@ export interface IWarehouseCreatedPayload {
|
||||
export interface IWarehouseTransferCreate {
|
||||
trx: Knex.Transaction;
|
||||
warehouseTransferDTO: ICreateWarehouseTransferDTO;
|
||||
tenantId: number;
|
||||
}
|
||||
|
||||
export interface IWarehouseTransferCreated {
|
||||
@@ -146,10 +141,8 @@ export interface IItemWarehouseQuantityChange {
|
||||
}
|
||||
|
||||
export interface IWarehousesActivatePayload {
|
||||
// tenantId: number;
|
||||
}
|
||||
export interface IWarehousesActivatedPayload {
|
||||
// tenantId: number;
|
||||
primaryWarehouse: Warehouse;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user