Refactor ProjectService to update subscription status

This commit is contained in:
Simon Larsen 2024-09-11 16:02:52 -07:00
parent 956ac101a2
commit 1d85490c55
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA

View File

@ -347,6 +347,17 @@ export class ProjectService extends DatabaseService<Model> {
" completed.",
);
// refresh subscription status.
const subscriptionState: SubscriptionStatus =
await BillingService.getSubscriptionStatus(
subscription.subscriptionId as string,
);
const meteredSubscriptionState: SubscriptionStatus =
await BillingService.getSubscriptionStatus(
subscription.meteredSubscriptionId as string,
);
await this.updateOneById({
id: new ObjectID(updateBy.query._id! as string),
data: {
@ -357,6 +368,9 @@ export class ProjectService extends DatabaseService<Model> {
planName: SubscriptionPlan.getPlanType(
updateBy.data.paymentProviderPlanId! as string,
),
paymentProviderMeteredSubscriptionStatus:
meteredSubscriptionState,
paymentProviderSubscriptionStatus: subscriptionState,
},
props: {
isRoot: true,