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

@@ -0,0 +1,37 @@
import { IItemEntry } from '@/interfaces';
import { Transformer } from '@/lib/Transformer/Transformer';
import { formatNumber } from '@/utils';
export class ItemEntryTransformer extends Transformer {
/**
* Include these attributes to item entry object.
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return ['rateFormatted', 'totalFormatted'];
};
/**
* Retrieves the formatted rate of item entry.
* @param {IItemEntry} itemEntry -
* @returns {string}
*/
protected rateFormatted = (entry: IItemEntry): string => {
return formatNumber(entry.rate, {
currencyCode: this.context.currencyCode,
money: false,
});
};
/**
* Retrieves the formatted total of item entry.
* @param {IItemEntry} entry
* @returns {string}
*/
protected totalFormatted = (entry: IItemEntry): string => {
return formatNumber(entry.total, {
currencyCode: this.context.currencyCode,
money: false,
});
};
}