From 35b6d276bdeabdf7bf5eee59d85dfefee7531fce Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Wed, 7 Oct 2020 10:54:15 -0500 Subject: Add expected expenses --- src/server.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/server.js') diff --git a/src/server.js b/src/server.js index 69d3968..f72f21b 100644 --- a/src/server.js +++ b/src/server.js @@ -163,6 +163,29 @@ function setUpRoutes(models, jwtFunctions, database) { res.status(400).send(e.message); } }) + server.get(`/expected`, async (req, res, next) => { + try { + var result = await database.query("SELECT * FROM expecteds WHERE username = '" + res.locals.user.username + "' ORDER BY `name` DESC", { type: database.QueryTypes.SELECT }) + res.status(200).send(result); + next(); + } catch (e) { + console.log(e) + res.status(400).send(e.message); + } + }) + server.post(`/expected`, async (req, res, next) => { + try { + let item = req.body; + console.log(item); + item.username = res.locals.user.username + await models.expected.create(item); + var result = await database.query("SELECT * FROM expecteds WHERE username = '" + res.locals.user.username + "' ORDER BY `name` DESC", { type: database.QueryTypes.SELECT }) + res.status(200).send(result); + } catch (e) { + console.log(e); + res.status(400).send(e.message); + } + }) server.get(`/summary`, async (req, res, next) => { try { res.status(200).send({ -- cgit v1.2.3