mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 05:42:27 +00:00
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
JoinColumn,
|
|
ManyToMany,
|
|
ManyToOne,
|
|
PrimaryGeneratedColumn,
|
|
UpdateDateColumn,
|
|
} from 'typeorm';
|
|
import { Junior } from '~/junior/entities';
|
|
import { CategoryType } from '../enums';
|
|
import { SavingGoal } from './saving-goal.entity';
|
|
|
|
@Entity('categories')
|
|
export class Category {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
@Column({ type: 'varchar', length: 255, name: 'name' })
|
|
name!: string;
|
|
|
|
@Column({ type: 'varchar', length: 255, name: 'type' })
|
|
type!: CategoryType;
|
|
|
|
@Column({ type: 'uuid', name: 'junior_id', nullable: true })
|
|
juniorId!: string;
|
|
|
|
@ManyToOne(() => Junior, (junior) => junior.categories, { onDelete: 'CASCADE', nullable: true })
|
|
@JoinColumn({ name: 'junior_id' })
|
|
junior!: Junior;
|
|
|
|
@ManyToMany(() => SavingGoal, (savingGoal) => savingGoal.categories)
|
|
goals!: SavingGoal[];
|
|
|
|
@CreateDateColumn({ type: 'timestamp', name: 'created_at', default: () => 'CURRENT_TIMESTAMP' })
|
|
createdAt!: Date;
|
|
|
|
@UpdateDateColumn({ type: 'timestamp', name: 'updated_at', default: () => 'CURRENT_TIMESTAMP' })
|
|
updatedAt!: Date;
|
|
}
|