Files
entity/src/entity/remit_partner_users.ts
2025-07-02 22:41:50 +07:00

88 lines
1.6 KiB
TypeScript

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 { RemitPartner } from "./remit_partners";
@Entity("remit_partner_users", { schema: "remits" })
export class RemitPartnerUser {
@PrimaryGeneratedColumn("uuid")
id: string;
@Column({
nullable: true,
unique: false,
length: 64,
})
email: string;
@Column({
nullable: true,
length: 64,
select: false,
})
password: string;
@Column({
nullable: false,
unique: false,
length: 64,
})
username: string;
@Column({
nullable: false,
length: 64,
unique: false,
})
name: string;
@ManyToOne(() => RemitPartner, { onDelete: "CASCADE" })
@JoinTable()
partner: RemitPartner;
@Index()
@Column({
nullable: true,
type: "uuid",
select: false,
})
reset_token: string;
@Column({
nullable: false,
length: 64,
})
status: String;
@Column()
@CreateDateColumn()
created_at: Date;
@Column({ nullable: true, length: 256 })
created_by: string;
@Column({ nullable: true })
@UpdateDateColumn()
updated_at: Date;
@Column({ nullable: true, length: 256 })
updated_by: string;
@Column({ nullable: true })
@DeleteDateColumn()
deleted_at: Date;
@Column({ nullable: true, length: 256 })
deleted_by: string;
hashPassword() {
this.password = bcrypt.hashSync(this.password, 8);
}
checkIfPasswordMatch(unencryptedPassword: string) {
return bcrypt.compareSync(unencryptedPassword, this.password);
}
}