Revert "Merge branch 'master' of https://github.com/LukasNowy/SmartShopper"
This reverts commit 6ee5de3477c87d43d8ba7f41d95263e8e81225a6, reversing changes made to d7491e863750b4563644135b69b987fa9b4c2c5b.
This commit is contained in:
parent
6ee5de3477
commit
84afb3f32d
@ -1,6 +1,5 @@
|
||||
const { query, nonQuery } = require("../db-config/postgresql-common");
|
||||
|
||||
//SELECT own shopping lists
|
||||
async function getShoppinglistsAdmin(username) {
|
||||
try {
|
||||
|
||||
@ -15,8 +14,6 @@ async function getShoppinglistsAdmin(username) {
|
||||
}
|
||||
}
|
||||
|
||||
//SELECT shared shopping lists
|
||||
|
||||
async function getShoppinglistsShared(username) {
|
||||
try {
|
||||
let result = await query('SELECT row_to_json("Shoppinglist") AS obj FROM "Shoppinglist" JOIN "Shoppinglist_member" USING (sl_id) WHERE \
|
||||
@ -30,46 +27,7 @@ async function getShoppinglistsShared(username) {
|
||||
}
|
||||
}
|
||||
|
||||
//INSERT new Shoppinglist
|
||||
|
||||
async function newShoppinglist(name, description, username) {
|
||||
|
||||
//generate sl_id
|
||||
|
||||
let sl_id = generate_sl_id();
|
||||
|
||||
//insert shoppinglist
|
||||
try {
|
||||
await nonQuery('INSERT INTO "Shoppinglist" (sl_id, name, description) VALUES ($1, $2, $3);', [sl_id, name, description]);
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
|
||||
//insert admin
|
||||
try {
|
||||
await nonQuery('INSERT INTO "Shoppinglist_admin" (username, sl_id) VALUES ($1, $2);', [username, sl_id]);
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//sl_id generieren
|
||||
function generate_sl_id() {
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
var output = "";
|
||||
|
||||
for(let i = 0; i < 8; i++) {
|
||||
output += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist
|
||||
getShoppinglistsAdmin, getShoppinglistsShared
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
$(document).ready(function() {
|
||||
//DELETE THIS
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/shoppinglist",
|
||||
data: {
|
||||
name: "Name Test",
|
||||
description: "Description Test"
|
||||
}
|
||||
});
|
||||
// ---
|
||||
});
|
@ -49,7 +49,6 @@ 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 {
|
||||
@ -62,7 +61,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(req.session.passport.user.profile.id));
|
||||
res.status(200).send(await postgres.getShoppinglistsAdmin("testuser"));
|
||||
}
|
||||
|
||||
catch(err) {
|
||||
@ -76,7 +75,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(req.session.passport.user.profile.id));
|
||||
res.status(200).send(await postgres.getShoppinglistsShared("testuser"));
|
||||
}
|
||||
|
||||
catch(err) {
|
||||
@ -85,16 +84,4 @@ 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user