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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import { DateTime } from 'luxon'
|
||||
import { BaseModel, beforeSave, column, hasOne, HasOne } from '@ioc:Adonis/Lucid/Orm'
|
||||
import Hash from '@ioc:Adonis/Core/Hash'
|
||||
import Employee from 'App/Models/Employee'
|
||||
|
||||
export default class User extends BaseModel {
|
||||
@column({ isPrimary: true })
|
||||
public id: number
|
||||
|
||||
@column.dateTime({ autoCreate: true })
|
||||
public createdAt: DateTime
|
||||
|
||||
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||
public updatedAt: DateTime
|
||||
|
||||
@column()
|
||||
public username: string
|
||||
|
||||
@column()
|
||||
public email: string
|
||||
|
||||
@column({serializeAs: null})
|
||||
public password : string
|
||||
|
||||
@hasOne(() => Employee)
|
||||
public employeeProfile : HasOne<typeof Employee>
|
||||
|
||||
@column()
|
||||
public role : string
|
||||
|
||||
@column()
|
||||
public isActive : boolean
|
||||
|
||||
@beforeSave()
|
||||
public static async hashPassword(user: User) {
|
||||
if(user.$dirty.password){
|
||||
user.password = await Hash.make(user.password)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user