import { Model, Table, Column, ForeignKey, BelongsTo, DataType } from "sequelize-typescript"; import { User } from "../../users/entities/user.entity"; import { Product } from "../../shop/entities/product.entity"; import { Invoice } from "./invoice.entity"; @Table export class Cart extends Model<Cart> { @ForeignKey(() => User) @Column userId: number; @BelongsTo(() => User, { onDelete: "CASCADE" }) user: User; @ForeignKey(() => Product) @Column productId: number; @BelongsTo(() => Product, { onDelete: "CASCADE" }) product: Product; @ForeignKey(() => Invoice) @Column invoiceId: number; @BelongsTo(() => Invoice, { onDelete: "CASCADE" }) invoice: Invoice; @Column({ type: DataType.INTEGER, allowNull: true, }) quantity: number; @Column({ type: DataType.INTEGER, allowNull: true, }) productPrice: number; @Column({ type: DataType.ENUM("open", "closed"), allowNull: false, defaultValue: "open", }) status: "open" | "closed"; }