adding table target, adjust categories

This commit is contained in:
fro1991
2024-12-18 01:00:01 +07:00
parent ba46237805
commit fe046e8cd7
3 changed files with 59 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import { Column, CreateDateColumn, DeleteDateColumn, Entity, JoinColumn, ManyToO
import { CategorySource } from '../types/category_source';
import { Status } from '../types/status';
import { Target } from './targets';
@Entity('categories')
export class Category {
@ -56,6 +57,10 @@ export class Category {
})
products: string[];
@OneToMany(() => Target, (target) => target.category)
targets: Target[];
@Column()
@CreateDateColumn()
created_at: Date;

51
src/entity/targets.ts Normal file
View File

@ -0,0 +1,51 @@
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index, JoinColumn, ManyToOne } from 'typeorm';
import { Category } from './categories';
@Entity('targets')
export class Target {
@PrimaryGeneratedColumn('uuid')
id: string;
@ManyToOne(() => Category, (category) => category.targets, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'categoryId' }) // Add foreign key column
category: Category;
@Column({ nullable: false })
categoryId: string;
@Column({
type: 'int2',
nullable: false,
})
year: number;
@Column({
type: 'int2',
nullable: false,
})
month: number;
@Column({
type: 'float8',
nullable: true,
})
target: number;
@Column({
nullable: true,
length: 4096
})
notes: string;
@Column()
@CreateDateColumn()
created_at: Date;
@Column({ nullable: true })
@UpdateDateColumn()
updated_at: Date;
@Column({ nullable: true })
@DeleteDateColumn()
deleted_at: Date;
}

View File

@ -27,6 +27,7 @@ import { LogPullType, StatusLogPull } from "./types/pull";
import { Category } from "./entity/categories";
import { CategorySource } from "./types/category_source";
import { PullerStatus } from "./entity/puller_status";
import { Target } from "./entity/targets";
export {
User,
@ -59,5 +60,6 @@ export {
StatusLogPull,
Category,
CategorySource,
PullerStatus
PullerStatus,
Target
};