fix(server): add formatted values to responses transformers

This commit is contained in:
Ahmed Bouhuolia
2023-12-04 08:21:06 +02:00
parent 0f39cfb3af
commit fb70c94465
12 changed files with 189 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { Inject, Service } from 'typedi';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { PaymentReceiveValidators } from './PaymentReceiveValidators';
@Service()

View File

@@ -0,0 +1,29 @@
import { Transformer } from '@/lib/Transformer/Transformer';
import { SaleInvoiceTransformer } from '../Invoices/SaleInvoiceTransformer';
import { formatNumber } from '@/utils';
export class PaymentReceiveEntryTransfromer extends Transformer {
/**
* Include these attributes to payment receive entry object.
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return ['paymentAmountFormatted', 'entry'];
};
/**
* Retreives the payment amount formatted.
* @param entry
* @returns {string}
*/
protected paymentAmountFormatted(entry) {
return formatNumber(entry.paymentAmount, { money: false });
}
/**
* Retreives the transformed invoice.
*/
protected invoice(entry) {
return this.item(entry.invoice, new SaleInvoiceTransformer());
}
}

View File

@@ -2,6 +2,7 @@ import { IPaymentReceive, IPaymentReceiveEntry } from '@/interfaces';
import { Transformer } from '@/lib/Transformer/Transformer';
import { formatNumber } from 'utils';
import { SaleInvoiceTransformer } from '../Invoices/SaleInvoiceTransformer';
import { PaymentReceiveEntryTransfromer } from './PaymentReceiveEntryTransformer';
export class PaymentReceiveTransfromer extends Transformer {
/**
@@ -45,14 +46,11 @@ export class PaymentReceiveTransfromer extends Transformer {
};
/**
* Retrieves the
* @param {IPaymentReceive} payment
* Retrieves the payment entries.
* @param {IPaymentReceive} payment
* @returns {IPaymentReceiveEntry[]}
*/
protected entries = (payment: IPaymentReceive): IPaymentReceiveEntry[] => {
return payment?.entries?.map((entry) => ({
...entry,
invoice: this.item(entry.invoice, new SaleInvoiceTransformer()),
}));
return this.item(payment.entries, new PaymentReceiveEntryTransfromer());
};
}