Skip to content

Commit

Permalink
#139 Added server side code
Browse files Browse the repository at this point in the history
  • Loading branch information
nohorjo committed Aug 26, 2018
1 parent 22f783d commit 8638d86
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "centsa",
"version": "2.11.1",
"version": "2.11.2",
"description": "Centsa money managing solution",
"main": "src/index.js",
"directories": {
Expand Down
30 changes: 25 additions & 5 deletions src/General.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ route.get("/budget", (req, resp) => {
const { userData : { user_id } } = req.session;
const today:any = new Date(req.get('x-date'));
log('get budget', mode);
const respond = budget => {
log('returning budget');
if (+mode.cashflowPeriod) {
getSummary(user_id, {
fromDate: new Date(today - 8.64e7 * mode.cashflowPeriod),
toDate: today,
}, (err, data) => {
if (err) {
log.error(err);
resp.status(500).send(err);
} else {
const max = -data[0].sum;
resp.send({
afterAll: Math.min(max, budget.afterAll),
afterAuto: Math.min(max, budget.afterAuto)
});
}
});
} else {
resp.send(budget);
}
};
switch (mode.mode) {
case 'expense': case 'strictExpense':
getAllWithSum(user_id, (err, results) => {
Expand Down Expand Up @@ -63,8 +85,7 @@ route.get("/budget", (req, resp) => {
afterAuto: results[0][0].total
}
);
log('returning budget');
resp.send(budget);
respond(budget);
}
});
break;
Expand All @@ -79,8 +100,7 @@ route.get("/budget", (req, resp) => {
resp.status(500).send(err);
} else {
const days = (today - start) / DAY;
log('returning budget');
resp.send({afterAll: Math.ceil(days / mode.frequency) * mode.amount - sum});
respond({afterAll: Math.ceil(days / mode.frequency) * mode.amount - sum});
}
});
break;
Expand Down Expand Up @@ -110,7 +130,7 @@ route.get("/budget", (req, resp) => {
}

log('returning budget');
resp.send({afterAll, afterAuto});
respond({afterAll, afterAuto});
}
});
break;
Expand Down
1 change: 1 addition & 0 deletions static/summary/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ <h4>Summary</h4>
<option value="0">Never</option>
<option value="7">Week</option>
<option value="30">Month</option>
<option value="90">Quarter</option>
</select>
</td>
</tr>
Expand Down

0 comments on commit 8638d86

Please sign in to comment.