-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
212 lines (187 loc) · 5.61 KB
/
Copy pathapp.js
File metadata and controls
212 lines (187 loc) · 5.61 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
var express = require('express');
var app = express();
var mongoJs = require('mongoJs');
var ObjectId = require('mongodb').ObjectId;
var db = mongoJs('support_system', ['Users', 'userQueries', 'Conversation']);
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
app.use(express.static(__dirname + '/public'));
//get user data for login form...
app.post('/loginUser', function (req, res) {
var data = JSON.parse(req.query.data);
db.Users.find({
user_name: data.username,
password: data.password
}, function (err, docs) {
if (err) console.log("error: " + err);
else {
res.send(docs);
}
})
})
//post a new user in user table...
app.post('/addUser', function (req, res) {
var data = JSON.parse(req.query.data);
db.Users.insert(data, function (err, doc) {
if (err) throw err;
else
res.send(200);
})
}); //end of ADDUser
//add a User query...
app.post('/addNewQuery', function (req, res) {
var data = JSON.parse(req.query.data);
db.userQueries.insert(data, function (err, doc) {
if (err) throw err;
else {
res.send(200);
}
})
}); //end of add NewQuery...
app.get('/getQueryByUser/:user_name', function (req, res) {
var user = req.params.user_name;
db.userQueries.find({
"user_name": user
}, function (err, docs) {
if (err) console.log("error: " + err);
else {
res.send(docs);
}
})
});
// get query detail by Id
app.get('/getQueryById/:queryId', function (req, res) {
var queryId = req.params.queryId;
db.userQueries.find(ObjectId(queryId), function (err, docs) {
if (err) console.log("error: " + err);
else {
res.send(docs);
}
})
});
//get Query by username and id both...
app.get('/getQueryByUserId/:user/:id', function (req, res) {
var username = req.params.user;
var queryId = req.params.id;
db.userQueries.find({
_id: ObjectId(queryId),
user_name: username
}, function (err, docs) {
if (err) console.log("error: " + err);
else {
res.send(docs);
}
})
}) //end of getAllQueries...
//get all User Queries...
app.get('/getAllQueries', function (req, res) {
db.userQueries.find(function (err, docs) {
if (err) console.log("error: " + err);
else {
res.send(docs);
}
})
}) //end of getAllQueries...
//post Conversation in db
app.post('/addConversation', function (req, res) {
var data = JSON.parse(req.query.data);
db.Conversation.insert(data, function (err, doc) {
if (err) throw err;
else {
res.send(200);
}
});
})
app.get('/getConversationById/:queryId', function (req, res) {
var id = req.params.queryId;
db.Conversation.find({
queryId: id
}, function (err, docs) {
if (err) console.log("error: " + err);
else {
res.send(docs);
}
})
})
app.post('/sendGuestEmail', function (req, res) {
var data = JSON.parse(req.query.data);
// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport(smtpTransport({
host: "localhost", // hostname
secure: false, // use SSL
port: 3000, // port for secure SMTP
service: 'gmail',
auth: {
user: 'baigny@gmail.com',
pass: '13nyb89baig'
},
tls: {
rejectUnauthorized: false
}
}));
// setup e-mail data with unicode symbols
var mailOptions = {
from: 'baigny@gmail.com', // sender address
to: 'baigny@gmail.com', // list of receivers
subject: 'Guest mail from support_system ✔', // Subject line
text: 'test upgrde nodemailer subject', // plaintext body
html: '<h4>Contact : ' + data.querySub + '</h4>' +
'<h4>Name : ' + data.name + '</h4>' +
'<h4>Email : ' + data.email + '</h4>' +
'<h4>Contact : ' + data.phone + '</h4>' +
'<h4>Message : </h4><p>' + data.query + '</p>' //html body ends...
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
return console.log(error);
}
console.log('Message sent: ' + info.response);
res.send(200);
});
})
//update the status of queries...
app.get('/updateStatus/:queryId/:status', function (req, res) {
var id = req.params.queryId;
var status_value = req.params.status;
db.userQueries.update({
_id: ObjectId(id)
}, {
$set: {
status: status_value
}
}, {
multi: true
}, function (err, docs) {
if (err) console.log(err);
else
console.log(docs);
});
});
app.post('/editUserQueries', function (req, res) {
var data = JSON.parse(req.query.data);
db.userQueries.update({
_id: ObjectId(data.queryId)
}, {
$set: {
querySub: data.querySub,
query : data.query
}
},function (err, docs) {
if (err) console.log(err);
else
res.send(200);
});
});
app.get('/deleteUserQueries/:id', function (req, res) {
var id=req.params.id;
db.userQueries.remove({_id: ObjectId(id)},
function(err,docs){
if (err) console.log(err);
else
res.send(200);
});
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})