Fix price on voucher

This commit is contained in:
Roba Boru
2026-08-14 08:22:50 +03:00
parent 1f0d3d3a22
commit aa850146dc
3 changed files with 98 additions and 18 deletions

View File

@@ -0,0 +1,49 @@
/**
* One-off data fix: corrects PaymentMethod.currency for methods whose settlement currency
* was never set at seed time and silently defaulted to the schema's ETB default.
*
* payments.service.ts's chargeCurrency resolution reads this column directly (see the
* comment above `chargeCurrency` in `initiatePayment`): WAAFI settles in DJF, CARD in USD.
* With WAAFI stuck on the ETB default, live Waafi payments were charged in ETB instead of
* being converted to DJF — not just a mislabeled report. This script only touches the
* PaymentMethod config row; it does NOT rewrite any existing PaymentIntent/Booking records,
* since correcting historical transaction currency is a financial decision, not a data-fix
* this script should make unilaterally.
*
* Safe to re-run. Only updates rows that already exist; does not create new ones.
*
* Usage: node --env-file=.env -r ts-node/register prisma/fix-payment-method-currency.ts
*/
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const CORRECTIONS: { type: string; currency: string }[] = [
{ type: 'WAAFI', currency: 'DJF' },
{ type: 'CARD', currency: 'USD' },
];
async function main() {
for (const { type, currency } of CORRECTIONS) {
const existing = await prisma.paymentMethod.findUnique({ where: { type: type as any } });
if (!existing) {
console.log(` ⚠️ No PaymentMethod row for ${type} — skipping (nothing to correct).`);
continue;
}
if (existing.currency === currency) {
console.log(` ${type} already set to ${currency} — no change.`);
continue;
}
await prisma.paymentMethod.update({ where: { type: type as any }, data: { currency } });
console.log(`${type}: ${existing.currency}${currency}`);
}
}
main()
.catch((e) => {
console.error('❌ fix-payment-method-currency failed:', e);
process.exitCode = 1;
})
.finally(async () => {
await prisma.$disconnect();
});