menual invite, get uids from shoppinglist
This commit is contained in:
		@@ -1,5 +1,40 @@
 | 
				
			|||||||
const { query, nonQuery } = require("../db-config/postgresql-common");
 | 
					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
 | 
					//SELECT own shopping lists
 | 
				
			||||||
async function getShoppinglistsAdmin(username) {
 | 
					async function getShoppinglistsAdmin(username) {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
@@ -242,7 +277,6 @@ async function verifyInvite(link, user_id) {
 | 
				
			|||||||
    try {
 | 
					    try {
 | 
				
			||||||
        let result = await query('SELECT row_to_json("Shoppinglist") AS obj FROM "Shoppinglist" WHERE invitelink = $1;', [link]);
 | 
					        let result = await query('SELECT row_to_json("Shoppinglist") AS obj FROM "Shoppinglist" WHERE invitelink = $1;', [link]);
 | 
				
			||||||
        let sl_id = result[0].sl_id;
 | 
					        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]);
 | 
					        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;
 | 
					    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 = {
 | 
					module.exports = {
 | 
				
			||||||
    getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
 | 
					    getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
 | 
				
			||||||
    addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem, deleteGroup, deleteItem
 | 
					    addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem, deleteGroup, deleteItem, manInvite, updateUser
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,6 +26,16 @@ msg.requestPermission()
 | 
				
			|||||||
    console.error("Msg Error: ", err)
 | 
					    console.error("Msg Error: ", err)
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					axios.post('/user', {
 | 
				
			||||||
 | 
					    message_id: 'test',
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  .then(function (response) {
 | 
				
			||||||
 | 
					    console.log(response);
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  .catch(function (error) {
 | 
				
			||||||
 | 
					    console.log(error);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
msg.onMessage(payload => {
 | 
					msg.onMessage(payload => {
 | 
				
			||||||
    const title = payload.data.title
 | 
					    const title = payload.data.title
 | 
				
			||||||
    new Notification(title, { body: payload.data.text});
 | 
					    new Notification(title, { body: payload.data.text});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -71,6 +71,14 @@ var vue = new Vue({
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    mounted() {
 | 
					    mounted() {
 | 
				
			||||||
        
 | 
					        axios.post('/user', {
 | 
				
			||||||
 | 
					            message_id: 'test',
 | 
				
			||||||
 | 
					          })
 | 
				
			||||||
 | 
					          .then(function (response) {
 | 
				
			||||||
 | 
					            console.log(response);
 | 
				
			||||||
 | 
					          })
 | 
				
			||||||
 | 
					          .catch(function (error) {
 | 
				
			||||||
 | 
					            console.log(error);
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
@@ -301,6 +301,25 @@ router.post("/invite", async (req, res) => {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					router.post("/maninvite", async (req, res) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  var token = req.query.idtoken;
 | 
				
			||||||
 | 
					  var uid;
 | 
				
			||||||
 | 
					  firebaseAdmin.auth().verifyIdToken(token)
 | 
				
			||||||
 | 
					    .then(function(decodedToken) {
 | 
				
			||||||
 | 
					      uid = decodedToken.uid;
 | 
				
			||||||
 | 
					      console.log("UID: ", uid);
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
 | 
					        res.status(200).send(postgres.manInvite(req.body.sl_id, uid));
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      catch(err) {
 | 
				
			||||||
 | 
					        console.log(error);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }).catch(function(error) {
 | 
				
			||||||
 | 
					      console.log(error)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
router.get("/invite/:link", async (req, res) => {
 | 
					router.get("/invite/:link", async (req, res) => {
 | 
				
			||||||
  var token = req.query.idtoken;
 | 
					  var token = req.query.idtoken;
 | 
				
			||||||
  var uid;
 | 
					  var uid;
 | 
				
			||||||
@@ -320,6 +339,29 @@ router.get("/invite/:link", async (req, res) => {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//Update User
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					router.post("/user", async (req, res) => {
 | 
				
			||||||
 | 
					  var token = req.query.idtoken;
 | 
				
			||||||
 | 
					  var uid;
 | 
				
			||||||
 | 
					  firebaseAdmin.auth().verifyIdToken(token)
 | 
				
			||||||
 | 
					    .then(function(decodedToken) {
 | 
				
			||||||
 | 
					      uid = decodedToken.uid;
 | 
				
			||||||
 | 
					      console.log("UID: ", uid);
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
 | 
					        postgres.updateUser(uid, req.body.message_id);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      catch(err) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }).catch(function(error) {
 | 
				
			||||||
 | 
					      console.log(error)
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
router.get("/scan/", async (req, res,) => {
 | 
					router.get("/scan/", async (req, res,) => {
 | 
				
			||||||
  res.render("ocrscan");
 | 
					  res.render("ocrscan");
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user