mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
refactor: remove dead code (#3337)
This commit is contained in:
1 parent
a19002652b
commit
93d1f8af46
1527 files changed
+21170
-73846
No files matched your search
@@ -46,7 +46,7 @@ type StripeExpandableId =
|
||||
| null
|
||||
| undefined;
|
||||
|
||||
export interface StripeSubscriptionPendingUpdatePayload {
|
||||
interface StripeSubscriptionPendingUpdatePayload {
|
||||
expires_at?: number | null;
|
||||
subscription_proration_subtotal?: number | null;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ interface StripeSubscriptionItemPricePayload {
|
||||
unit_amount?: number | null;
|
||||
}
|
||||
|
||||
export interface StripeSubscriptionItemPayload {
|
||||
interface StripeSubscriptionItemPayload {
|
||||
id: string;
|
||||
current_period_start?: number | null;
|
||||
current_period_end?: number | null;
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {fetchMany, fetchOne, upsertOne} from '@app/api/database/CassandraQueryExecution';
|
||||
import type {
|
||||
BillingActionIntentRow,
|
||||
BillingActionIntentStatus,
|
||||
BillingActionType,
|
||||
} from '@app/api/database/types/BillingTypes';
|
||||
import {BILLING_ACTION_INTENT_COLUMNS} from '@app/api/database/types/BillingTypes';
|
||||
import {fetchOne, upsertOne} from '@app/api/database/CassandraQueryExecution';
|
||||
import type {BillingActionIntentRow, BillingActionType} from '@app/api/database/types/BillingTypes';
|
||||
import type {ISnowflakeService} from '@app/api/infrastructure/ISnowflakeService';
|
||||
import {BillingActionIntents} from '@app/api/Tables';
|
||||
|
||||
@@ -14,10 +9,6 @@ const FETCH_BY_ID = BillingActionIntents.selectCql({
|
||||
where: BillingActionIntents.where.eq('intent_id'),
|
||||
limit: 1,
|
||||
});
|
||||
const FETCH_STUCK = BillingActionIntents.select({
|
||||
columns: BILLING_ACTION_INTENT_COLUMNS,
|
||||
where: [BillingActionIntents.where.eq('status'), BillingActionIntents.where.lt('started_at', 'older_than')],
|
||||
});
|
||||
|
||||
export class BillingActionIntentRepository {
|
||||
constructor(private snowflakeService: ISnowflakeService) {}
|
||||
@@ -58,37 +49,4 @@ export class BillingActionIntentRepository {
|
||||
async findById(intentId: bigint): Promise<BillingActionIntentRow | null> {
|
||||
return fetchOne<BillingActionIntentRow>(FETCH_BY_ID, {intent_id: intentId});
|
||||
}
|
||||
|
||||
async markStage(
|
||||
intentId: bigint,
|
||||
stage: BillingActionIntentStatus,
|
||||
fields: Partial<BillingActionIntentRow>,
|
||||
): Promise<void> {
|
||||
const current = await this.findById(intentId);
|
||||
if (!current) {
|
||||
throw new Error(`BillingActionIntent ${intentId} not found`);
|
||||
}
|
||||
const merged: BillingActionIntentRow = {
|
||||
...current,
|
||||
...fields,
|
||||
intent_id: intentId,
|
||||
status: stage,
|
||||
};
|
||||
await upsertOne(BillingActionIntents.upsertAll(merged));
|
||||
}
|
||||
|
||||
async findStuck(olderThan: Date): Promise<Array<BillingActionIntentRow>> {
|
||||
const nonTerminalStatuses: Array<BillingActionIntentStatus> = ['pending', 'sub_canceled', 'refund_created'];
|
||||
const all: Array<BillingActionIntentRow> = [];
|
||||
for (const status of nonTerminalStatuses) {
|
||||
const rows = await fetchMany<BillingActionIntentRow>(
|
||||
FETCH_STUCK.bind({
|
||||
status,
|
||||
older_than: olderThan,
|
||||
}),
|
||||
);
|
||||
all.push(...rows);
|
||||
}
|
||||
return all;
|
||||
}
|
||||
}
|
||||
@@ -32,9 +32,6 @@ const FETCH_BY_ID = BillingInvoices.selectCql({
|
||||
const FETCH_BY_CUSTOMER_PARTITION = BillingInvoicesByCustomer.selectCql({
|
||||
where: BillingInvoicesByCustomer.where.eq('customer_id'),
|
||||
});
|
||||
const FETCH_BY_SUBSCRIPTION_PARTITION = BillingInvoicesBySubscription.selectCql({
|
||||
where: BillingInvoicesBySubscription.where.eq('subscription_id'),
|
||||
});
|
||||
const FETCH_BY_PROVIDER_IDS = BillingInvoices.selectCql({
|
||||
where: BillingInvoices.where.in('provider_id', 'provider_ids'),
|
||||
});
|
||||
@@ -71,28 +68,6 @@ export class BillingInvoiceRepository {
|
||||
return {rows, pageState: refsPage.pageState};
|
||||
}
|
||||
|
||||
async listBySubscription(
|
||||
subscriptionId: string,
|
||||
page?: {
|
||||
pageSize: number;
|
||||
pageState?: string | null;
|
||||
},
|
||||
): Promise<PagedQueryResult<BillingInvoiceRow>> {
|
||||
const refsPage = await fetchPage<{
|
||||
provider_id: string;
|
||||
}>(
|
||||
FETCH_BY_SUBSCRIPTION_PARTITION,
|
||||
{subscription_id: subscriptionId},
|
||||
{pageSize: page?.pageSize ?? 50, pageState: page?.pageState ?? null},
|
||||
);
|
||||
if (refsPage.rows.length === 0) {
|
||||
return {rows: [], pageState: refsPage.pageState};
|
||||
}
|
||||
const ids = refsPage.rows.map((r) => r.provider_id);
|
||||
const rows = await fetchMany<BillingInvoiceRow>(FETCH_BY_PROVIDER_IDS, {provider_ids: ids});
|
||||
return {rows, pageState: refsPage.pageState};
|
||||
}
|
||||
|
||||
async listByUser(
|
||||
userId: bigint,
|
||||
page?: {
|
||||
|
||||
@@ -10,12 +10,7 @@ import {
|
||||
upsertOne,
|
||||
} from '@app/api/database/CassandraQueryExecution';
|
||||
import type {BillingPaymentIntentRow} from '@app/api/database/types/BillingTypes';
|
||||
import {
|
||||
BillingPaymentIntents,
|
||||
BillingPaymentIntentsByCustomer,
|
||||
BillingPayments,
|
||||
BillingPaymentsByInvoice,
|
||||
} from '@app/api/Tables';
|
||||
import {BillingPaymentIntents, BillingPaymentIntentsByCustomer} from '@app/api/Tables';
|
||||
import type Stripe from 'stripe';
|
||||
|
||||
const FETCH_BY_ID = BillingPaymentIntents.selectCql({
|
||||
@@ -28,15 +23,6 @@ const FETCH_BY_CUSTOMER = BillingPaymentIntentsByCustomer.selectCql({
|
||||
const FETCH_BY_PROVIDER_IDS = BillingPaymentIntents.selectCql({
|
||||
where: BillingPaymentIntents.where.in('provider_id', 'provider_ids'),
|
||||
});
|
||||
const FETCH_PAYMENT_INTENTS_BY_INVOICE_VIA_PAYMENTS = BillingPayments.selectCql({
|
||||
columns: ['payment_intent_id'],
|
||||
where: BillingPayments.where.eq('provider_id'),
|
||||
limit: 1,
|
||||
});
|
||||
const FETCH_PAYMENTS_BY_INVOICE = BillingPaymentsByInvoice.select({
|
||||
columns: ['provider_id', 'payment_intent_id'],
|
||||
where: BillingPaymentsByInvoice.where.eq('invoice_id'),
|
||||
});
|
||||
|
||||
export class BillingPaymentIntentRepository {
|
||||
async findById(providerId: string): Promise<BillingPaymentIntentRow | null> {
|
||||
@@ -65,32 +51,6 @@ export class BillingPaymentIntentRepository {
|
||||
return {rows, pageState: refsPage.pageState};
|
||||
}
|
||||
|
||||
async findByInvoiceId(invoiceId: string): Promise<BillingPaymentIntentRow | null> {
|
||||
const refs = await fetchMany<{
|
||||
provider_id: string;
|
||||
payment_intent_id: string | null;
|
||||
}>(
|
||||
FETCH_PAYMENTS_BY_INVOICE.bind({
|
||||
invoice_id: invoiceId,
|
||||
}),
|
||||
);
|
||||
if (refs.length === 0) return null;
|
||||
for (const ref of refs) {
|
||||
const payment = await fetchOne<{
|
||||
is_default: boolean | null;
|
||||
payment_intent_id: string | null;
|
||||
}>(FETCH_PAYMENT_INTENTS_BY_INVOICE_VIA_PAYMENTS, {provider_id: ref.provider_id});
|
||||
if (payment?.is_default === true && payment.payment_intent_id) {
|
||||
return this.findById(payment.payment_intent_id);
|
||||
}
|
||||
}
|
||||
const firstWithIntent = refs.find((r) => r.payment_intent_id !== null);
|
||||
if (firstWithIntent?.payment_intent_id) {
|
||||
return this.findById(firstWithIntent.payment_intent_id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async upsertFromStripe(pi: Stripe.PaymentIntent): Promise<{
|
||||
changed: boolean;
|
||||
row: BillingPaymentIntentRow;
|
||||
|
||||
@@ -40,11 +40,6 @@ export class BillingPaymentMethodRepository {
|
||||
return rows.filter((row) => row.customer_id === customerId);
|
||||
}
|
||||
|
||||
async findDefaultForCustomer(customerId: string): Promise<BillingPaymentMethodRow | null> {
|
||||
const list = await this.listByCustomer(customerId);
|
||||
return list.find((r) => r.is_default === true) ?? null;
|
||||
}
|
||||
|
||||
async upsertFromStripe(
|
||||
pm: Stripe.PaymentMethod,
|
||||
hints?: {
|
||||
|
||||
@@ -24,11 +24,6 @@ export class BillingPriceRepository {
|
||||
return fetchOne<BillingPriceRow>(FETCH_BY_ID, {provider_id: providerId});
|
||||
}
|
||||
|
||||
async listByProduct(productId: string): Promise<Array<BillingPriceRow>> {
|
||||
const result = await fetchPage<BillingPriceRow>(FETCH_ALL, {}, {pageSize: 1000, pageState: null});
|
||||
return result.rows.filter((r) => r.product_id === productId);
|
||||
}
|
||||
|
||||
async listAllActive(page?: {
|
||||
pageSize: number;
|
||||
pageState?: string | null;
|
||||
|
||||
@@ -30,11 +30,6 @@ const FETCH_BY_USER = BillingSubscriptionsByUser.selectCql({
|
||||
const FETCH_BY_PROVIDER_IDS = BillingSubscriptions.selectCql({
|
||||
where: BillingSubscriptions.where.in('provider_id', 'provider_ids'),
|
||||
});
|
||||
const ACTIVE_SUBSCRIPTION_STATUSES = new Set<BillingSubscriptionRow['status']>(['active', 'trialing']);
|
||||
|
||||
function getSubscriptionEndMs(row: BillingSubscriptionRow): number {
|
||||
return row.current_period_end?.getTime() ?? 0;
|
||||
}
|
||||
|
||||
export class BillingSubscriptionRepository {
|
||||
async findById(providerId: string): Promise<BillingSubscriptionRow | null> {
|
||||
@@ -62,15 +57,6 @@ export class BillingSubscriptionRepository {
|
||||
return rows.map(normalizeBillingSubscriptionRow);
|
||||
}
|
||||
|
||||
async findActiveForUser(userId: bigint): Promise<BillingSubscriptionRow | null> {
|
||||
const subs = await this.listByUser(userId);
|
||||
return (
|
||||
subs
|
||||
.filter((subscription) => ACTIVE_SUBSCRIPTION_STATUSES.has(subscription.status))
|
||||
.sort((left, right) => getSubscriptionEndMs(right) - getSubscriptionEndMs(left))[0] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
async upsertFromStripe(
|
||||
s: StripeSubscriptionPayload,
|
||||
hints?: MapStripeSubscriptionHints,
|
||||
|
||||
Reference in new issue
Block a user