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
|
* Create a new subscription
|
||||||
*/
|
*/
|
||||||
async create(data: CreateSubscriptionRequest & { stripeCustomerId: string }): Promise<Subscription> {
|
async create(data: CreateSubscriptionRequest & { stripeCustomerId?: string | null }): Promise<Subscription> {
|
||||||
const query = `
|
const query = `
|
||||||
INSERT INTO subscriptions (
|
INSERT INTO subscriptions (
|
||||||
user_id, stripe_customer_id, tier, billing_cycle
|
user_id, stripe_customer_id, tier, billing_cycle
|
||||||
@@ -38,7 +38,7 @@ export class SubscriptionsRepository {
|
|||||||
|
|
||||||
const values = [
|
const values = [
|
||||||
data.userId,
|
data.userId,
|
||||||
data.stripeCustomerId,
|
data.stripeCustomerId ?? null,
|
||||||
data.tier,
|
data.tier,
|
||||||
data.billingCycle,
|
data.billingCycle,
|
||||||
];
|
];
|
||||||
@@ -579,18 +579,16 @@ export class SubscriptionsRepository {
|
|||||||
client?: any
|
client?: any
|
||||||
): Promise<Subscription> {
|
): Promise<Subscription> {
|
||||||
const queryClient = client || this.pool;
|
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 = `
|
const query = `
|
||||||
INSERT INTO subscriptions (
|
INSERT INTO subscriptions (
|
||||||
user_id, stripe_customer_id, tier, billing_cycle, status
|
user_id, stripe_customer_id, tier, billing_cycle, status
|
||||||
)
|
)
|
||||||
VALUES ($1, $2, $3, 'monthly', 'active')
|
VALUES ($1, NULL, $2, 'monthly', 'active')
|
||||||
RETURNING *
|
RETURNING *
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const values = [userId, placeholderCustomerId, tier];
|
const values = [userId, tier];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await queryClient.query(query, values);
|
const result = await queryClient.query(query, values);
|
||||||
@@ -623,7 +621,7 @@ export class SubscriptionsRepository {
|
|||||||
return {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
userId: row.user_id,
|
userId: row.user_id,
|
||||||
stripeCustomerId: row.stripe_customer_id,
|
stripeCustomerId: row.stripe_customer_id ?? null,
|
||||||
stripeSubscriptionId: row.stripe_subscription_id || undefined,
|
stripeSubscriptionId: row.stripe_subscription_id || undefined,
|
||||||
tier: row.tier,
|
tier: row.tier,
|
||||||
billingCycle: row.billing_cycle || undefined,
|
billingCycle: row.billing_cycle || undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user