chore(server): remove old subscription table usage (#9928)
This commit is contained in:
@@ -227,23 +227,6 @@ export class UserSubscriptionManager extends SubscriptionManager {
|
|||||||
|
|
||||||
const subscriptionData = this.transformSubscription(subscription);
|
const subscriptionData = this.transformSubscription(subscription);
|
||||||
|
|
||||||
// @deprecated backward compatibility
|
|
||||||
await this.db.deprecatedUserSubscription.upsert({
|
|
||||||
where: {
|
|
||||||
stripeSubscriptionId: stripeSubscription.id,
|
|
||||||
},
|
|
||||||
update: pick(subscriptionData, [
|
|
||||||
'status',
|
|
||||||
'stripeScheduleId',
|
|
||||||
'nextBillAt',
|
|
||||||
'canceledAt',
|
|
||||||
]),
|
|
||||||
create: {
|
|
||||||
userId,
|
|
||||||
...omit(subscriptionData, 'quantity'),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.db.subscription.upsert({
|
return this.db.subscription.upsert({
|
||||||
where: {
|
where: {
|
||||||
stripeSubscriptionId: stripeSubscription.id,
|
stripeSubscriptionId: stripeSubscription.id,
|
||||||
@@ -274,13 +257,6 @@ export class UserSubscriptionManager extends SubscriptionManager {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// @deprecated backward compatibility
|
|
||||||
await this.db.deprecatedUserSubscription.deleteMany({
|
|
||||||
where: {
|
|
||||||
stripeSubscriptionId: stripeSubscription.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (deleted.count > 0) {
|
if (deleted.count > 0) {
|
||||||
this.event.emit('user.subscription.canceled', {
|
this.event.emit('user.subscription.canceled', {
|
||||||
userId,
|
userId,
|
||||||
@@ -291,17 +267,6 @@ export class UserSubscriptionManager extends SubscriptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async cancelSubscription(subscription: Subscription) {
|
async cancelSubscription(subscription: Subscription) {
|
||||||
// @deprecated backward compatibility
|
|
||||||
await this.db.deprecatedUserSubscription.updateMany({
|
|
||||||
where: {
|
|
||||||
stripeSubscriptionId: subscription.stripeSubscriptionId,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
canceledAt: new Date(),
|
|
||||||
nextBillAt: null,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.db.subscription.update({
|
return this.db.subscription.update({
|
||||||
where: {
|
where: {
|
||||||
// @ts-expect-error checked outside
|
// @ts-expect-error checked outside
|
||||||
@@ -315,17 +280,6 @@ export class UserSubscriptionManager extends SubscriptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async resumeSubscription(subscription: Subscription) {
|
async resumeSubscription(subscription: Subscription) {
|
||||||
// @deprecated backward compatibility
|
|
||||||
await this.db.deprecatedUserSubscription.updateMany({
|
|
||||||
where: {
|
|
||||||
stripeSubscriptionId: subscription.stripeSubscriptionId,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
canceledAt: null,
|
|
||||||
nextBillAt: subscription.end,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.db.subscription.update({
|
return this.db.subscription.update({
|
||||||
where: {
|
where: {
|
||||||
// @ts-expect-error checked outside
|
// @ts-expect-error checked outside
|
||||||
@@ -342,14 +296,6 @@ export class UserSubscriptionManager extends SubscriptionManager {
|
|||||||
subscription: Subscription,
|
subscription: Subscription,
|
||||||
recurring: SubscriptionRecurring
|
recurring: SubscriptionRecurring
|
||||||
) {
|
) {
|
||||||
// @deprecated backward compatibility
|
|
||||||
await this.db.deprecatedUserSubscription.updateMany({
|
|
||||||
where: {
|
|
||||||
stripeSubscriptionId: subscription.stripeSubscriptionId,
|
|
||||||
},
|
|
||||||
data: { recurring },
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.db.subscription.update({
|
return this.db.subscription.update({
|
||||||
where: {
|
where: {
|
||||||
// @ts-expect-error checked outside
|
// @ts-expect-error checked outside
|
||||||
@@ -396,18 +342,6 @@ export class UserSubscriptionManager extends SubscriptionManager {
|
|||||||
|
|
||||||
const invoiceData = await this.transformInvoice(knownInvoice);
|
const invoiceData = await this.transformInvoice(knownInvoice);
|
||||||
|
|
||||||
// @deprecated backward compatibility
|
|
||||||
await this.db.deprecatedUserInvoice.upsert({
|
|
||||||
where: {
|
|
||||||
stripeInvoiceId: stripeInvoice.id,
|
|
||||||
},
|
|
||||||
update: omit(invoiceData, 'stripeInvoiceId'),
|
|
||||||
create: {
|
|
||||||
userId,
|
|
||||||
...invoiceData,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const invoice = await this.db.invoice.upsert({
|
const invoice = await this.db.invoice.upsert({
|
||||||
where: {
|
where: {
|
||||||
stripeInvoiceId: stripeInvoice.id,
|
stripeInvoiceId: stripeInvoice.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user