56 lines
1.9 KiB
TypeScript
Executable File
56 lines
1.9 KiB
TypeScript
Executable File
import { Column, DeleteDateColumn, Entity, ManyToOne, OneToMany } from "typeorm";
|
|
|
|
import { UsageDiscount } from "./usage-discount.entity";
|
|
import { BaseEntity } from "../../../common/entities/base.entity";
|
|
import { DecimalTransformer } from "../../../common/transformers/decimal.transformer";
|
|
import { Invoice } from "../../invoices/entities/invoice.entity";
|
|
import { SubscriptionPlan } from "../../subscriptions/entities/subscription.entity";
|
|
import { User } from "../../users/entities/user.entity";
|
|
import { DiscountApplicationType } from "../enums/discount-application-type.enum";
|
|
import { DiscountType } from "../enums/discount-type.enum";
|
|
|
|
@Entity()
|
|
export class Discount extends BaseEntity {
|
|
@Column({ type: "varchar", length: 150 })
|
|
title: string;
|
|
|
|
@Column({ type: "enum", enum: DiscountApplicationType })
|
|
applicationType: DiscountApplicationType;
|
|
|
|
@Column({ type: "varchar", length: 100, unique: true, nullable: true })
|
|
code?: string;
|
|
|
|
@Column({ type: "enum", enum: DiscountType, default: DiscountType.PERCENTAGE })
|
|
type: DiscountType;
|
|
|
|
@Column({ type: "decimal", precision: 16, scale: 2, transformer: new DecimalTransformer() })
|
|
value: number;
|
|
|
|
@Column({ type: "timestamptz" })
|
|
startDate: Date;
|
|
|
|
@Column({ type: "timestamptz" })
|
|
endDate: Date;
|
|
|
|
@Column({ type: "int", default: 0 })
|
|
usedCount: number;
|
|
|
|
@Column({ type: "boolean", default: true })
|
|
isActive: boolean;
|
|
|
|
@DeleteDateColumn({ nullable: true })
|
|
deletedAt?: Date;
|
|
|
|
@ManyToOne(() => User, (user) => user.discounts, { nullable: true })
|
|
user?: User | null;
|
|
|
|
@OneToMany(() => UsageDiscount, (usageDiscount) => usageDiscount.discount)
|
|
usages: UsageDiscount[];
|
|
|
|
@OneToMany(() => SubscriptionPlan, (subscriptionPlan) => subscriptionPlan.directDiscount, { cascade: ["update"] })
|
|
subscriptionPlans: SubscriptionPlan[];
|
|
|
|
@OneToMany(() => Invoice, (invoice) => invoice.discount)
|
|
invoices: Invoice[];
|
|
}
|