From 2cfcfccfaa39de503c227e5ca9e3d1089d1304ff Mon Sep 17 00:00:00 2001 From: fadlydev Date: Sat, 28 Dec 2024 12:00:26 +0700 Subject: [PATCH] add supplier entity --- src/entity/goods.ts | 46 +++++++++++++++++----------- src/entity/supplier.ts | 68 ++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 4 ++- 3 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 src/entity/supplier.ts diff --git a/src/entity/goods.ts b/src/entity/goods.ts index 43e6b91..0ff8721 100644 --- a/src/entity/goods.ts +++ b/src/entity/goods.ts @@ -7,11 +7,12 @@ import { DeleteDateColumn, Index, ManyToOne, - JoinColumn + JoinColumn, } from 'typeorm'; import { Status } from '../types/status'; import { User } from './users'; +import { Supplier } from './supplier'; @Entity('goods') export class Goods { @@ -19,34 +20,34 @@ export class Goods { id: string; @Column({ - nullable: false, - length: 128, + nullable: false, + length: 128, }) name: string; @Column({ - nullable: true, - length: 255, + nullable: true, + length: 255, }) description: string; @Column({ - nullable: false, - type: 'decimal', - precision: 10, - scale: 2, + nullable: false, + type: 'decimal', + precision: 10, + scale: 2, }) price: number; @Column({ - nullable: true, - type: 'int', + nullable: true, + type: 'int', }) quantity: number; @Column({ - nullable: true, - type: 'uuid', + nullable: true, + type: 'uuid', }) category_id: string; @@ -56,14 +57,25 @@ export class Goods { @Index() @Column({ - nullable: true, - type: 'uuid', + nullable: true, + type: 'uuid', }) created_by: string; + @ManyToOne(() => Supplier, { nullable: false }) + @JoinColumn({ name: 'supplier_id' }) + supplier: Supplier; + + @Index() @Column({ - nullable: false, - length: 64, + nullable: false, + type: 'uuid', + }) + supplier_id: string; + + @Column({ + nullable: false, + length: 64, }) status: Status; diff --git a/src/entity/supplier.ts b/src/entity/supplier.ts new file mode 100644 index 0000000..7daab55 --- /dev/null +++ b/src/entity/supplier.ts @@ -0,0 +1,68 @@ +import { + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + UpdateDateColumn, + DeleteDateColumn, +} from 'typeorm'; + +@Entity('suppliers') +export class Supplier { + @PrimaryGeneratedColumn('uuid') + id: string; + + @Column({ + nullable: false, + length: 128, + }) + name: string; + + @Column({ + nullable: true, + length: 255, + }) + description: string; + + @Column({ + nullable: true, + length: 128, + }) + contact_person: string; + + @Column({ + nullable: true, + length: 128, + }) + email: string; + + @Column({ + nullable: true, + length: 15, + }) + phone: string; + + @Column({ + nullable: true, + length: 255, + }) + address: string; + + @Column({ + nullable: false, + length: 64, + }) + status: string; + + @Column() + @CreateDateColumn() + created_at: Date; + + @Column({ nullable: true }) + @UpdateDateColumn() + updated_at: Date; + + @Column({ nullable: true }) + @DeleteDateColumn() + deleted_at: Date; +} diff --git a/src/index.ts b/src/index.ts index daa5784..2b2d3d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,6 +36,7 @@ import { Summarize } from "./entity/summarizes"; import { SummarizeLog } from "./entity/summarize_log"; import { SummarizeLogStatus, SummarizeType } from "./types/summarize"; import { Goods } from "./entity/goods"; +import { Supplier } from "./entity/supplier"; export { User, // @@ -78,5 +79,6 @@ export { SummarizeLog, SummarizeLogStatus, SummarizeType, - Goods + Goods, + Supplier };