Files
dashlibstorage/src/store/payment/delete.js
2026-10-09 10:41:17 +02:00

27 lines
952 B
JavaScript

import { queriesFor, requireId } from '../logistics/helpers.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import makeRunner from '../runner.js';
/**
* Deletes a payment belonging to a manifest of the user's selected company.
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {number} id - The payment id.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<void>}
*
* @example
* await store.payment.delete(googleAuthId, 7);
*/
export default function del(provider) {
const access = resolveSelectedCompanyAccess(provider);
const q = queriesFor(provider);
return async (googleAuthId, id, tx) => {
const paymentId = requireId(id, 'Payment');
const runner = makeRunner(provider, tx);
const { companyId } = await access(googleAuthId, runner);
await runner.query(q.PAYMENT_DELETE, { id: paymentId, companyId });
};
}