chore: add discount logic to apply to the plan price and ...

This commit is contained in:
mahyargdz
2025-04-19 12:36:33 +03:30
parent f9e44fc29a
commit bf3402cc7a
8 changed files with 144 additions and 20 deletions
@@ -20,6 +20,9 @@ export class Invoice extends BaseEntity {
@Column({ type: "decimal", precision: 16, scale: 2, nullable: false, transformer: new DecimalTransformer() })
totalPrice: Decimal;
@Column({ type: "decimal", precision: 16, scale: 2, nullable: true, transformer: new DecimalTransformer() })
originalPrice?: Decimal;
@Column({ type: "enum", enum: InvoiceStatus, default: InvoiceStatus.PENDING })
status: InvoiceStatus;
@@ -40,8 +43,8 @@ export class Invoice extends BaseEntity {
@OneToMany(() => InvoiceItem, (invoiceItem) => invoiceItem.invoice, { cascade: true })
items: InvoiceItem[];
@ManyToOne(() => Discount, { nullable: true, onDelete: "SET NULL" })
discount: Discount;
@ManyToOne(() => Discount, (discount) => discount.invoices, { nullable: true, onDelete: "RESTRICT" })
discount?: Discount;
get isOverdue(): boolean {
return this.status === InvoiceStatus.PENDING && new Date() > this.dueDate;