fixed EmployeesController. Correct error response in store function
This commit is contained in:
@@ -49,26 +49,21 @@ export default class EmployeesController {
|
|||||||
public async store ({request, bouncer}: HttpContextContract) {
|
public async store ({request, bouncer}: HttpContextContract) {
|
||||||
await bouncer.with('EmployeesPolicy').authorize('store')
|
await bouncer.with('EmployeesPolicy').authorize('store')
|
||||||
|
|
||||||
try {
|
const payload = await request.validate(CreateEmployeeValidator)
|
||||||
const payload = await request.validate(CreateEmployeeValidator)
|
|
||||||
|
|
||||||
return await Employee.create({
|
|
||||||
firstName: payload.firstName,
|
|
||||||
lastName: payload.lastName,
|
|
||||||
shorthand: payload.shorthand,
|
|
||||||
email: payload.email,
|
|
||||||
phone: payload.phone,
|
|
||||||
mobile: payload.mobile,
|
|
||||||
contractHours: payload.contractHours,
|
|
||||||
username: payload.username,
|
|
||||||
password: payload.password,
|
|
||||||
role: payload.role,
|
|
||||||
isActive: payload.isActive
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
return error
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return await Employee.create({
|
||||||
|
firstName: payload.firstName,
|
||||||
|
lastName: payload.lastName,
|
||||||
|
shorthand: payload.shorthand,
|
||||||
|
email: payload.email,
|
||||||
|
phone: payload.phone,
|
||||||
|
mobile: payload.mobile,
|
||||||
|
contractHours: payload.contractHours,
|
||||||
|
username: payload.username,
|
||||||
|
password: payload.password,
|
||||||
|
role: payload.role ?? 'employee',
|
||||||
|
isActive: payload.isActive ?? false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async show ({params, bouncer, auth}: HttpContextContract) : Promise<ResultShow> {
|
public async show ({params, bouncer, auth}: HttpContextContract) : Promise<ResultShow> {
|
||||||
@@ -127,8 +122,8 @@ export default class EmployeesController {
|
|||||||
await employee.save()
|
await employee.save()
|
||||||
|
|
||||||
return response.ok({
|
return response.ok({
|
||||||
status: 200,
|
status: 200,
|
||||||
message: "Employee updated successfully"
|
message: "Employee updated successfully"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default class SettingsController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async get({params, auth, response}: HttpContextContract): Promise<ResultSetting | null> {
|
public async get({params, auth}: HttpContextContract): Promise<ResultSetting | null> {
|
||||||
|
|
||||||
const key = params.key
|
const key = params.key
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user