Userdaten in db einfügen, user suchfunktion

This commit is contained in:
Lukas Nowy
2019-02-20 21:50:21 +01:00
parent 4ed6ae52bf
commit 8089359741
3 changed files with 71 additions and 6 deletions

View File

@ -4,9 +4,9 @@ const stringSimilarity = require('string-similarity');
//Create User Info
async function updateUser(uid, mid) {
async function updateUser(uid, mid, name, picture, email) {
try {
await nonQuery('INSERT INTO "User" (username, message_id) VALUES ($1, $2);', [uid, mid]);
await nonQuery('INSERT INTO "User" (username, message_id, name, picture, email) VALUES ($1, $2, $3, $4, $5);', [uid, mid, name, picture, email]);
}
@ -28,6 +28,22 @@ async function getmessageids(sl_id) {
}
}
async function searchUsers(searchstring) {
try {
let users = await query('SELECT row_to_json("User") AS obj FROM "User";');
return users.filter(function(obj) {return obj.name.toUpperCase().includes(searchstring.toUpperCase())});
}
catch(error) {
console.error(error);
}
}
//SELECT own shopping lists
async function getShoppinglistsAdmin(username) {
try {
@ -534,5 +550,5 @@ function probability(cur_item, data) {
module.exports = {
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem, deleteGroup, deleteItem, manInvite, updateUser,
moveDoneItems, getDonePurchases, getShoppinglistsByLink
moveDoneItems, getDonePurchases, getShoppinglistsByLink, searchUsers
}