add groups, add items
This commit is contained in:
@ -109,6 +109,33 @@ async function deleteShoppinglist(sl_id) {
|
||||
}
|
||||
}
|
||||
|
||||
//add group into shoppinglist
|
||||
|
||||
async function addGroup(sl_id, name, color) {
|
||||
try {
|
||||
let grid = generate_group_id();
|
||||
await nonQuery('INSERT INTO "Group" VALUES ($1, $2, $3, $4);', [grid, sl_id, name, color]);
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
//add item into group
|
||||
|
||||
async function addItem(group_id, sl_id, name, count) {
|
||||
try {
|
||||
let itid = generate_item_id();
|
||||
await nonQuery('INSERT INTO "Item" VALUES ($1, $2, $3, $4, $5);', [itid, group_id, sl_id, name, count]);
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//sl_id generieren
|
||||
function generate_sl_id() {
|
||||
@ -122,6 +149,30 @@ function generate_sl_id() {
|
||||
return output;
|
||||
}
|
||||
|
||||
//group_id generieren
|
||||
function generate_group_id() {
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
var output = "";
|
||||
|
||||
for(let i = 0; i < 8; i++) {
|
||||
output += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
//item_id generieren
|
||||
function generate_item_id() {
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
var output = "";
|
||||
|
||||
for(let i = 0; i < 8; i++) {
|
||||
output += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
function items_in_groups(groups, items) {
|
||||
|
||||
let result = [];
|
||||
@ -140,5 +191,6 @@ function items_in_groups(groups, items) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist
|
||||
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
|
||||
addItem
|
||||
}
|
||||
|
Reference in New Issue
Block a user