import Decimal from "decimal.js"; import { Column, Entity, ManyToOne } from "typeorm"; import { Invoice } from "./invoice.entity"; import { BaseEntity } from "../../../common/entities/base.entity"; import { DecimalTransformer } from "../../../common/transformers/decimal.transformer"; import { UserSubscription } from "../../subscriptions/entities/user-subscription.entity"; @Entity() export class InvoiceItem extends BaseEntity { @ManyToOne(() => Invoice, (invoice) => invoice.items, { onDelete: "CASCADE" }) invoice: Invoice; @Column({ type: "varchar", length: 150, nullable: false }) name: string; @Column({ type: "int", nullable: false }) count: number; @Column({ type: "decimal", precision: 16, scale: 2, nullable: false, transformer: new DecimalTransformer() }) discount: Decimal; @Column({ type: "decimal", precision: 16, scale: 2, nullable: false, transformer: new DecimalTransformer() }) unitPrice: Decimal; @Column({ type: "decimal", precision: 16, scale: 2, nullable: false, transformer: new DecimalTransformer() }) totalPrice: Decimal; @ManyToOne(() => UserSubscription, { nullable: true, onDelete: "RESTRICT" }) subscriptionPlan: UserSubscription | null; }