-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimp.txt
176 lines (131 loc) · 4.03 KB
/
imp.txt
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
process.env.MONGO_URL
mongodb Atlas - [email protected]
deployed in - [email protected]
'mongodb://127.0.0.1:27017/ExpenseApp'
inline fold extension mohamad almairi
console.log(require('dotenv').config());
------ design refrence -----
https://in.pinterest.com/pin/825284700477985507/
https://in.pinterest.com/pin/1041950063772439997/2
const uploadOnCloudinary = async (localFilePath) => {
try {
if (!localFilePath) return null
//upload the file on cloudinary
const response = await cloudinary.uploader.upload(localFilePath, {
resource_type: "auto"
})
// file has been uploaded successfull
//console.log("file is uploaded on cloudinary ", response.url);
fs.unlinkSync(localFilePath)
return response;
} catch (error) {
fs.unlinkSync(localFilePath) // remove the locally saved temporary file as the upload operation got failed
return null;
}
}
router.get('/search-expenses', isLoggedIn, async function (req, res, next) {
try {
let { expenses } = await req.user.populate('expenses');
expenses = expenses.filter( (e) => {
console.log(e);
return e[req.query.key] == req.query.value
});
res.render('transaction', { admin: req.user, expenses });
} catch (error) {
console.log(error);
res.send(error);
}
});
router.get('/search-expenses', isLoggedIn, async function (req, res, next) {
try {
let search = '';
if (req.query.search) {
search = req.query.search;
}
let expenses = function () {
expenses = req.user.populate('expenses');
expenses = expenses.find({
$or: [
{ amount: { $regex: '.*' + search + '.*', $options: 'i' } },
{ remark: { $regex: '.*' + search + '.*', $options: 'i' } },
{ category: { $regex: '.*' + search + '.*', $options: 'i' } },
{ paymentmode: { $regex: '.*' + search + '.*', $options: 'i' } },
],
});
return expenses;
};
res.render('transaction', { admin: req.user, expenses });
} catch (error) {
console.log(error);
res.send(error);
}
});
router.post(
'/uploadimg',
isLoggedIn,
upload.single('image'),
async function (req, res, next) {
const onUser = await User.findOne({ username: req.session.passport.user });
console.log(onUser);
try {
const result = await cloudinary.uploader.upload(req.file.path, {
public_id: `${onUser._id}_logo`,
});
req.file.filename = result.url;
onUser.logo = req.file.filename;
onUser.save().then(function () {
res.redirect('back');
});
} catch (error) {
console.log(error);
}
}
);
const expenses = User.findOne({
username: req.session.passport.user,
}).populate({
path: 'expenses',
populate: {
path: 'amount remark category paymentmode',
$or: [
{ amount: { $regex: '.*' + search + '.*', $options: 'i' } },
{ remark: { $regex: '.*' + search + '.*', $options: 'i' } },
{ category: { $regex: '.*' + search + '.*', $options: 'i' } },
{ paymentmode: { $regex: '.*' + search + '.*', $options: 'i' } },
]
},
});
router.get('/transaction', isLoggedIn, async function (req, res, next) {
try {
let { expenses } = await req.user.populate('expenses');
let { income } = await req.user.populate('income');
// console.log(req.user, expenses, income);
res.render('transaction', { admin: req.user, expenses, income });
} catch (error) {
res.send(error);
}
});
let search='';
if(!req.query.search){
search = req.query.search
}
const expenses = User.findOne({
username: req.session.passport.user,
}).populate({
path: 'expenses',
populate: {
path: 'amount remark category paymentmode',
$or: [
{ amount: { $regex: '.*' + search + '.*', $options: 'i' } },
{ remark: { $regex: '.*' + search + '.*', $options: 'i' } },
{ category: { $regex: '.*' + search + '.*', $options: 'i' } },
{ paymentmode: { $regex: '.*' + search + '.*', $options: 'i' } },
]
},
});
res.json(expenses)
const resul = expenses.map(function(exp){
return exp.createdAt;
})
console.log(expenses);
console.log(resul);