38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
import { listDueDynamicQrTransactions, toTransactionPayload, updateTransactionStatus } from "../store/transactionStore";
|
|
export async function expireDueDynamicQrTransactions(input) {
|
|
const due = await listDueDynamicQrTransactions(input?.limit || 100);
|
|
const expired = [];
|
|
const skipped = [];
|
|
const sweptAt = new Date().toISOString();
|
|
for (const tx of due) {
|
|
try {
|
|
const updated = await updateTransactionStatus(tx.id, "expired", {
|
|
source: input?.source || "system",
|
|
expired_at: tx.expired_at || sweptAt,
|
|
eventContext: {
|
|
reason: "dynamic_qr_expired",
|
|
expired_at: tx.expired_at,
|
|
swept_at: sweptAt,
|
|
request_id: input?.request_id
|
|
}
|
|
});
|
|
expired.push(toTransactionPayload(updated));
|
|
}
|
|
catch (error) {
|
|
skipped.push({
|
|
transaction_id: tx.id,
|
|
partner_reference: tx.partner_reference,
|
|
reason: error instanceof Error ? error.message : "UNKNOWN_ERROR"
|
|
});
|
|
}
|
|
}
|
|
return {
|
|
scanned: due.length,
|
|
expired_count: expired.length,
|
|
skipped_count: skipped.length,
|
|
swept_at: sweptAt,
|
|
expired,
|
|
skipped
|
|
};
|
|
}
|