45 create billing core tables (#4096)
* Add self billing feature flag * Add two core tables for billing * Remove useless imports * Remove graphql decorators * Rename subscriptionProduct table
This commit is contained in:
@ -0,0 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
})
|
||||
export class BillingModule {}
|
||||
@ -0,0 +1,46 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import { BillingSubscription } from 'src/core/billing/entities/billing-subscription.entity';
|
||||
|
||||
@Entity({ name: 'billingSubscriptionItem', schema: 'core' })
|
||||
export class BillingSubscriptionItem {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
deletedAt?: Date;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamp with time zone' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ type: 'timestamp with time zone' })
|
||||
updatedAt: Date;
|
||||
|
||||
@Column({ nullable: false })
|
||||
billingSubscriptionId: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => BillingSubscription,
|
||||
(billingSubscription) => billingSubscription.billingSubscriptionItems,
|
||||
{
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
)
|
||||
billingSubscription: BillingSubscription;
|
||||
|
||||
@Column({ nullable: false })
|
||||
stripeProductId: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
stripePriceId: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
quantity: number;
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import Stripe from 'stripe';
|
||||
|
||||
import { Workspace } from 'src/core/workspace/workspace.entity';
|
||||
import { BillingSubscriptionItem } from 'src/core/billing/entities/billing-subscription-item.entity';
|
||||
|
||||
@Entity({ name: 'billingSubscription', schema: 'core' })
|
||||
export class BillingSubscription {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
deletedAt?: Date;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamp with time zone' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ type: 'timestamp with time zone' })
|
||||
updatedAt: Date;
|
||||
|
||||
@OneToOne(() => Workspace, (workspace) => workspace.billingSubscription, {
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@JoinColumn()
|
||||
workspace: Workspace;
|
||||
|
||||
@Column({ nullable: false, type: 'uuid' })
|
||||
workspaceId: string;
|
||||
|
||||
@Column({ unique: true, nullable: false })
|
||||
stripeCustomerId: string;
|
||||
|
||||
@Column({ unique: true, nullable: false })
|
||||
stripeSubscriptionId: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
status: Stripe.Subscription.Status;
|
||||
|
||||
@OneToMany(
|
||||
() => BillingSubscriptionItem,
|
||||
(billingSubscriptionItem) => billingSubscriptionItem.billingSubscription,
|
||||
)
|
||||
billingSubscriptionItems: BillingSubscriptionItem[];
|
||||
}
|
||||
@ -8,6 +8,7 @@ import { ApiRestModule } from 'src/core/api-rest/api-rest.module';
|
||||
import { FeatureFlagModule } from 'src/core/feature-flag/feature-flag.module';
|
||||
import { OpenApiModule } from 'src/core/open-api/open-api.module';
|
||||
import { TimelineMessagingModule } from 'src/core/messaging/timeline-messaging.module';
|
||||
import { BillingModule } from 'src/core/billing/billing.module';
|
||||
|
||||
import { AnalyticsModule } from './analytics/analytics.module';
|
||||
import { FileModule } from './file/file.module';
|
||||
@ -15,25 +16,26 @@ import { ClientConfigModule } from './client-config/client-config.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
AuthModule,
|
||||
WorkspaceModule,
|
||||
UserModule,
|
||||
RefreshTokenModule,
|
||||
AnalyticsModule,
|
||||
FileModule,
|
||||
ClientConfigModule,
|
||||
ApiRestModule,
|
||||
OpenApiModule,
|
||||
AuthModule,
|
||||
BillingModule,
|
||||
ClientConfigModule,
|
||||
FeatureFlagModule,
|
||||
FileModule,
|
||||
OpenApiModule,
|
||||
RefreshTokenModule,
|
||||
TimelineMessagingModule,
|
||||
UserModule,
|
||||
WorkspaceModule,
|
||||
],
|
||||
exports: [
|
||||
AuthModule,
|
||||
WorkspaceModule,
|
||||
UserModule,
|
||||
AnalyticsModule,
|
||||
AuthModule,
|
||||
FeatureFlagModule,
|
||||
TimelineMessagingModule,
|
||||
UserModule,
|
||||
WorkspaceModule,
|
||||
],
|
||||
})
|
||||
export class CoreModule {}
|
||||
|
||||
@ -18,6 +18,7 @@ export enum FeatureFlagKeys {
|
||||
IsCalendarEnabled = 'IS_CALENDAR_ENABLED',
|
||||
IsMessagingEnabled = 'IS_MESSAGING_ENABLED',
|
||||
IsNewRecordBoardEnabled = 'IS_NEW_RECORD_BOARD_ENABLED',
|
||||
IsSelfBillingEnabled = 'IS_SELF_BILLING_ENABLED',
|
||||
IsWorkspaceCleanable = 'IS_WORKSPACE_CLEANABLE',
|
||||
}
|
||||
|
||||
|
||||
@ -6,12 +6,14 @@ import {
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import { User } from 'src/core/user/user.entity';
|
||||
import { FeatureFlagEntity } from 'src/core/feature-flag/feature-flag.entity';
|
||||
import { BillingSubscription } from 'src/core/billing/entities/billing-subscription.entity';
|
||||
|
||||
@Entity({ name: 'workspace', schema: 'core' })
|
||||
@ObjectType('Workspace')
|
||||
@ -65,4 +67,10 @@ export class Workspace {
|
||||
|
||||
@Field()
|
||||
activationStatus: 'active' | 'inactive';
|
||||
|
||||
@OneToOne(
|
||||
() => BillingSubscription,
|
||||
(billingSubscription) => billingSubscription.workspace,
|
||||
)
|
||||
billingSubscription: BillingSubscription;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user