refactor: update repository for nullable stripe_customer_id (refs #208)
Remove admin_override_ placeholder from createForAdminOverride(), use NULL. Update mapSubscriptionRow() with ?? null. Make stripeCustomerId optional in create() method. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,7 @@ export class SubscriptionsRepository {
|
||||
/**
|
||||
* Create a new subscription
|
||||
*/
|
||||
async create(data: CreateSubscriptionRequest & { stripeCustomerId: string }): Promise<Subscription> {
|
||||
async create(data: CreateSubscriptionRequest & { stripeCustomerId?: string | null }): Promise<Subscription> {
|
||||
const query = `
|
||||
INSERT INTO subscriptions (
|
||||
user_id, stripe_customer_id, tier, billing_cycle
|
||||
@@ -38,7 +38,7 @@ export class SubscriptionsRepository {
|
||||
|
||||
const values = [
|
||||
data.userId,
|
||||
data.stripeCustomerId,
|
||||
data.stripeCustomerId ?? null,
|
||||
data.tier,
|
||||
data.billingCycle,
|
||||
];
|
||||
@@ -579,18 +579,16 @@ export class SubscriptionsRepository {
|
||||
client?: any
|
||||
): Promise<Subscription> {
|
||||
const queryClient = client || this.pool;
|
||||
// Generate a placeholder Stripe customer ID since admin override bypasses Stripe
|
||||
const placeholderCustomerId = `admin_override_${userId}_${Date.now()}`;
|
||||
|
||||
const query = `
|
||||
INSERT INTO subscriptions (
|
||||
user_id, stripe_customer_id, tier, billing_cycle, status
|
||||
)
|
||||
VALUES ($1, $2, $3, 'monthly', 'active')
|
||||
VALUES ($1, NULL, $2, 'monthly', 'active')
|
||||
RETURNING *
|
||||
`;
|
||||
|
||||
const values = [userId, placeholderCustomerId, tier];
|
||||
const values = [userId, tier];
|
||||
|
||||
try {
|
||||
const result = await queryClient.query(query, values);
|
||||
@@ -623,7 +621,7 @@ export class SubscriptionsRepository {
|
||||
return {
|
||||
id: row.id,
|
||||
userId: row.user_id,
|
||||
stripeCustomerId: row.stripe_customer_id,
|
||||
stripeCustomerId: row.stripe_customer_id ?? null,
|
||||
stripeSubscriptionId: row.stripe_subscription_id || undefined,
|
||||
tier: row.tier,
|
||||
billingCycle: row.billing_cycle || undefined,
|
||||
|
||||
Reference in New Issue
Block a user