Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handler: async (request, reply) => {
if (request.payload.actions && request.payload.actions.length) {
for (let action of request.payload.actions) {
if (!isValidAction(action)) {
return reply.response(`Invalid action: "${action}"`).code(400);
}
}
}
const task = await model.task.create(request.payload);
if (!task) {
return reply.response().code(500);
}
return reply.response(task)
.header('Location', `http://${request.info.host}/tasks/${task.id}`)
.code(201);
},
options: {
handler: async (request, reply) => {
const task = await model.task.getById(request.params.id);
if (!task) {
return reply.response('Not Found').code(404);
}
if (request.payload.actions && request.payload.actions.length) {
for (let action of request.payload.actions) {
if (!isValidAction(action)) {
return reply.response(`Invalid action: "${action}"`).code(400);
}
}
}
const updateCount = await model.task.editById(task.id, request.payload);
if (updateCount < 1) {
return reply.response().code(500);
}
const taskAgain = await model.task.getById(task.id);
return reply.response(taskAgain).code(200);
},
options: {