Files
edr-platform/apps/edr-passenger-api/prisma/fix-payment-method-currency.ts
2026-08-14 08:22:50 +03:00

50 lines
1.9 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 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();
});