UNPKG

@accounter/server

Version:

51 lines 2.25 kB
import { BusinessTripsProvider } from '../../business-trips/providers/business-trips.provider.js'; import { ChargesProvider } from '../../charges/providers/charges.provider.js'; import { commonChargeFields } from './common.js'; export const accountantApprovalResolvers = { Mutation: { updateChargeAccountantApproval: async (_, { chargeId, approvalStatus }, { injector }) => { const adjustedFields = { accountantStatus: approvalStatus, chargeId, }; const res = await injector .get(ChargesProvider) .updateAccountantApproval({ ...adjustedFields }); if (!res || res.length === 0) { throw new Error(`Failed to update charge ID='${chargeId}'`); } /* clear cache */ if (res[0].id) { injector.get(ChargesProvider).getChargeByIdLoader.clear(res[0].id); } return res[0].accountant_status || 'UNAPPROVED'; }, updateBusinessTripAccountantApproval: async (_, { businessTripId, approvalStatus }, { injector }) => { const adjustedFields = { accountantStatus: approvalStatus, businessTripId, }; const res = await injector .get(BusinessTripsProvider) .updateAccountantApproval({ ...adjustedFields }); if (!res || res.length === 0) { throw new Error(`Failed to update business trip ID='${businessTripId}'`); } return res[0].accountant_status || 'UNAPPROVED'; }, }, CommonCharge: commonChargeFields, FinancialCharge: commonChargeFields, ConversionCharge: commonChargeFields, SalaryCharge: commonChargeFields, InternalTransferCharge: commonChargeFields, DividendCharge: commonChargeFields, BusinessTripCharge: commonChargeFields, MonthlyVatCharge: commonChargeFields, BankDepositCharge: commonChargeFields, CreditcardBankCharge: commonChargeFields, BusinessTrip: { accountantApproval: dbBusinessTrip => dbBusinessTrip.accountant_status ?? 'UNAPPROVED', }, }; //# sourceMappingURL=accountant-approval.resolver.js.map