Spaces:
Sleeping
Sleeping
File size: 1,559 Bytes
6f39f03 85a7484 6f39f03 85a7484 6f39f03 85a7484 439f1c8 6f39f03 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
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<BranchEntity>[];
@OneToMany(() => ReceiptEntity, (receipt) => receipt.sender)
in_receipts: Relation<ReceiptEntity>[];
@OneToMany(() => ReceiptEntity, (receipt) => receipt.receiver)
out_receipts: Relation<ReceiptEntity>[];
@ManyToOne(() => BranchEntity, { nullable: true })
@JoinColumn({ name: 'branch_id' }) // Tùy chỉnh tên cột là branch_id
branch: Relation<BranchEntity>;
@Column({ nullable: true })
branch_id: string;
}
|