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[];
|
||||
}
|
||||
Reference in New Issue
Block a user