forked from domini-code/mysql_node_angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsers.ts
More file actions
34 lines (28 loc) · 697 Bytes
/
Copy pathUsers.ts
File metadata and controls
34 lines (28 loc) · 697 Bytes
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
import { Entity, PrimaryGeneratedColumn, Unique, Column } from 'typeorm';
import { MinLength, IsNotEmpty, IsEmail } from 'class-validator';
import * as bcrypt from 'bcryptjs';
@Entity()
@Unique(['username'])
export class Users {
@PrimaryGeneratedColumn()
id: number;
@Column()
@MinLength(6)
@IsEmail()
@IsNotEmpty()
username: string;
@Column()
@MinLength(6)
@IsNotEmpty()
password: string;
@Column()
@IsNotEmpty()
role: string;
hashPassword(): void {
const salt = bcrypt.genSaltSync(10);
this.password = bcrypt.hashSync(this.password, salt);
}
checkPassword(password: string): boolean {
return bcrypt.compareSync(password, this.password);
}
}