-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
43 lines (35 loc) · 1.02 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module.exports = (expenses) => {
const home = (req, res) => {
res.render('index');
}
const addExpenses = async (req, res) => {
let name = req.body.userName;
let category = req.body.category;
let date = req.body.day;
let amount = req.body.amount;
await expenses.setName(name);
let userId = await expenses.userId(name);
let categoriesId = await expenses.categoryId(category);
await expenses.setExpenses(userId, categoriesId, amount, date)
res.redirect('back')
}
const getExpenses = async (req, res) => {
let name = req.params.name;
let data = await expenses.returnExpenses(name);
res.render('expenses', {
data
})
}
const uniqueNames = async (req, res) => {
let uniqueNames = await expenses.namesList()
res.render('enteredExpenses', {
uniqueNames
})
}
return {
home,
addExpenses,
getExpenses,
uniqueNames
}
}