import bcrypt from "bcryptjs"; import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index, OneToOne, JoinColumn, ManyToOne, OneToMany, ManyToMany, JoinTable } from "typeorm"; import { Status } from "../types/status"; import { TrxCompany } from "./trx_companies"; import { TrxConfigLevel } from "./trx_config_levels"; @Entity("trx_company_users", { schema: "trx" }) export class TrxCompanyUser { @PrimaryGeneratedColumn("uuid") id: string; @Column({ nullable: false, unique: true, length: 64, }) email: string; @Column({ nullable: false, unique: true, length: 256, }) phone: string; @Column({ nullable: false, length: 64, select: false, }) password: string; @Column({ nullable: false, unique: true, length: 64, }) username: string; @Column({ nullable: true, length: 64, unique: false, }) name: string; @OneToMany(() => TrxConfigLevel, (level) => level.id, { onDelete: "NO ACTION", nullable: false }) level: TrxConfigLevel[]; @ManyToOne(() => TrxCompany, { onDelete: "NO ACTION" }) @JoinTable() company: TrxCompany; @Index() @Column({ nullable: true, type: "uuid", select: false, }) reset_token: string; @Column({ nullable: false, length: 64, }) status: Status; @Column() @CreateDateColumn() created_at: Date; @Column({ nullable: true }) @UpdateDateColumn() updated_at: Date; @Column({ nullable: true }) @DeleteDateColumn() deleted_at: Date; hashPassword() { this.password = bcrypt.hashSync(this.password, 8); } checkIfPasswordMatch(unencryptedPassword: string) { return bcrypt.compareSync(unencryptedPassword, this.password); } }