Userdaten in db einfügen, user suchfunktion
This commit is contained in:
parent
4ed6ae52bf
commit
8089359741
@ -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
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ var config = {
|
||||
getAllShoppinglists();
|
||||
|
||||
updateUser();
|
||||
displayShoppinglist();
|
||||
testSearch();
|
||||
|
||||
|
||||
|
||||
@ -110,6 +110,40 @@ function updateProgress(percent) {
|
||||
|
||||
}
|
||||
|
||||
function updateUser() {
|
||||
firebase.auth().onAuthStateChanged(function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/user",
|
||||
data:{
|
||||
idtoken: idtoken,
|
||||
message_id: "msgtest"
|
||||
},
|
||||
success(){
|
||||
console.log("USer updated");
|
||||
},
|
||||
error(err){
|
||||
console.error("Error: " + err);
|
||||
}
|
||||
});
|
||||
}).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
|
||||
}
|
||||
|
||||
function testSearch() {
|
||||
console.log("dpne");
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/users?search=Lukas",
|
||||
success(data) {
|
||||
console.log(data);
|
||||
},
|
||||
error(err) {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getAllShoppinglists() {
|
||||
firebase.auth().onAuthStateChanged(function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
|
||||
$.ajax({
|
||||
|
@ -398,8 +398,11 @@ router.post("/user", async function(req, res, next) {
|
||||
firebaseAdmin.auth().verifyIdToken(token)
|
||||
.then(async function(decodedToken) {
|
||||
uid = decodedToken.uid;
|
||||
console.log("UID: ", uid);
|
||||
console.log("So andere sachen: ", req.body.name, req.body.description);
|
||||
try {
|
||||
res.status(200).send(await postgres.updateUser(uid, req.body.message_id));
|
||||
|
||||
res.status(200).send(await postgres.updateUser(uid, req.body.message_id, decodedToken.name, decodedToken.picture, decodedToken.email));
|
||||
}
|
||||
|
||||
catch(err) {
|
||||
@ -408,7 +411,19 @@ router.post("/user", async function(req, res, next) {
|
||||
}).catch(function(error) {
|
||||
console.log(error)
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/users", async (req, res) => {
|
||||
try {
|
||||
res.status(200).send(await postgres.searchUsers(req.query.search));
|
||||
}
|
||||
|
||||
catch(err) {
|
||||
res.status(400).send(err);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
//postgres.updateUser("testuser2", "einemessageid");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user