63 lines
1.3 KiB
TypeScript
63 lines
1.3 KiB
TypeScript
import { DateTime } from 'luxon'
|
|
import { BaseModel, beforeSave, column, hasMany, HasMany } from '@ioc:Adonis/Lucid/Orm'
|
|
import Setting from 'App/Models/Setting'
|
|
import Hash from '@ioc:Adonis/Core/Hash'
|
|
|
|
export default class Employee 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 firstName : string
|
|
|
|
@column()
|
|
public lastName : string | undefined
|
|
|
|
@column()
|
|
public shorthand: string
|
|
|
|
@column()
|
|
public email : string | undefined
|
|
|
|
@column()
|
|
public phone : string | undefined
|
|
|
|
@column()
|
|
public mobile : string | undefined
|
|
|
|
@column()
|
|
public contractHours : number | undefined
|
|
|
|
@column()
|
|
public isActive : boolean
|
|
|
|
@column()
|
|
public role: string
|
|
|
|
@column()
|
|
public username: string | undefined
|
|
|
|
@column({serializeAs: null})
|
|
public password: string
|
|
|
|
@hasMany(() => Setting)
|
|
public settings: HasMany<typeof Setting>
|
|
|
|
@beforeSave()
|
|
public static async hashPassword(employee: Employee){
|
|
if(employee.$dirty.password){
|
|
employee.password = await Hash.make(employee.password)
|
|
}
|
|
}
|
|
|
|
public isAdmin(): boolean {
|
|
return this.role === 'admin'
|
|
}
|
|
}
|