delete /group

Gruppe mit allen Items löschen
This commit is contained in:
Lukas Nowy 2019-01-15 17:39:33 +01:00
parent 84705cd155
commit ed1e752ace
2 changed files with 25 additions and 1 deletions

View File

@ -203,6 +203,21 @@ async function editItem(sl_id, group_id, item_id, name, count) {
}
}
//Delete Group
async function deleteGroup(group_id, sl_id) {
try {
//Alle Items der Group löschen
nonQuery('DELETE FROM "Item" WHERE group_id = $1 AND sl_id = $2', [group_id, sl_id]);
//Leere Gruppe löschen
nonQuery('DELETE FROM "Group" WHERE group_id = $1 AND sl_id = $2', [group_id, sl_id]);
}
catch (error) {
console.error(error);
}
}
@ -312,5 +327,5 @@ function generateInviteLink() {
module.exports = {
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem
addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem, deleteGroup
}

View File

@ -243,6 +243,15 @@ router.put("/item", async (req, res) => {
}
});
router.delete("/group", async(req, res) => {
try {
res.status(200).send(await postgres.deleteGroup(req.body.group_id, req.body.sl_id));
}
catch(err) {
res.status(400).send(await err);
}
});
// Invite System