import bcrypt from 'bcryptjs'; import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index } from 'typeorm'; import { Status } from '../types/status'; @Entity('users') export class User { @PrimaryGeneratedColumn('uuid') id: string; @Column({ nullable: false, unique: true, length: 64 }) email: string; @Column({ nullable: false, length: 64, select: false }) password: string; @Column({ nullable: false, unique: true, length: 64 }) username: string; @Column({ nullable: true, length: 64 }) name: string; @Column({ nullable: true, type: 'uuid' }) id_role: string; @Index() @Column({ nullable: true, type: 'uuid' }) 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); } }