feat: is trailing
This commit is contained in:
parent
74b46a1660
commit
1783da607c
|
|
@ -66,6 +66,7 @@ export class UsersController {
|
|||
isLifetime: !!organization?.subscription?.isLifetime,
|
||||
admin: !!user.isSuperAdmin,
|
||||
impersonate: !!impersonate,
|
||||
isTrailing: !process.env.STRIPE_PUBLISHABLE_KEY ? false : organization?.isTrailing,
|
||||
allowTrial: organization?.allowTrial,
|
||||
// @ts-ignore
|
||||
publicApi: organization?.users[0]?.role === 'SUPERADMIN' || organization?.users[0]?.role === 'ADMIN' ? organization?.apiKey : '',
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ model Organization {
|
|||
post Post[] @relation("organization")
|
||||
submittedPost Post[] @relation("submittedForOrg")
|
||||
allowTrial Boolean @default(false)
|
||||
isTrailing Boolean @default(false)
|
||||
Comments Comments[]
|
||||
notifications Notifications[]
|
||||
buyerOrganization MessagesGroup[]
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ export class SubscriptionRepository {
|
|||
}
|
||||
|
||||
async createOrUpdateSubscription(
|
||||
isTrailing: boolean,
|
||||
identifier: string,
|
||||
customerId: string,
|
||||
totalChannels: number,
|
||||
|
|
@ -178,6 +179,7 @@ export class SubscriptionRepository {
|
|||
id: findOrg.id,
|
||||
},
|
||||
data: {
|
||||
isTrailing,
|
||||
allowTrial: false,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -150,6 +150,7 @@ export class SubscriptionService {
|
|||
}
|
||||
|
||||
async createOrUpdateSubscription(
|
||||
isTrailing: boolean,
|
||||
identifier: string,
|
||||
customerId: string,
|
||||
totalChannels: number,
|
||||
|
|
@ -174,6 +175,7 @@ export class SubscriptionService {
|
|||
}
|
||||
}
|
||||
return this._subscriptionRepository.createOrUpdateSubscription(
|
||||
isTrailing,
|
||||
identifier,
|
||||
customerId,
|
||||
totalChannels,
|
||||
|
|
@ -219,6 +221,7 @@ export class SubscriptionService {
|
|||
|
||||
async lifeTime(orgId: string, identifier: string, subscription: any) {
|
||||
return this.createOrUpdateSubscription(
|
||||
false,
|
||||
identifier,
|
||||
identifier,
|
||||
pricing[subscription].channel!,
|
||||
|
|
@ -233,6 +236,7 @@ export class SubscriptionService {
|
|||
async addSubscription(orgId: string, userId: string, subscription: any) {
|
||||
await this._subscriptionRepository.setCustomerId(orgId, userId);
|
||||
return this.createOrUpdateSubscription(
|
||||
false,
|
||||
makeId(5),
|
||||
userId,
|
||||
pricing[subscription].channel!,
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ export class StripeService {
|
|||
}
|
||||
|
||||
return this._subscriptionService.createOrUpdateSubscription(
|
||||
event.data.object.status === 'trialing',
|
||||
uniqueId,
|
||||
event.data.object.customer as string,
|
||||
pricing[billing].channel!,
|
||||
|
|
@ -168,12 +169,13 @@ export class StripeService {
|
|||
}
|
||||
|
||||
return this._subscriptionService.createOrUpdateSubscription(
|
||||
event.data.object.status === 'trialing',
|
||||
uniqueId,
|
||||
event.data.object.customer as string,
|
||||
pricing[billing].channel!,
|
||||
billing,
|
||||
period,
|
||||
event.data.object.cancel_at
|
||||
event.data.object.cancel_at,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -729,6 +731,7 @@ export class StripeService {
|
|||
const findPricing = pricing[nextPackage];
|
||||
|
||||
await this._subscriptionService.createOrUpdateSubscription(
|
||||
false,
|
||||
makeId(10),
|
||||
organizationId,
|
||||
getCurrentSubscription?.subscriptionTier === 'PRO'
|
||||
|
|
|
|||
Loading…
Reference in New Issue