Included user-information in employee Model.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { DateTime } from 'luxon'
|
||||
import { BaseModel, belongsTo, BelongsTo, column } from '@ioc:Adonis/Lucid/Orm'
|
||||
import User from 'App/Models/User'
|
||||
import { BaseModel, beforeSave, column } from '@ioc:Adonis/Lucid/Orm'
|
||||
import Hash from '@ioc:Adonis/Core/Hash'
|
||||
|
||||
export default class Employee extends BaseModel {
|
||||
@column({ isPrimary: true })
|
||||
@@ -22,20 +22,33 @@ export default class Employee extends BaseModel {
|
||||
public shorthand: string
|
||||
|
||||
@column()
|
||||
public email : string
|
||||
public email : string | undefined
|
||||
|
||||
@column()
|
||||
public phone : string
|
||||
public phone : string | undefined
|
||||
|
||||
@column()
|
||||
public mobile : string
|
||||
public mobile : string | undefined
|
||||
|
||||
@column()
|
||||
public contractHours : number
|
||||
public contractHours : number | undefined
|
||||
|
||||
@column()
|
||||
public userId : number
|
||||
public isActive : boolean
|
||||
|
||||
@belongsTo(() => User)
|
||||
public user: BelongsTo<typeof User>
|
||||
@column()
|
||||
public role: string
|
||||
|
||||
@column()
|
||||
public username: string | undefined
|
||||
|
||||
@column({serializeAs: null})
|
||||
public password: string
|
||||
|
||||
@beforeSave()
|
||||
public static async hashPassword(employee: Employee){
|
||||
if(employee.$dirty.password){
|
||||
employee.password = await Hash.make(employee.password)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user