40 lines
1.5 KiB
TypeScript
Executable File
40 lines
1.5 KiB
TypeScript
Executable File
import Decimal from "decimal.js";
|
|
import { Column, DeleteDateColumn, Entity, Index, ManyToOne, OneToMany } from "typeorm";
|
|
|
|
import { UserSubscription } from "./user-subscription.entity";
|
|
import { BaseEntity } from "../../../common/entities/base.entity";
|
|
import { DecimalTransformer } from "../../../common/transformers/decimal.transformer";
|
|
import { DanakService } from "../../danak-services/entities/danak-service.entity";
|
|
import { Discount } from "../../discounts/entities/discount.entity";
|
|
|
|
@Entity()
|
|
@Index(["service", "name"], { unique: true })
|
|
export class SubscriptionPlan extends BaseEntity {
|
|
@Column({ type: "varchar", length: 150, nullable: false })
|
|
name: string;
|
|
|
|
@Column({ type: "int", nullable: false })
|
|
duration: number;
|
|
|
|
@Column({ type: "decimal", precision: 16, scale: 2, nullable: false, transformer: new DecimalTransformer() })
|
|
price: Decimal;
|
|
|
|
@Column({ type: "decimal", precision: 16, scale: 2, nullable: false, transformer: new DecimalTransformer() })
|
|
originalPrice: Decimal;
|
|
|
|
@Column({ type: "boolean", default: true })
|
|
isActive: boolean;
|
|
|
|
@ManyToOne(() => DanakService, (danakService) => danakService.subscriptionPlans, { nullable: false, onDelete: "CASCADE" })
|
|
service: DanakService;
|
|
|
|
@OneToMany(() => UserSubscription, (userSubscription) => userSubscription.plan)
|
|
userSubscriptions: UserSubscription[];
|
|
|
|
@ManyToOne(() => Discount, (discount) => discount.subscriptionPlans, { nullable: true, onUpdate: "CASCADE" })
|
|
directDiscount: Discount | null;
|
|
|
|
@DeleteDateColumn({ nullable: true })
|
|
deletedAt?: Date;
|
|
}
|