Added settings API
This commit is contained in:
@@ -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'
|
||||
}
|
||||
}
|
||||
|
||||
26
app/Models/Setting.ts
Normal file
26
app/Models/Setting.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { DateTime } from 'luxon'
|
||||
import { BaseModel, belongsTo, BelongsTo, column } from '@ioc:Adonis/Lucid/Orm'
|
||||
import Employee from 'App/Models/Employee'
|
||||
|
||||
export default class Setting 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 employeeId: number
|
||||
|
||||
@belongsTo(() => Employee)
|
||||
public employee: BelongsTo<typeof Employee>
|
||||
|
||||
@column()
|
||||
public key: string
|
||||
|
||||
@column()
|
||||
public value: string
|
||||
}
|
||||
Reference in New Issue
Block a user