45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
// eslint-disable-next-line import/no-named-as-default
|
|
import Decimal from "decimal.js";
|
|
import { Column, Entity, JoinTable, ManyToMany } from "typeorm";
|
|
|
|
import { BaseEntity } from "../../../common/entities/base.entity";
|
|
import { DecimalTransformer } from "../../../common/transformers/decimal.transformer";
|
|
import { SubscriptionPlan } from "../../subscriptions/entities/subscription.entity";
|
|
import { User } from "../../users/entities/user.entity";
|
|
import { DiscountCalculationType, DiscountType } from "../enums/discount-type.enum";
|
|
|
|
@Entity()
|
|
export class Discount extends BaseEntity {
|
|
@Column({ type: "varchar", length: 200, nullable: false })
|
|
title: string;
|
|
|
|
@Column({ type: "enum", enum: DiscountType })
|
|
type: DiscountType;
|
|
|
|
@Column({ type: "enum", enum: DiscountCalculationType })
|
|
calculationType: DiscountCalculationType;
|
|
|
|
@Column({ type: "decimal", precision: 10, scale: 2, nullable: false, transformer: new DecimalTransformer() })
|
|
amount: Decimal;
|
|
|
|
@Column({ type: "boolean", default: true })
|
|
isActive: boolean;
|
|
|
|
@Column({ nullable: true })
|
|
code?: string;
|
|
|
|
@Column({ type: "timestamptz" })
|
|
startDate: Date;
|
|
|
|
@Column({ type: "timestamptz" })
|
|
endDate: Date;
|
|
|
|
@ManyToMany(() => SubscriptionPlan, (subscriptionPlan) => subscriptionPlan.discounts, { nullable: true })
|
|
@JoinTable()
|
|
subscriptionPlans: SubscriptionPlan[];
|
|
|
|
@ManyToMany(() => User, (user) => user.discounts, { nullable: true })
|
|
@JoinTable()
|
|
users: User[];
|
|
}
|