import bcrypt from 'bcryptjs' ; import { Entity , PrimaryGeneratedColumn , Column , CreateDateColumn , UpdateDateColumn } from 'typeorm' ; import { Role , Language } from './types' ; @ Entity ( 'users' ) export class User { @ PrimaryGeneratedColumn ( ) id : number ; @ Column ( { unique : true , } ) email : string ; @ Column ( ) password : string ; @ Column ( { nullable : true , unique : true , } ) username : string ; @ Column ( { nullable : true , } ) name : string ; @ Column ( { default : 'STANDARD' as Role , length : 30 , } ) role : string ; @ Column ( { default : 'en-US' as Language , length : 15 , } ) language : string ; @ Column ( ) @ CreateDateColumn ( ) created_at : Date ; @ Column ( ) @ UpdateDateColumn ( ) updated_at : Date ; setLanguage ( language ) { this . language = language ; } hashPassword ( ) { this . password = bcrypt . hashSync ( this . password , 8 ) ; } checkIfPasswordMatch ( unencryptedPassword ) { return bcrypt . compareSync ( unencryptedPassword , this . password ) ; } }