refactor: sale estimates to nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-22 14:16:01 +02:00
parent 8a12caf48d
commit 336171081e
69 changed files with 4998 additions and 497 deletions

View File

@@ -1,35 +1,31 @@
// import { Service, Inject } from 'typedi';
// import { omit } from 'lodash';
// import { BranchesSettings } from '../BranchesSettings';
import { Inject, Injectable } from '@nestjs/common';
import { omit } from 'lodash';
import { BranchesSettingsService } from '../BranchesSettings';
// @Service()
// export class BranchTransactionDTOTransform {
// @Inject()
// branchesSettings: BranchesSettings;
@Injectable()
export class BranchTransactionDTOTransformer {
constructor(private readonly branchesSettings: BranchesSettingsService) {}
// /**
// * Excludes DTO branch id when mutli-warehouses feature is inactive.
// * @param {number} tenantId
// * @returns {any}
// */
// private excludeDTOBranchIdWhenInactive = <T extends { branchId?: number }>(
// tenantId: number,
// DTO: T
// ): Omit<T, 'branchId'> | T => {
// const isActive = this.branchesSettings.isMultiBranchesActive(tenantId);
/**
* Excludes DTO branch id when mutli-warehouses feature is inactive.
* @returns {any}
*/
private excludeDTOBranchIdWhenInactive = <T extends { branchId?: number }>(
DTO: T,
): Omit<T, 'branchId'> | T => {
const isActive = this.branchesSettings.isMultiBranchesActive();
// return !isActive ? omit(DTO, ['branchId']) : DTO;
// };
return !isActive ? omit(DTO, ['branchId']) : DTO;
};
// /**
// * Transformes the input DTO for branches feature.
// * @param {number} tenantId -
// * @param {T} DTO -
// * @returns {Omit<T, 'branchId'> | T}
// */
// public transformDTO =
// <T extends { branchId?: number }>(tenantId: number) =>
// (DTO: T): Omit<T, 'branchId'> | T => {
// return this.excludeDTOBranchIdWhenInactive<T>(tenantId, DTO);
// };
// }
/**
* Transformes the input DTO for branches feature.
* @param {T} DTO -
* @returns {Omit<T, 'branchId'> | T}
*/
public transformDTO = <T extends { branchId?: number }>(
DTO: T,
): Omit<T, 'branchId'> | T => {
return this.excludeDTOBranchIdWhenInactive<T>(DTO);
};
}