Skip to content

Instantly share code, notes, and snippets.

@Jmzp
Created July 11, 2019 19:49
Show Gist options
  • Select an option

  • Save Jmzp/bda5aa654a7b1aae40ba2cfe98f5e544 to your computer and use it in GitHub Desktop.

Select an option

Save Jmzp/bda5aa654a7b1aae40ba2cfe98f5e544 to your computer and use it in GitHub Desktop.

Revisions

  1. Jmzp created this gist Jul 11, 2019.
    18 changes: 18 additions & 0 deletions tasks.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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 }] } });
    })
    });