Update stats when creating events and people
This commit is contained in:
parent
99989e66aa
commit
ac96c9b441
3 changed files with 25 additions and 1 deletions
|
|
@ -36,6 +36,18 @@ module.exports = async (req, res) => {
|
|||
await req.datastore.insert(entity);
|
||||
|
||||
res.sendStatus(201);
|
||||
|
||||
// Update stats
|
||||
let personCountResult = (await req.datastore.get(req.datastore.key([req.types.stats, 'personCount'])))[0] || null;
|
||||
if (personCountResult) {
|
||||
personCountResult.value++;
|
||||
await req.datastore.upsert(personCountResult);
|
||||
} else {
|
||||
await req.datastore.insert({
|
||||
key: req.datastore.key([req.types.stats, 'personCount']),
|
||||
data: { value: 1 },
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.sendStatus(400);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue