generated from corysanin/nodejs-web-template
chore done endpoint
This commit is contained in:
27
src/Web.ts
27
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({
|
||||
|
Reference in New Issue
Block a user