put /group
Gruppe bearbeiten
This commit is contained in:
parent
8f17cf423c
commit
7fc2ccf040
@ -70,19 +70,19 @@ async function newShoppinglist(name, description, username, color) {
|
||||
//rename Shoppinglist
|
||||
|
||||
|
||||
async function renameShoppinglist(sl_id, newname, newdescription, newcolor) {
|
||||
async function editShoppinglist(sl_id, newname, newdescription, newcolor) {
|
||||
try {
|
||||
let shoppinglist = await query('SELECT row_to_json("Shoppinglist") AS obj FROM "Shoppinglist" WHERE sl_id = $1;', [sl_id]);
|
||||
|
||||
if(shoppinglist.name != newname) {
|
||||
if(shoppinglist.name != newname && newname != undefined) {
|
||||
await nonQuery('UPDATE "Shoppinglist" SET name = $1 WHERE sl_id = $2;', [newname, sl_id]);
|
||||
}
|
||||
|
||||
if(shoppinglist.description != newdescription) {
|
||||
if(shoppinglist.description != newdescription && newdescription != undefined) {
|
||||
await nonQuery('UPDATE "Shoppinglist" SET description = $1 WHERE sl_id = $2;', [newdescription, sl_id]);
|
||||
}
|
||||
|
||||
if(shoppinglist.color != newcolor) {
|
||||
if(shoppinglist.color != newcolor && newcolor != undefined) {
|
||||
await nonQuery('UPDATE "Shoppinglist" SET color = $1 WHERE sl_id = $2;', [newcolor, sl_id]);
|
||||
}
|
||||
}
|
||||
@ -158,7 +158,29 @@ async function addItem(group_id, sl_id, name, count) {
|
||||
}
|
||||
}
|
||||
|
||||
//Edit Group
|
||||
async function editGroup(sl_id, group_id, name, color, hidden) {
|
||||
try {
|
||||
let group = await query('SELECT row_to_json("Group") AS obj FROM "Group" WHERE group_id = $1 AND sl_id = $2', [sl_id, group_id]);
|
||||
|
||||
if(group.name != name && name != undefined) {
|
||||
await nonQuery('UPDATE "Group" SET name = $1 WHERE group_id = $2 AND sl_id = $3;', [name, group_id, sl_id]);
|
||||
}
|
||||
|
||||
if(group.color != color && color != undefined) {
|
||||
await nonQuery('UPDATE "Group" SET color = $1 WHERE group_id = $2 AND sl_id = $3;', [color, group_id, sl_id]);
|
||||
}
|
||||
|
||||
if(group.hidden != hidden && hidden != undefined) {
|
||||
await nonQuery('UPDATE "Group" SET hidden = $1 WHERE group_id = $2 AND sl_id = $3;', [hidden, group_id, sl_id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
// Invite System
|
||||
|
||||
@ -186,7 +208,6 @@ async function createInvite(sl_id) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//sl_id generieren
|
||||
function generate_sl_id() {
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
@ -257,5 +278,5 @@ function generateInviteLink() {
|
||||
|
||||
module.exports = {
|
||||
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
|
||||
addItem, verifyInvite, createInvite, renameShoppinglist
|
||||
addItem, verifyInvite, createInvite, editShoppinglist, editGroup
|
||||
}
|
||||
|
@ -211,9 +211,21 @@ router.get("/userinfo_json", (req, res) => {
|
||||
});
|
||||
|
||||
//Rename Shoppinglist
|
||||
router.put("/renamelist", async (req, res) => {
|
||||
router.put("/shoppinglist", async (req, res) => {
|
||||
try {
|
||||
res.status(200).send(await postgres.renameShoppinglist(req.body.sl_id, req.body.name, req.body.description, req.body.color));
|
||||
res.status(200).send(await postgres.editShoppinglist(req.body.sl_id, req.body.name, req.body.description, req.body.color));
|
||||
}
|
||||
|
||||
catch(err) {
|
||||
res.status(400).send(await err);
|
||||
}
|
||||
});
|
||||
|
||||
//Rename Group
|
||||
|
||||
router.put("/group", async (req, res) => {
|
||||
try {
|
||||
res.status(200).send(await postgres.editGroup(req.body.sl_id, req.body.group_id, req.body.name, req.body.color, req.body.hidden));
|
||||
}
|
||||
|
||||
catch(err) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user