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

38 lines
1.5 KiB
JavaScript

import { queriesFor, requireId } from '../logistics/helpers.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import resolveManifestAccess from '../manifestattachment/resolveManifestAccess.js';
import makeRunner from '../runner.js';
/**
* Lists payments of a manifest (order) in the user's selected company.
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {number} manifestId - The manifest id.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<Array<{id: number, accountId: number, manifestId: number, type: string, amount: number}>>}
*
* @example
* const payments = await store.payment.listByManifestId(googleAuthId, 42);
*/
export default function listByManifestId(provider) {
const access = resolveSelectedCompanyAccess(provider);
const manifestAccess = resolveManifestAccess(provider);
const q = queriesFor(provider);
return async (googleAuthId, manifestIdInput, tx) => {
const manifestId = requireId(manifestIdInput, 'Manifest');
const runner = makeRunner(provider, tx);
const { companyId } = await access(googleAuthId, runner);
await manifestAccess(companyId, manifestId, tx);
const result = await runner.query(q.PAYMENT_LIST_BY_MANIFEST, { manifestId });
return result.rows.map((row) => ({
id: row.id,
accountId: row.account_id,
manifestId: row.manifest_id,
type: row.type,
amount: row.amount,
}));
};
}