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

View File

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

View File

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