28 lines
754 B
TypeScript
28 lines
754 B
TypeScript
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
|
import { Expense } from './Expense.js';
|
|
import { User } from './User.js';
|
|
|
|
@Entity('categories')
|
|
export class Category {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
@Column({ type: 'varchar', length: 80 })
|
|
name!: string;
|
|
|
|
@Column({ type: 'varchar', length: 32, default: '#0d6efd' })
|
|
color!: string;
|
|
|
|
@Column({ type: 'boolean', default: false })
|
|
isSystem!: boolean;
|
|
|
|
@CreateDateColumn({ type: 'datetime' })
|
|
createdAt!: Date;
|
|
|
|
@ManyToOne(() => User, (user) => user.categories, { nullable: true, onDelete: 'CASCADE' })
|
|
user!: User | null;
|
|
|
|
@OneToMany(() => Expense, (expense) => expense.category)
|
|
expenses!: Expense[];
|
|
}
|