menual invite, get uids from shoppinglist
This commit is contained in:
@ -1,5 +1,40 @@
|
||||
const { query, nonQuery } = require("../db-config/postgresql-common");
|
||||
|
||||
//Create User Info
|
||||
|
||||
async function updateUser(uid, mid) {
|
||||
try {
|
||||
let exists = await query('SELECT row_to_json(username) FROM "User" As obj WHERE username = $1;', [uid]);
|
||||
|
||||
//existiert
|
||||
if(exists != undefined) {
|
||||
await nonQuery('UPDATE "User" SET message_id = $1 WHERE username = $2', [mid, uid]);
|
||||
}
|
||||
|
||||
//existiert nicht
|
||||
else {
|
||||
await nonQuery('INSERT INTO "User" (username, message_id) VALUES ($1, $2);', [uid, mid]);
|
||||
}
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function getmessageids(sl_id) {
|
||||
try {
|
||||
let members = query('SELECT * FROM "Shoppinglist_member" WHERE sl_id = $1;', [sl_id]);
|
||||
let admin = query('SELECT * FROM "Shoppinglist_admin" WHERE sl_id = $1;', [sl_id]);
|
||||
return users_to_array(admin, members);
|
||||
|
||||
}
|
||||
|
||||
catch(error) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//SELECT own shopping lists
|
||||
async function getShoppinglistsAdmin(username) {
|
||||
try {
|
||||
@ -242,7 +277,6 @@ async function verifyInvite(link, user_id) {
|
||||
try {
|
||||
let result = await query('SELECT row_to_json("Shoppinglist") AS obj FROM "Shoppinglist" WHERE invitelink = $1;', [link]);
|
||||
let sl_id = result[0].sl_id;
|
||||
console.log(result[0].sl_id);
|
||||
await nonQuery('INSERT INTO "Shoppinglist_member" (username, sl_id) VALUES ($1, $2);', [user_id, sl_id]);
|
||||
}
|
||||
|
||||
@ -262,6 +296,16 @@ async function createInvite(sl_id) {
|
||||
}
|
||||
}
|
||||
|
||||
async function manInvite(sl_id, uid) {
|
||||
try {
|
||||
await nonQuery('INSERT INTO "Shoppinglist_member" (username, sl_id) VALUES ($1, $2);', [uid, sl_id]);
|
||||
}
|
||||
|
||||
catch(error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -337,7 +381,19 @@ function generateInviteLink() {
|
||||
return output;
|
||||
}
|
||||
|
||||
function users_to_array(admin, members) {
|
||||
let users = [];
|
||||
|
||||
users.push(admin.username);
|
||||
|
||||
for(let item of members) {
|
||||
users.push(item.username);
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
|
||||
addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem, deleteGroup, deleteItem
|
||||
addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem, deleteGroup, deleteItem, manInvite, updateUser
|
||||
}
|
||||
|
Reference in New Issue
Block a user