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

@@ -22,7 +22,7 @@ type ResultShow = {
export default class EmployeesController {
public async index ({bouncer, request}: HttpContextContract) {
await bouncer.authorize('employees.index')
await bouncer.with('EmployeesPolicy').authorize('index')
const limit: number = request.qs().limit ?? 10
const page: number = request.qs().page ?? 1
@@ -46,7 +46,9 @@ export default class EmployeesController {
return employees.paginate(page, limit)
}
public async store ({request}: HttpContextContract) {
public async store ({request, bouncer}: HttpContextContract) {
await bouncer.with('EmployeesPolicy').authorize('store')
try {
const payload = await request.validate(CreateEmployeeValidator)
@@ -79,7 +81,7 @@ export default class EmployeesController {
emp = await Employee.findOrFail(params.id)
}
await bouncer.authorize('employees.show', emp)
await bouncer.with('EmployeesPolicy').authorize('show', emp)
return {
id: emp.id,
@@ -101,7 +103,7 @@ export default class EmployeesController {
const employee : Employee = await Employee.findOrFail(params.id)
const editContractHours : boolean = employee.contractHours !== request.input('contractHours')
await bouncer.authorize('employees.update', editContractHours, employee)
await bouncer.with('EmployeesPolicy').authorize('update', editContractHours, employee)
const payload = await request.validate(UpdateEmployeeValidator)
@@ -131,7 +133,7 @@ export default class EmployeesController {
}
public async destroy ({params, bouncer}: HttpContextContract) {
await bouncer.authorize('employees.destroy')
await bouncer.with('EmployeesPolicy').authorize('destroy')
return await Database.from('employees').where('id', params.id).delete()
}
@@ -186,7 +188,7 @@ export default class EmployeesController {
let arr = qs.split(',').filter(item => item !== 'password' && item !== '' && columns.hasOwnProperty(item))
if(arr.length === 0) arr = ['id', 'last_name', 'first_name', 'email', 'mobile', 'phone', 'role']
if(arr.length === 0) arr = ['id', 'last_name', 'first_name', 'shorthand', 'email', 'mobile', 'phone', 'role']
return arr
}