Einkaufsliste erstellen + ausgabe mit user acconts

This commit is contained in:
Lukas Nowy
2018-10-27 20:03:07 +02:00
parent 8e7d96310f
commit bd4053054a
3 changed files with 70 additions and 3 deletions

View File

@ -47,6 +47,7 @@ router.get('/logout', (req, res) => {
router.get('/dash', function(req, res, next) {
console.log("Session: ", req.session.passport.user.token);
console.log("User ID: " + req.session.passport.user.profile.id);
if (req.session.passport.user.token) {
res.render('index');
} else {
@ -59,7 +60,7 @@ router.get('/dash', function(req, res, next) {
router.get("/myshoppinglists", async function(req, res, next) {
try {
//Get user id: req.session.passport.user.profile.id
res.status(200).send(await postgres.getShoppinglistsAdmin("testuser"));
res.status(200).send(await postgres.getShoppinglistsAdmin(req.session.passport.user.profile.id));
}
catch(err) {
@ -73,7 +74,7 @@ router.get("/myshoppinglists", async function(req, res, next) {
router.get("/sharedshoppinglists", async function(req, res, next) {
try {
//Get user id: req.session.passport.user.profile.id
res.status(200).send(await postgres.getShoppinglistsShared("testuser"));
res.status(200).send(await postgres.getShoppinglistsShared(req.session.passport.user.profile.id));
}
catch(err) {
@ -82,4 +83,16 @@ router.get("/sharedshoppinglists", async function(req, res, next) {
});
//POST new shoppinglist
router.post("/shoppinglist", async function(req, res, next) {
try {
res.status(200).send(await postgres.newShoppinglist(req.body.name, req.body.description, req.session.passport.user.profile.id));
}
catch(err) {
res.status(400).send(await err);
}
});
module.exports = router;