UNPKG

@accounter/server

Version:

The test suite is split into three Vitest projects for efficiency and isolation:

47 lines 1.87 kB
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 getBalanceCancellationByChargesIds = sql ` SELECT * FROM accounter_schema.charge_balance_cancellation WHERE charge_id IN $$chargeIds;`; const deleteBalanceCancellationByBusinessId = sql ` DELETE FROM accounter_schema.charge_balance_cancellation WHERE business_id = $businessId;`; let BalanceCancellationProvider = class BalanceCancellationProvider { dbProvider; cache = getCacheInstance({ stdTTL: 60 * 5, }); constructor(dbProvider) { this.dbProvider = dbProvider; } async batchBalanceCancellationByChargesIds(ids) { const ballanceCancellations = await getBalanceCancellationByChargesIds.run({ chargeIds: ids, }, this.dbProvider); return ids.map(id => ballanceCancellations.filter(record => record.charge_id === id)); } getBalanceCancellationByChargesIdLoader = new DataLoader((keys) => this.batchBalanceCancellationByChargesIds(keys), { cacheKeyFn: key => `balance-cancellation-charge-${key}`, cacheMap: this.cache, }); deleteBalanceCancellationByBusinessId(businessId) { return deleteBalanceCancellationByBusinessId.run({ businessId }, this.dbProvider); } clearCache() { this.cache.clear(); } }; BalanceCancellationProvider = __decorate([ Injectable({ scope: Scope.Singleton, global: true, }), __metadata("design:paramtypes", [DBProvider]) ], BalanceCancellationProvider); export { BalanceCancellationProvider }; //# sourceMappingURL=balance-cancellation.provider.js.map