mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
33 lines
806 B
TypeScript
33 lines
806 B
TypeScript
import { omit } from 'lodash';
|
|
import { Inject, Service } from 'typedi';
|
|
import { IManualJournal } from '@/interfaces';
|
|
import { BranchesSettings } from '../../BranchesSettings';
|
|
|
|
@Service()
|
|
export class ManualJournalBranchesDTOTransformer {
|
|
@Inject()
|
|
branchesSettings: BranchesSettings;
|
|
|
|
private excludeDTOBranchIdWhenInactive = (
|
|
tenantId: number,
|
|
DTO: IManualJournal
|
|
): IManualJournal => {
|
|
const isActive = this.branchesSettings.isMultiBranchesActive(tenantId);
|
|
|
|
if (isActive) return DTO;
|
|
|
|
return {
|
|
...DTO,
|
|
entries: DTO.entries.map((e) => omit(e, ['branchId'])),
|
|
};
|
|
};
|
|
/**
|
|
*
|
|
*/
|
|
public transformDTO =
|
|
(tenantId: number) =>
|
|
(DTO: IManualJournal): IManualJournal => {
|
|
return this.excludeDTOBranchIdWhenInactive(tenantId, DTO);
|
|
};
|
|
}
|