diff --git a/src/Web.ts b/src/Web.ts index 65bcd3a..7db826a 100644 --- a/src/Web.ts +++ b/src/Web.ts @@ -96,6 +96,33 @@ class Web { }); }); + app.post('/api/chores/:id', async (req, res) => { + const doer = req.body?.done_by; + const chore = req.params?.id; + if (typeof doer != 'number' || doer < 0) { + res.status(400).send({ + error: 'done_by value is invalid.' + }); + return; + } + if (typeof chore != 'number' || chore < 0) { + res.status(400).send({ + error: 'chore id value is invalid.' + }); + return; + } + try { + const resp = await this.grocy.doChore(chore, doer); + res.send(resp); + } + catch (err) { + console.error(err); + res.status(400).send({ + error: 'grocy didn\'t like that.' + }); + } + }); + app.get('/api/users/:id', async (req, res) => { const user = await this.grocy.user(parseInt(req.params.id)) res.send({