src/auth/user.entity.ts
BaseEntity
Properties |
Methods |
|
| id |
Type : string
|
Decorators :
@PrimaryGeneratedColumn('uuid')
|
|
Defined in src/auth/user.entity.ts:9
|
| password |
Type : string
|
Decorators :
@Column()
|
|
Defined in src/auth/user.entity.ts:15
|
| salt |
Type : string
|
Decorators :
@Column()
|
|
Defined in src/auth/user.entity.ts:18
|
| tasks |
Type : Task[]
|
Decorators :
@OneToMany(undefined, undefined, {eager: true})
|
|
Defined in src/auth/user.entity.ts:21
|
| username |
Type : string
|
Decorators :
@Column()
|
|
Defined in src/auth/user.entity.ts:12
|
| Async validatePassword | ||||||
validatePassword(password: string)
|
||||||
|
Defined in src/auth/user.entity.ts:23
|
||||||
|
Parameters :
Returns :
Promise<boolean>
|
import { Entity, BaseEntity, PrimaryGeneratedColumn, Column, Unique, OneToMany } from 'typeorm';
import * as bcrypt from 'bcryptjs';
import { Task } from '../task/task-entity';
@Entity()
@Unique(['username'])
export class User extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
username: string;
@Column()
password: string;
@Column()
salt: string;
@OneToMany(type => Task, task => task.user, {eager: true})
tasks: Task[];
async validatePassword(password: string): Promise<boolean> {
const hash = await bcrypt.hash(password, this.salt);
return hash === this.password;
}
}