diff options
author | Mark Powers <markppowers0@gmail.com> | 2020-11-19 20:45:18 -0600 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2020-11-19 20:45:18 -0600 |
commit | 3b2fd5d0d684cd78ece02dc4a9583b92ed431850 (patch) | |
tree | 7947f2702b24ffbed2cd603d2910939a2ebee12e /src/server/index.js | |
parent | a227e15d79f545ad84c3113dddeedcd87ff955a1 (diff) |
Update expected pages to include in/out/net
Diffstat (limited to 'src/server/index.js')
-rw-r--r-- | src/server/index.js | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/server/index.js b/src/server/index.js index 75c00d1..c34e9d6 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -145,15 +145,34 @@ function setUpRoutes(models, jwtFunctions, database, templates) { server.get(`/expected`, async (req, res, next) => { try { let expecteds = await database.query(`SELECT * FROM expecteds WHERE username = '${res.locals.user.username}' ORDER BY \`name\` DESC`, { type: database.QueryTypes.SELECT }) - let day_average = 0 + let day_in = 0 + let day_out = 0 expecteds.forEach((element, i) => { element.index = i + 1 - day_average += (element.total / element.days) + let day = (element.total / element.days) + if(day < 0) { // negative since that is income + day_in += day; + } else { + day_out += day; + } }); + let day_net = day_in + day_out; let name = res.locals.user.username - let week = Math.round(day_average * 7) - let month = Math.round(day_average * 31) - let year = Math.round(day_average * 365) + let week = { + net: Math.round(day_net * 7), + in: Math.round(day_in * 7), + out: Math.round(day_out * 7), + } + let month = { + net: Math.round(day_net * 31), + in: Math.round(day_in * 31), + out: Math.round(day_out * 31), + } + let year = { + net: Math.round(day_net * 365), + in: Math.round(day_in * 365), + out: Math.round(day_out * 365), + } let body = templates["expected"]({ name, expecteds, week, month, year }) res.status(200).send(body); } catch (e) { |