A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
refactor(billing): share refund lookup fields, drop dead exports
Hampus2575d183fd6d
diff --git a/fluxer_api/src/api/billing/mappers/StripeToBillingMapper.ts b/fluxer_api/src/api/billing/mappers/StripeToBillingMapper.tsindex 4942fd3e1..99a88c9ad 100644--- a/fluxer_api/src/api/billing/mappers/StripeToBillingMapper.ts+++ b/fluxer_api/src/api/billing/mappers/StripeToBillingMapper.ts@@ -186,7 +186,7 @@ class BillingMappingError extends Error {}}-export function unixToDate(seconds: number | null | undefined): Date | null {+function unixToDate(seconds: number | null | undefined): Date | null {if (seconds === null || seconds === undefined) {return null;}@@ -196,7 +196,7 @@ export function unixToDate(seconds: number | null | undefined): Date | null {return new Date(seconds * 1000);}-export function safeMetadata(m: Stripe.Metadata | null | undefined): Map<string, string> | null {+function safeMetadata(m: Stripe.Metadata | null | undefined): Map<string, string> | null {if (m === null || m === undefined) {return null;}@@ -779,6 +779,15 @@ export function mapStripeChargeToRow(c: Stripe.Charge): {return {primary};}+function refundLookupFields(refund: Stripe.Refund, createdAt: Date) {+ return {+ stripe_created_at: createdAt,+ provider_id: refund.id,+ status: refund.status ?? null,+ amount: typeof refund.amount === 'number' ? BigInt(refund.amount) : null,+ };+}+export function mapStripeRefundToRow(r: Stripe.Refund,hints?: {@@ -827,30 +836,21 @@ export function mapStripeRefundToRow(chargeId !== null? ({charge_id: chargeId,- stripe_created_at: createdAtForLookup,- provider_id: r.id,- status: r.status ?? null,- amount: typeof r.amount === 'number' ? BigInt(r.amount) : null,+ ...refundLookupFields(r, createdAtForLookup),} as BillingRefundByChargeRow): null;const byPaymentIntent: BillingRefundByPaymentIntentRow | null =paymentIntentId !== null? ({payment_intent_id: paymentIntentId,- stripe_created_at: createdAtForLookup,- provider_id: r.id,- status: r.status ?? null,- amount: typeof r.amount === 'number' ? BigInt(r.amount) : null,+ ...refundLookupFields(r, createdAtForLookup),} as BillingRefundByPaymentIntentRow): null;const byInvoice: BillingRefundByInvoiceRow | null =invoiceId !== null? ({invoice_id: invoiceId,- stripe_created_at: createdAtForLookup,- provider_id: r.id,- status: r.status ?? null,- amount: typeof r.amount === 'number' ? BigInt(r.amount) : null,+ ...refundLookupFields(r, createdAtForLookup),} as BillingRefundByInvoiceRow): null;return {primary, byCharge, byPaymentIntent, byInvoice};diff --git a/fluxer_api/src/api/billing/repositories/BillingRefundRepository.ts b/fluxer_api/src/api/billing/repositories/BillingRefundRepository.tsindex d34d85e2d..3cfaa4ee8 100644--- a/fluxer_api/src/api/billing/repositories/BillingRefundRepository.ts+++ b/fluxer_api/src/api/billing/repositories/BillingRefundRepository.ts@@ -16,9 +16,6 @@ const FETCH_BY_ID = BillingRefunds.selectCql({where: BillingRefunds.where.eq('provider_id'),limit: 1,});-const FETCH_BY_CHARGE = BillingRefundsByCharge.selectCql({- where: BillingRefundsByCharge.where.eq('charge_id'),-});const FETCH_BY_PAYMENT_INTENT = BillingRefundsByPaymentIntent.selectCql({where: BillingRefundsByPaymentIntent.where.eq('payment_intent_id'),});@@ -34,10 +31,6 @@ export class BillingRefundRepository {return fetchOne<BillingRefundRow>(FETCH_BY_ID, {provider_id: providerId});}- async listByCharge(chargeId: string): Promise<Array<BillingRefundRow>> {- return hydrateByRefs<BillingRefundRow>(FETCH_BY_CHARGE, {charge_id: chargeId}, FETCH_BY_PROVIDER_IDS);- }-async listByPaymentIntent(paymentIntentId: string): Promise<Array<BillingRefundRow>> {return hydrateByRefs<BillingRefundRow>(FETCH_BY_PAYMENT_INTENT,diff --git a/fluxer_api/src/api/billing/repositories/BillingRepoHelpers.ts b/fluxer_api/src/api/billing/repositories/BillingRepoHelpers.tsindex c1033ebfb..24771e74b 100644--- a/fluxer_api/src/api/billing/repositories/BillingRepoHelpers.ts+++ b/fluxer_api/src/api/billing/repositories/BillingRepoHelpers.ts@@ -4,7 +4,7 @@ import {fetchMany, upsertOne} from '@app/api/database/CassandraQueryExecution';import type {CassandraParams, ColumnName, PreparedQuery, Table} from '@app/api/database/CassandraTypes';import {buildPatchFromData, executeVersionedUpdate, valuesEqual} from '@app/api/database/CassandraVersionedUpdate';-export function rowsEquivalent<T extends object>(a: T, b: T, ignoreFields: ReadonlyArray<keyof T>): boolean {+function rowsEquivalent<T extends object>(a: T, b: T, ignoreFields: ReadonlyArray<keyof T>): boolean {const ignore = new Set<keyof T>(ignoreFields);const keys = new Set<keyof T>([...(Object.keys(a) as Array<keyof T>), ...(Object.keys(b) as Array<keyof T>)]);for (const key of keys) {@@ -14,7 +14,7 @@ export function rowsEquivalent<T extends object>(a: T, b: T, ignoreFields: Readoreturn true;}-export function isExistingNewer(+function isExistingNewer(existing: {stripe_updated_at?: Date | null;} | null,