Created
July 11, 2019 19:49
-
-
Save Jmzp/bda5aa654a7b1aae40ba2cfe98f5e544 to your computer and use it in GitHub Desktop.
Tutorial of Koa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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