forked from meJill/MP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
78 lines (66 loc) · 2.46 KB
/
Copy pathcontroller.js
File metadata and controls
78 lines (66 loc) · 2.46 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const db = require('../models/db.js');
const Transaction = require('../models/TransactionModel.js');
const app = require('../routes/routes.js');
const controller = {
getFavicon: function (req, res) {
res.status(204);
},
/*
TODO: This function is executed when the client sends an HTTP GET
request to path `/`. This displays `index.hbs` with all
transactions currently stored in the database.
*/
getIndex: function(req, res) {
db.findMany(Transaction, {}, {}, function(transactions){
res.render('main', {transactions}); // This is to load the page initially
})
},
/*
TODO: This function is executed when the client sends an HTTP GET
request to path `/getCheckRefNo`. This function checks if a
specific reference number is stored in the database. If the number
is stored in the database, it returns an object containing the
reference number, otherwise, it returns an empty string.
*/
getCheckRefNo: function(req, res) {
var ref = req.query.refno
console.log(req.query)
db.findOne(Transaction, {refno : ref}, {}, function(result){
// console.log(result);
res.send(result);
});
},
/*
TODO: This function is executed when the client sends an HTTP GET
request to path `/getAdd`. This function adds the transaction
sent by the client to the database, then appends the new
transaction to the list of transactions in `index.hbs`.
*/
getAdd: function(req, res) {
var iName = req.query.name;
var iRefno = req.query.refno;
var iAmount = req.query.amount;
var transaction = {
name: iName,
refno: iRefno,
amount: iAmount
};
db.insertOne(Transaction, transaction, function(result)
{
res.send(result)
});
},
/*
TODO: This function is executed when the client sends an HTTP GET
request to path `/getDelete`. This function deletes the transaction
from the database, then removes the transaction from the list of
transactions in `index.hbs`.
*/
getDelete: function (req, res) {
// console.log(req.query.refno)
db.deleteOne(Transaction, {refno: req.query.refno}, function(result){
res.send(result)
})
}
}
module.exports = controller;