File

src/auth/user.entity.ts

Extends

BaseEntity

Index

Properties
Methods

Properties

id
Type : string
Decorators :
@PrimaryGeneratedColumn('uuid')
password
Type : string
Decorators :
@Column()
salt
Type : string
Decorators :
@Column()
tasks
Type : Task[]
Decorators :
@OneToMany(undefined, undefined, {eager: true})
username
Type : string
Decorators :
@Column()

Methods

Async validatePassword
validatePassword(password: string)
Parameters :
Name Type Optional
password string No
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;
    }
}

result-matching ""

    No results matching ""