chore: add invoice and subscription entities

This commit is contained in:
mahyargdz
2025-02-08 15:27:32 +03:30
parent ffa2a2a806
commit e4f201bea2
16 changed files with 181 additions and 10 deletions
@@ -0,0 +1,22 @@
import { Column, Entity, ManyToOne } from "typeorm";
import { BaseEntity } from "../../../common/entities/base.entity";
import { DanakService } from "../../danak-services/entities/danak-service.entity";
@Entity()
export class SubscriptionPlan extends BaseEntity {
@Column({ type: "varchar", length: 100, nullable: false })
name: string;
@Column({ type: "int", nullable: false })
duration: number;
@Column({ type: "decimal", precision: 10, scale: 2, nullable: false })
price: number;
@Column({ type: "boolean", default: true })
isActive: boolean;
@ManyToOne(() => DanakService, (danakService) => danakService.subscriptionPlans, { nullable: false, onDelete: "CASCADE" })
service: DanakService;
}
@@ -0,0 +1,23 @@
import { Column, Entity, ManyToOne } from "typeorm";
import { SubscriptionPlan } from "./subscription.entity";
import { BaseEntity } from "../../../common/entities/base.entity";
import { User } from "../../users/entities/user.entity";
@Entity()
export class UserSubscription extends BaseEntity {
@ManyToOne(() => User, (user) => user.subscriptions, { nullable: false, onDelete: "CASCADE" })
user: User;
@ManyToOne(() => SubscriptionPlan, { nullable: false, onDelete: "CASCADE" })
plan: SubscriptionPlan;
@Column({ type: "timestamp", nullable: false }) // When the subscription started
startDate: Date;
@Column({ type: "timestamp", nullable: false }) // When it expires
endDate: Date;
@Column({ type: "boolean", default: false }) // Whether the user canceled it
isCanceled: boolean;
}