/put item
Item bearbeiten
This commit is contained in:
		| @@ -182,6 +182,33 @@ async function editGroup(sl_id, group_id, name, color, hidden) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | //Edit Item | ||||||
|  |  | ||||||
|  | async function editItem(sl_id, group_id, item_id, name, count) { | ||||||
|  |  | ||||||
|  |     try { | ||||||
|  |         let item = query('SELECT row_to_json("Item") FROM "Item" WHERE item_id = $1 AND group_id = $2 AND sl_id = $3', [item_id, group_id, sl_id]); | ||||||
|  |  | ||||||
|  |         if(item.name != name && name != undefined) { | ||||||
|  |             await nonQuery('UPDATE "Item" SET name = $1 WHERE item_id = $2 AND group_id = $3 AND sl_id = $4', [name, item_id, group_id, sl_id]); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if(item.count != count && count != undefined) { | ||||||
|  |             await nonQuery('UPDATE "Item" SET count = $1 WHERE item_id = $2 AND group_id = $3 AND sl_id = $4', [count, item_id, group_id, sl_id]); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     catch (error) { | ||||||
|  |         console.error(error); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| // Invite System | // Invite System | ||||||
|  |  | ||||||
| async function verifyInvite(link, user_id) { | async function verifyInvite(link, user_id) { | ||||||
| @@ -208,6 +235,13 @@ async function createInvite(sl_id) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| //sl_id generieren | //sl_id generieren | ||||||
| function generate_sl_id() { | function generate_sl_id() { | ||||||
|     var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |     var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||||||
| @@ -278,5 +312,5 @@ function generateInviteLink() { | |||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup, |     getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup, | ||||||
|     addItem, verifyInvite, createInvite, editShoppinglist, editGroup |     addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem | ||||||
| } | } | ||||||
|   | |||||||
| @@ -233,6 +233,17 @@ router.put("/group", async (req, res) => { | |||||||
|   } |   } | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | router.put("/item", async (req, res) => { | ||||||
|  |   try { | ||||||
|  |     res.status(200).send(await postgres.editItem(req.body.sl_id, req.body.group_id, req.body.item_id, req.body.name, req.body.count)); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   catch(err) { | ||||||
|  |     res.status(400).send(await err); | ||||||
|  |   } | ||||||
|  | }); | ||||||
|  |  | ||||||
|  |  | ||||||
| // Invite System | // Invite System | ||||||
|  |  | ||||||
| router.post("/invite", async (req, res) => { | router.post("/invite", async (req, res) => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user