rename shoppinglist

This commit is contained in:
Lukas Nowy 2019-01-12 15:13:41 +01:00
parent 6f0e230e10
commit bf07e39660
2 changed files with 36 additions and 6 deletions

View File

@ -67,6 +67,27 @@ async function newShoppinglist(name, description, username, color) {
}
}
//rename Shoppinglist
async function renameShoppinglist(sl_id, newname, newdescription) {
try {
let shoppinglist = await query('SELECT row_to_json("Shoppinglist") AS obj FROM "Shoppinglist" WHERE sl_id = $1;', [sl_id]);
if(shoppinglist.name != newname) {
await nonQuery('UPDATE "Shoppinglist" SET name = $1 WHERE sl_id = $2;', [newname, sl_id]);
}
if(shoppinglist.description != newdescription) {
await nonQuery('UPDATE "Shoppinglist" SET description = $1 WHERE sl_id = $2;', [newdescription, sl_id]);
}
}
catch (error) {
console.error(error);
}
}
async function generateUser() {
//insert user
@ -133,6 +154,8 @@ async function addItem(group_id, sl_id, name, count) {
}
}
// Invite System
async function verifyInvite(link, user_id) {
@ -160,10 +183,6 @@ async function createInvite(sl_id) {
}
//sl_id generieren
function generate_sl_id() {
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@ -234,5 +253,5 @@ function generateInviteLink() {
module.exports = {
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
addItem, verifyInvite, createInvite
addItem, verifyInvite, createInvite, renameShoppinglist
}

View File

@ -195,7 +195,7 @@ router.post("/item", async (req, res) => {
});
router.get("/test1", (req, res) => {
res.render("index1");
res.render("test");
});
router.get("/userinfo_json", (req, res) => {
@ -210,6 +210,17 @@ router.get("/userinfo_json", (req, res) => {
});
});
//Rename Shoppinglist
router.put("/renamelist", async (req, res) => {
try {
res.status(200).send(await postgres.renameShoppinglist(req.body.sl_id, req.body.name, req.body.description));
}
catch(err) {
res.status(400).send(await err);
}
});
// Invite System
router.post("/invite", async (req, res) => {