feat: setting up the date format in the whole system dates

This commit is contained in:
Ahmed Bouhuolia
2024-06-12 19:43:42 +02:00
parent 265ea9ca48
commit 3a0a0db8a7
24 changed files with 62 additions and 52 deletions

View File

@@ -5,7 +5,7 @@ import DashboardService from '@/services/Dashboard/DashboardService';
@Service()
export default class DashboardMetaController {
@Inject()
dashboardService: DashboardService;
private dashboardService: DashboardService;
/**
* Constructor router.

View File

@@ -149,13 +149,19 @@ export class Transformer {
return this.excludeAttributes().length > 0;
};
private dateFormat = 'YYYY MMM DD';
setDateFormat(format: string) {
this.dateFormat = format;
}
/**
*
* @param date
* @returns
*/
protected formatDate(date) {
return date ? moment(date).format('YYYY/MM/DD') : '';
return date ? moment(date).format(this.dateFormat) : '';
}
/**
@@ -193,6 +199,7 @@ export class Transformer {
) {
transformer.setOptions(options);
transformer.setContext(this.context);
transformer.setDateFormat(this.dateFormat);
return transformer.work(obj);
}

View File

@@ -24,6 +24,17 @@ export class TransformerInjectable {
};
}
/**
* Retrieves the given tenatn date format.
* @param {number} tenantId
* @returns {string}
*/
async getTenantDateFormat(tenantId: number) {
const metadata = await TenantMetadata.query().findOne('tenantId', tenantId);
return metadata.dateFormat;
}
/**
* Transformes the given transformer after inject the tenant context.
* @param {number} tenantId
@@ -41,7 +52,11 @@ export class TransformerInjectable {
if (!isNull(tenantId)) {
const context = await this.getApplicationContext(tenantId);
transformer.setContext(context);
const dateFormat = await this.getTenantDateFormat(tenantId);
transformer.setDateFormat(dateFormat);
}
transformer.setOptions(options);
return transformer.work(object);

View File

@@ -1,5 +1,6 @@
import { Transformer } from '@/lib/Transformer/Transformer';
import { formatNumber } from '@/utils';
import { PurchaseInvoiceTransformer } from '../Bills/PurchaseInvoiceTransformer';
export class BillPaymentEntryTransformer extends Transformer {
/**
@@ -7,7 +8,14 @@ export class BillPaymentEntryTransformer extends Transformer {
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return ['paymentAmountFormatted'];
return ['paymentAmountFormatted', 'bill'];
};
/**
* Retreives the
*/
protected bill = (entry) => {
return this.item(entry.bill, new PurchaseInvoiceTransformer());
};
/**