import { BaseEntity, Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; import Stock from "../../../domain/entities/stock"; import { ItemRecord } from "./item.record"; @Entity("stock", { synchronize: true }) @Index(["encodedCode", "item"], { unique: true, where: "encoded_code IS NOT NULL" }) export class StockRecord extends BaseEntity { @PrimaryGeneratedColumn("uuid") id: string; @Column() code: string; @Column({ nullable: true }) assignedToId?: number; @Column({ default: true }) available: boolean; @Column("text", { nullable: true, name: "encoded_code" }) encodedCode?: string; @ManyToOne(() => ItemRecord, (item) => item.stock, { nullable: false }) item: ItemRecord; toEntity = (): Stock => { return new Stock( this.item.toEntity(), this.code, this.assignedToId, this.encodedCode, this.id, ); }; }