mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
fix(server): add formatted values to responses transformers
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user