Added settings API

This commit is contained in:
Sockenklaus
2021-11-12 01:15:40 +01:00
parent 654a829c16
commit ed7120ad2e
10 changed files with 251 additions and 40 deletions

View File

@@ -1,5 +1,6 @@
import { DateTime } from 'luxon'
import { BaseModel, beforeSave, column } from '@ioc:Adonis/Lucid/Orm'
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 {
@@ -45,10 +46,17 @@ export default class Employee extends BaseModel {
@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'
}
}