import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, PrimaryGeneratedColumn, } from "typeorm"; import { DiscountCodeUserProduct, Gallery, Partner, ProductDate, ProductImage, ProductSchedule, } from ".."; import { jsonTransformer } from "../transformers/jsonTransformer"; import { Category } from "./Category"; import { ProductGroup } from "./ProductGroup"; import { ProductIngredient } from "./ProductIngredient"; import { RequestProduct } from "./RequestProduct"; import { User } from "./User"; @Entity({ comment: "Productos qué serán visibles a los usuarios, estos están asociados a un local.", }) export class Product { @PrimaryGeneratedColumn({ type: "int", comment: "Número de identificación (ID) único de cada registro.", }) id: number; @ManyToOne(() => Category, (category) => category.products, { onDelete: "CASCADE", onUpdate: "NO ACTION", }) @JoinColumn({ name: "category" }) category: Category; @Column({ length: 50, type: "varchar", comment: "Nombre del producto." }) name: string; @Column({ length: 400, type: "varchar", comment: "Detalles del producto. \n\n ¿Qué contiene?", }) details: string; @Column({ length: 20, type: "varchar", comment: "Precio del producto." }) price: string; @Column({ default: 0, type: "int", width: 1, comment: "¿El producto cuenta con restricción de edad?\r\n1. Cuenta con restricción.\r\n0. No cuenta con restricción.", }) age_restriction: number; @Column({ default: 0, type: "int", width: 1, comment: "¿El producto es un combo?\r\n1. Combo.\r\n0. No es un combo.", }) combo: number; @Column({ type: "int", comment: "En qué posición se va a mostrar el producto.", }) position: number; @Column({ type: "mediumtext", transformer: jsonTransformer, nullable: true, default: null, comment: "Campo de tipo JSON donde se guarda información necesaria para el registro.", }) additional_information: any | null; @Column({ nullable: true, type: "int", width: 1, comment: "Campo para saber el tipo de horario que se va a mostrar en la aplicación:\n 1. Días. \n2. Fecha específica.", default: null, }) type_sales_hours: number | null; @ManyToOne(() => Partner, (partner) => partner.partners_created_by, { onDelete: "RESTRICT", onUpdate: "NO ACTION", }) @JoinColumn({ name: "created_by" }) created_by: Partner; @Column({ type: "datetime", default: () => "CURRENT_TIMESTAMP", comment: "Fecha de creación del registro.", }) created: Date; @Column({ type: "datetime", nullable: true, default: null, onUpdate: "CURRENT_TIMESTAMP", comment: "Fecha de actualización del registro.", }) updated: Date | null; @ManyToOne(() => Partner, (partner) => partner.partners_update_by, { onDelete: "RESTRICT", onUpdate: "NO ACTION", nullable: true, }) @JoinColumn({ name: "updated_by" }) updated_by: Partner | null; @Column({ type: "mediumtext", nullable: true, default: null, transformer: jsonTransformer, comment: "Valores qué se van a mostrar mientras se aprueban los nuevos cambios.", }) current_values: any | null; @Column({ default: 1, type: "int", width: 1, comment: "Estado en el que está el elemento: \n0. Inactivo. \n1. Activo. \n2. Eliminado.", }) status: number; @Column({ default: 1, type: "int", width: 1, comment: "Estado en el que se encuentra la revisión de los cambios: \n1. En revisión. \n2. Rechazado.", }) status_review: number; @Column({ nullable: true, default: null, type: "varchar", length: 600, comment: "Comentarios u observaciones de la revisión.", }) review_comment: string | null; @OneToMany(() => ProductGroup, (productGroup) => productGroup.product) product_groups: ProductGroup[]; @OneToMany( () => ProductIngredient, (productIngredient) => productIngredient.product, ) product_ingredients: ProductIngredient[]; @OneToMany(() => RequestProduct, (requestProduct) => requestProduct.product) request_products: RequestProduct[]; @ManyToMany(() => User, (user) => user.user_favorite_products) @JoinTable({ name: "user_favorite_product", joinColumn: { name: "product", referencedColumnName: "id", }, inverseJoinColumn: { name: "user", referencedColumnName: "id", }, }) users_favorite_product: User[]; @OneToMany( () => ProductSchedule, (productSchedule) => productSchedule.product, ) product_schedules: ProductSchedule[]; @OneToMany(() => ProductDate, (productDate) => productDate.product) product_dates: ProductDate[]; @OneToMany(() => ProductImage, (productImage) => productImage.product) products_image: ProductImage[]; @ManyToMany(() => Gallery, (gallery) => gallery.products_images) @JoinTable({ name: "product_image", joinColumn: { name: "product", referencedColumnName: "id", }, inverseJoinColumn: { name: "image", referencedColumnName: "id", }, }) product_images: Gallery[]; @OneToMany( () => DiscountCodeUserProduct, (discountCodeUserProduct) => discountCodeUserProduct.product, ) discount_code_user_products: DiscountCodeUserProduct[]; }