-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.js
119 lines (80 loc) · 2.57 KB
/
database.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* Created by sandeep on 17/07/17.
*/
var mdb = require('mongodb');
var url = 'mongodb://localhost/expenso';
var _db = "";
var name = "";
function connectDB(run_server) {
mdb.MongoClient.connect(url,function (err,db) {
if(err) throw err;
console.log('connected to db');
_db = db;
run_server();
});
}
function get(info,cb) {
name = info.user;
_db.collection(info.user).find({_id: info.id}).toArray(function (err, data) {
cb(data);
});
}
function insertT(info,cb) {
_db.collection(info.user).updateOne({ _id : "2" },{ $push : { passbook : info.trns } },{ upsert: true},function(err,res){
cb(res);
});
}
function insertP(info,cb) {
_db.collection(info.user).updateOne({ _id : "3" },{ $push : { pending : info.pend } },{ upsert: true},function(err,res){
cb(res);
});
}
function deletePassbook(info,cb) {
_db.collection(info.user).updateOne({_id : "2" },{$pull:{"passbook": {"desp":info.up }}},function(err,res){
cb(res);
});
}
function deletePending(info,cb) {
_db.collection(info.user).updateOne({_id : "3" },{$pull:{"pending": {"desp":info.up }}},function(err,res){
cb(res);
});
}
function editPassbook(info,cb) {
console.log(info.p);
_db.collection(name).updateOne({_id : "2", "passbook.desp" : info.p.desp },
{ $set: {'passbook.$.bank' : info.n.bank, 'passbook.$.desp' : info.n.desp,
'passbook.$.sign' : info.n.sign , 'passbook.$.amt' : info.n.amt}}
,function (err,res) {
cb(res);
});
}
function editPending(info,cb) {
console.log(info.p);
_db.collection(name).updateOne({_id : "3", "pending.desp" : info.p.desp },
{ $set: {'pending.$.desp' : info.n.desp, 'pending.$.d_date' : info.n.ddate , 'pending.$.amt' : info.n.amt}}
,function (err,res) {
cb(res);
});
}
function settingsForm(info,cb) {
_db.collection(info.user).updateOne({_id : "1"},{settings : info.set},{upsert : true},function (err,res) {
cb(res);
});
}
function picture(file,cb) {
_db.collection(name).updateOne({_id : "4"},{picture : file},{upsert : true},function (err,res) {
cb(res);
});
}
module.exports = {
connectDB : connectDB,
get : get,
settingsForm : settingsForm,
insertT : insertT,
insertP : insertP,
deletePassbook : deletePassbook,
deletePending : deletePending,
editPassbook : editPassbook,
editPending : editPending,
picture: picture
};