fix(server): rename term to

This commit is contained in:
Ahmed Bouhuolia
2024-08-13 13:41:09 +02:00
parent cd90fede54
commit 9991eebaaf
35 changed files with 89 additions and 93 deletions

View File

@@ -0,0 +1,71 @@
import * as R from 'ramda';
import { Inject, Service } from 'typedi';
import { omit, sumBy } from 'lodash';
import {
ICustomer,
IPaymentReceive,
IPaymentReceiveCreateDTO,
IPaymentReceiveEditDTO,
} from '@/interfaces';
import { PaymentReceivedValidators } from './PaymentReceivedValidators';
import { PaymentReceivedIncrement } from './PaymentReceivedIncrement';
import { BranchTransactionDTOTransform } from '@/services/Branches/Integrations/BranchTransactionDTOTransform';
import { formatDateFields } from '@/utils';
@Service()
export class PaymentReceiveDTOTransformer {
@Inject()
private validators: PaymentReceivedValidators;
@Inject()
private increments: PaymentReceivedIncrement;
@Inject()
private branchDTOTransform: BranchTransactionDTOTransform;
/**
* Transformes the create payment receive DTO to model object.
* @param {number} tenantId
* @param {IPaymentReceiveCreateDTO|IPaymentReceiveEditDTO} paymentReceiveDTO - Payment receive DTO.
* @param {IPaymentReceive} oldPaymentReceive -
* @return {IPaymentReceive}
*/
public async transformPaymentReceiveDTOToModel(
tenantId: number,
customer: ICustomer,
paymentReceiveDTO: IPaymentReceiveCreateDTO | IPaymentReceiveEditDTO,
oldPaymentReceive?: IPaymentReceive
): Promise<IPaymentReceive> {
const amount =
paymentReceiveDTO.amount ??
sumBy(paymentReceiveDTO.entries, 'paymentAmount');
// Retreive the next invoice number.
const autoNextNumber =
this.increments.getNextPaymentReceiveNumber(tenantId);
// Retrieve the next payment receive number.
const paymentReceiveNo =
paymentReceiveDTO.paymentReceiveNo ||
oldPaymentReceive?.paymentReceiveNo ||
autoNextNumber;
this.validators.validatePaymentNoRequire(paymentReceiveNo);
const initialDTO = {
...formatDateFields(omit(paymentReceiveDTO, ['entries', 'attachments']), [
'paymentDate',
]),
amount,
currencyCode: customer.currencyCode,
...(paymentReceiveNo ? { paymentReceiveNo } : {}),
exchangeRate: paymentReceiveDTO.exchangeRate || 1,
entries: paymentReceiveDTO.entries.map((entry) => ({
...entry,
})),
};
return R.compose(
this.branchDTOTransform.transformDTO<IPaymentReceive>(tenantId)
)(initialDTO);
}
}