update goods relations

This commit is contained in:
fadlydev
2025-01-19 07:32:48 +07:00
parent a22b459823
commit ad907a7661
3 changed files with 44 additions and 20 deletions

View File

@ -5,8 +5,11 @@ import {
CreateDateColumn, CreateDateColumn,
UpdateDateColumn, UpdateDateColumn,
DeleteDateColumn, DeleteDateColumn,
OneToMany,
} from 'typeorm'; } from 'typeorm';
import { Goods } from './goods';
@Entity('asset_category') @Entity('asset_category')
export class AssetCategory { export class AssetCategory {
@PrimaryGeneratedColumn('uuid') @PrimaryGeneratedColumn('uuid')
@ -24,6 +27,15 @@ export class AssetCategory {
}) })
description: string; description: string;
@OneToMany(() => Goods, (goods) => goods.category)
goods: Goods[];
@Column({
nullable: false,
default: true,
})
is_active: boolean;
@Column() @Column()
@CreateDateColumn() @CreateDateColumn()
created_at: Date; created_at: Date;

View File

@ -6,9 +6,12 @@ import {
UpdateDateColumn, UpdateDateColumn,
DeleteDateColumn, DeleteDateColumn,
Index, Index,
ManyToOne,
JoinColumn,
} from 'typeorm'; } from 'typeorm';
import { Status } from '../types/status'; import { AssetCategory } from './asset_category';
import { Supplier } from './supplier';
@Entity('goods') @Entity('goods')
export class Goods { export class Goods {
@ -43,53 +46,55 @@ export class Goods {
price: number; price: number;
@Column({ @Column({
nullable: true, nullable: false,
type: 'int', type: 'int',
}) })
quantity: number; quantity: number;
@Index() @Index()
@Column({ @Column({
nullable: true, nullable: false,
type: 'uuid',
})
category_id: string;
@Index()
@Column({
nullable: true,
type: 'uuid', type: 'uuid',
}) })
created_by: string; created_by: string;
@Index() @Index()
@Column({ @Column({
nullable: true, nullable: false,
type: 'uuid', type: 'uuid',
}) })
updated_by: string; updated_by: string;
@Column({ @ManyToOne(() => AssetCategory, (category) => category.goods, {
nullable: false, nullable: false,
type: 'uuid', onDelete: 'SET NULL'
}) })
supplier_id: string;
@Index()
@JoinColumn({ name: 'category_id'})
category: AssetCategory;
@ManyToOne(() => Supplier, (supplier) => supplier.goods, {
nullable: true,
onDelete: 'SET NULL'
})
@Index()
@JoinColumn({ name: 'supplier_id' })
supplier: Supplier;
@Column({ @Column({
nullable: false, nullable: false,
length: 64, default: true,
}) })
status: Status; is_active: boolean;
@Column()
@CreateDateColumn() @CreateDateColumn()
created_at: Date; created_at: Date;
@Column({ nullable: true })
@UpdateDateColumn() @UpdateDateColumn()
updated_at: Date; updated_at: Date;
@Column({ nullable: true })
@DeleteDateColumn() @DeleteDateColumn()
deleted_at: Date; deleted_at: Date;
} }

View File

@ -1,5 +1,6 @@
import { import {
Entity, Entity,
OneToMany,
PrimaryGeneratedColumn, PrimaryGeneratedColumn,
Column, Column,
CreateDateColumn, CreateDateColumn,
@ -7,6 +8,8 @@ import {
DeleteDateColumn, DeleteDateColumn,
} from 'typeorm'; } from 'typeorm';
import { Goods } from './goods';
@Entity('suppliers') @Entity('suppliers')
export class Supplier { export class Supplier {
@PrimaryGeneratedColumn('uuid') @PrimaryGeneratedColumn('uuid')
@ -24,6 +27,9 @@ export class Supplier {
}) })
contact_person: string; contact_person: string;
@OneToMany(() => Goods, (goods) => goods.supplier)
goods: Goods[];
@Column({ @Column({
nullable: true, nullable: true,
length: 128, length: 128,
@ -45,6 +51,7 @@ export class Supplier {
@Column({ @Column({
nullable: false, nullable: false,
length: 64, length: 64,
unique: true,
}) })
code_id: string; code_id: string;
@ -55,7 +62,7 @@ export class Supplier {
type: string; type: string;
@Column({ @Column({
type: 'boolean', nullable: false,
default: true, default: true,
}) })
is_active: boolean; is_active: boolean;