@accounter/server
Version:
The test suite is split into three Vitest projects for efficiency and isolation:
39 lines • 1.47 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import DataLoader from 'dataloader';
import { Injectable, Scope } from 'graphql-modules';
import { sql } from '@pgtyped/runtime';
import { getCacheInstance } from '../../../shared/helpers/index.js';
import { DBProvider } from '../../app-providers/db.provider.js';
const getAllTaxVariables = sql `
SELECT *
FROM accounter_schema.business_trips_tax_variables
ORDER BY date DESC;`;
let BusinessTripTaxVariablesProvider = class BusinessTripTaxVariablesProvider {
dbProvider;
cache = getCacheInstance({
stdTTL: 60 * 5,
});
constructor(dbProvider) {
this.dbProvider = dbProvider;
}
async batchTaxVariablesByDates(dates) {
const taxVariables = await getAllTaxVariables.run(undefined, this.dbProvider);
return dates.map(date => taxVariables.find(record => date.getTime() >= record.date.getTime()));
}
getTaxVariablesByDateLoader = new DataLoader((dates) => this.batchTaxVariablesByDates(dates), {
cacheKeyFn: date => date.getTime(),
cacheMap: this.cache,
});
clearCache() {
this.cache.clear();
}
};
BusinessTripTaxVariablesProvider = __decorate([
Injectable({
scope: Scope.Singleton,
global: true,
}),
__metadata("design:paramtypes", [DBProvider])
], BusinessTripTaxVariablesProvider);
export { BusinessTripTaxVariablesProvider };
//# sourceMappingURL=business-trips-tax-variables.provider.js.map