- الحصول على الرابط
- X
- بريد إلكتروني
- التطبيقات الأخرى
1
// GET 2
getAllEmployees: async ({ response }: { response: any }) => { 3
const data = await EmployeeService.getAll(); 4
response.status = 200; 5
response.body = { 6
success: true, 7
data, 8
}; 9
}, 10
// POST 11
createEmployee: async ({ request, response }: { request: any; response: any },) => { 12
const body = await request.body(); 13
await EmployeeService.add( 14
{ name: body.value.name, 15
department:body.value.department, 16
isActive: true }, 17
); 18
response.body = { 19
success: true, 20
message: "The record was added successfully", 21
}; 22
}, 23
24
// GET by ID 25
getEmployeeById: async ( 26
{ params, response }: { params: { id: string }; response: any }, 27
) => { 28
const isAvailable = await EmployeeService.doesExistById( 29
{ id: Number(params.id) }, 30
); 31
const employee: Employee = await EmployeeService.getById({ id: Number(params.id) }); 32
response.status = 200; 33
... 34
}, 35
//PUT 36
updateEmployeeById: async ({ params, request, response }: {params: { id: string }; 37
request: any; 38
response: any; 39
},) => { 40
const isAvailable = await EmployeeService.doesExistById( 41
{ id: Number(params.id) }, 42
); 43
const body = await request.body(); 44
const updatedRows = await EmployeeService.updateById({ 45
id: Number(params.id), 46
...body.value, 47
}); 48
response.status = 200; 49
... 50
}, 51
//DELETE 52
deleteEmployeeById: async ( 53
{ params, response }: { params: { id: string }; response: any }, 54
) => { 55
const updatedRows = await EmployeeService.deleteById({ 56
id: Number(params.id), 57
}); 58
response.status = 200; 59
... 60
}, 61
};- الحصول على الرابط
- X
- بريد إلكتروني
- التطبيقات الأخرى
تعليقات
إرسال تعليق