import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, PrimaryGeneratedColumn, } from "typeorm"; import { Local, Partner, Product, ProductImage } from ".."; @Entity({ name: "gallery", comment: "Galería de imágenes qué se usan para los productos.", }) export class Gallery { @PrimaryGeneratedColumn({ type: "int", comment: "ID único de cada registro.", }) id: number; @ManyToOne(() => Local, (local) => local.galleries, { onDelete: "CASCADE", onUpdate: "NO ACTION", nullable: true, }) @JoinColumn({ name: "local" }) local: Local | null; @Column({ type: "varchar", length: 255, unique: true, comment: "ID de la imagen.", }) public_id: string; @Column({ type: "varchar", length: 1024, comment: "Url de la imagen.", }) image_url: string; @Column({ type: "datetime", default: () => "CURRENT_TIMESTAMP", comment: "Fecha de creación de la imagen.", }) created: Date; @ManyToOne(() => Partner, (partner) => partner.galleries, { onDelete: "NO ACTION", onUpdate: "NO ACTION", }) @JoinColumn({ name: "created_by" }) created_by: Partner; @Column({ default: 1, type: "int", width: 1, comment: "Estado en el que se encuentra la imagen:\r\n0: Inactivo.\r\n1: Activo.", }) status: number; @ManyToMany(() => Product, (product) => product.product_images) @JoinTable({ name: "product_image", joinColumn: { name: "image", referencedColumnName: "id", }, inverseJoinColumn: { name: "product", referencedColumnName: "id", }, }) products_images: Product[]; @OneToMany(() => ProductImage, (productImage) => productImage.image) product_images: ProductImage[]; }