Skip to content

Instantly share code, notes, and snippets.

@Jmzp
Created July 11, 2019 19:49
Show Gist options
  • Save Jmzp/bda5aa654a7b1aae40ba2cfe98f5e544 to your computer and use it in GitHub Desktop.
Save Jmzp/bda5aa654a7b1aae40ba2cfe98f5e544 to your computer and use it in GitHub Desktop.
Tutorial of Koa
router.get('/task/:id', async (ctx) => {
await Task.findOne({
where: {
id: ctx.params.id
}
})
.then(tasks => {
if (tasks === null){
Object.assign(ctx, { status: 404, body: { errors: [{ msg: 'Task does not exist' }] } });
}
else {
ctx.body = tasks;
}
})
.catch(() => {
Object.assign(ctx, { status: 500, body: { errors: [{ msg: err }] } });
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment