-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
184 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { NestjsQueryGraphQLModule } from '@ptc-org/nestjs-query-graphql'; | ||
import { NestjsQueryTypeOrmModule } from '@ptc-org/nestjs-query-typeorm'; | ||
|
||
import { BillingSubscription } from 'src/core/billing/entities/billing-subscription.entity'; | ||
import { BillingProduct } from 'src/core/billing/entities/billing-product.entity'; | ||
|
||
@Module({ | ||
imports: [ | ||
NestjsQueryGraphQLModule.forFeature({ | ||
imports: [ | ||
NestjsQueryTypeOrmModule.forFeature( | ||
[BillingSubscription, BillingProduct], | ||
'core', | ||
), | ||
], | ||
}), | ||
], | ||
}) | ||
export class BillingModule {} |
39 changes: 39 additions & 0 deletions
39
packages/twenty-server/src/core/billing/entities/billing-product.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Field, ID, ObjectType } from '@nestjs/graphql'; | ||
|
||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; | ||
import { IDField } from '@ptc-org/nestjs-query-graphql'; | ||
|
||
import { BillingSubscription } from 'src/core/billing/entities/billing-subscription.entity'; | ||
|
||
@Entity({ name: 'billingProduct', schema: 'core' }) | ||
@ObjectType('BillingProduct') | ||
export class BillingProduct { | ||
@IDField(() => ID) | ||
@PrimaryGeneratedColumn('uuid') | ||
id: string; | ||
|
||
@Field() | ||
@Column({ nullable: false }) | ||
billingSubscriptionId: string; | ||
|
||
@ManyToOne( | ||
() => BillingSubscription, | ||
(billingSubscription) => billingSubscription.billingProducts, | ||
{ | ||
onDelete: 'CASCADE', | ||
}, | ||
) | ||
billingSubscription: BillingSubscription; | ||
|
||
@Field() | ||
@Column({ nullable: false }) | ||
stripeProductId: string; | ||
|
||
@Field() | ||
@Column({ nullable: false }) | ||
stripePriceId: string; | ||
|
||
@Field() | ||
@Column({ nullable: false }) | ||
quantity: number; | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/twenty-server/src/core/billing/entities/billing-subscription.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Field, ID, ObjectType } from '@nestjs/graphql'; | ||
|
||
import { | ||
Column, | ||
Entity, | ||
JoinColumn, | ||
OneToMany, | ||
OneToOne, | ||
PrimaryGeneratedColumn, | ||
} from 'typeorm'; | ||
import { IDField } from '@ptc-org/nestjs-query-graphql'; | ||
import Stripe from 'stripe'; | ||
|
||
import { Workspace } from 'src/core/workspace/workspace.entity'; | ||
import { BillingProduct } from 'src/core/billing/entities/billing-product.entity'; | ||
|
||
@Entity({ name: 'billingSubscription', schema: 'core' }) | ||
@ObjectType('BillingSubscription') | ||
export class BillingSubscription { | ||
@IDField(() => ID) | ||
@PrimaryGeneratedColumn('uuid') | ||
id: string; | ||
|
||
@OneToOne(() => Workspace, (workspace) => workspace.billingSubscription, { | ||
onDelete: 'CASCADE', | ||
}) | ||
@JoinColumn() | ||
workspace: Workspace; | ||
|
||
@Field() | ||
@Column({ nullable: false, type: 'uuid' }) | ||
workspaceId: string; | ||
|
||
@Field() | ||
@Column({ unique: true, nullable: false }) | ||
stripeCustomerId: string; | ||
|
||
@Field() | ||
@Column({ unique: true, nullable: false }) | ||
stripeSubscriptionId: string; | ||
|
||
@Field() | ||
@Column({ nullable: false }) | ||
status: Stripe.Subscription.Status; | ||
|
||
@OneToMany( | ||
() => BillingProduct, | ||
(billingProduct) => billingProduct.billingSubscription, | ||
) | ||
billingProducts: BillingProduct[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../twenty-server/src/database/typeorm/core/migrations/1708531440013-addBillingCoreTables.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class AddBillingCoreTables1708531440013 implements MigrationInterface { | ||
name = 'AddBillingCoreTables1708531440013' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`CREATE TABLE "core"."billingProduct" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "billingSubscriptionId" uuid NOT NULL, "stripeProductId" character varying NOT NULL, "stripePriceId" character varying NOT NULL, "quantity" integer NOT NULL, CONSTRAINT "PK_8bb3c7be66db8e05476808b0ca7" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`CREATE TABLE "core"."billingSubscription" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "workspaceId" uuid NOT NULL, "stripeCustomerId" character varying NOT NULL, "stripeSubscriptionId" character varying NOT NULL, "status" character varying NOT NULL, CONSTRAINT "UQ_9120b7586c3471463480b58d20a" UNIQUE ("stripeCustomerId"), CONSTRAINT "UQ_1a858c28c7766d429cbd25f05e8" UNIQUE ("stripeSubscriptionId"), CONSTRAINT "REL_4abfb70314c18da69e1bee1954" UNIQUE ("workspaceId"), CONSTRAINT "PK_6e9c72c32d91640b8087cb53666" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`ALTER TABLE "core"."billingProduct" ADD CONSTRAINT "FK_8362bf28155ad6651243ce00317" FOREIGN KEY ("billingSubscriptionId") REFERENCES "core"."billingSubscription"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); | ||
await queryRunner.query(`ALTER TABLE "core"."billingSubscription" ADD CONSTRAINT "FK_4abfb70314c18da69e1bee1954d" FOREIGN KEY ("workspaceId") REFERENCES "core"."workspace"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "core"."billingSubscription" DROP CONSTRAINT "FK_4abfb70314c18da69e1bee1954d"`); | ||
await queryRunner.query(`ALTER TABLE "core"."billingProduct" DROP CONSTRAINT "FK_8362bf28155ad6651243ce00317"`); | ||
await queryRunner.query(`DROP TABLE "core"."billingSubscription"`); | ||
await queryRunner.query(`DROP TABLE "core"."billingProduct"`); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters