mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat: tax rate transformer
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import { CommandTaxRatesValidators } from './CommandTaxRatesValidators';
|
||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
import { TaxRateTransformer } from './TaxRateTransformer';
|
||||
|
||||
@Service()
|
||||
export class GetTaxRateService {
|
||||
@@ -10,6 +12,9 @@ export class GetTaxRateService {
|
||||
@Inject()
|
||||
private validators: CommandTaxRatesValidators;
|
||||
|
||||
@Inject()
|
||||
private transformer: TransformerInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the given tax rate.
|
||||
* @param {number} tenantId
|
||||
@@ -24,6 +29,11 @@ export class GetTaxRateService {
|
||||
// Validates the tax rate existance.
|
||||
this.validators.validateTaxRateExistance(taxRate);
|
||||
|
||||
return taxRate;
|
||||
// Transforms the tax rate.
|
||||
return this.transformer.transform(
|
||||
tenantId,
|
||||
taxRate,
|
||||
new TaxRateTransformer()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
import { TaxRateTransformer } from './TaxRateTransformer';
|
||||
|
||||
@Service()
|
||||
export class GetTaxRatesService {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private transformer: TransformerInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the tax rates list.
|
||||
* @param {number} tenantId
|
||||
@@ -16,6 +21,11 @@ export class GetTaxRatesService {
|
||||
|
||||
const taxRates = await TaxRate.query();
|
||||
|
||||
return taxRates;
|
||||
// Transforms the tax rates.
|
||||
return this.transformer.transform(
|
||||
tenantId,
|
||||
taxRates,
|
||||
new TaxRateTransformer()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
20
packages/server/src/services/TaxRates/TaxRateTransformer.ts
Normal file
20
packages/server/src/services/TaxRates/TaxRateTransformer.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||
|
||||
export class TaxRateTransformer extends Transformer {
|
||||
/**
|
||||
* Include these attributes to tax rate object.
|
||||
* @returns {Array}
|
||||
*/
|
||||
public includeAttributes = (): string[] => {
|
||||
return ['nameFormatted'];
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats the tax rate name.
|
||||
* @param taxRate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected nameFormatted = (taxRate): string => {
|
||||
return `${taxRate.name} (${taxRate.rate}%)`;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user