import { Entity, Column, BaseEntity, PrimaryGeneratedColumn, OneToMany, ManyToOne, Relation, JoinColumn, CreateDateColumn, } from 'typeorm'; import { BranchEntity } from './branch.entity.js'; import { IsOptional } from 'class-validator'; import { Role } from '../common/enums/role.enum.js'; import { ReceiptEntity } from './receipt.entity.js'; @Entity('users') export class UserEntity extends BaseEntity { @PrimaryGeneratedColumn('uuid') id: string; @IsOptional() @Column({ nullable: true }) avatar: string; @Column() full_name: string; @Column({ unique: true }) phone_number: string; @IsOptional() @Column({ nullable: true }) address: string; @Column({ nullable: true, unique: true }) email: string; @Column({ type: 'enum', enum: Role, default: 'CUSTOMER' }) role: Role; @Column() hash_password: string; @Column({ default: true }) is_valid: boolean; @CreateDateColumn() create_at: Date; @OneToMany(() => BranchEntity, (branch) => branch.owner) branches: Relation[]; @OneToMany(() => ReceiptEntity, (receipt) => receipt.sender) in_receipts: Relation[]; @OneToMany(() => ReceiptEntity, (receipt) => receipt.receiver) out_receipts: Relation[]; @ManyToOne(() => BranchEntity, { nullable: true }) @JoinColumn({ name: 'branch_id' }) // Tùy chỉnh tên cột là branch_id branch: Relation; @Column({ nullable: true }) branch_id: string; }