-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
357 lines (330 loc) · 10.3 KB
/
server.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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
const express = require("express");
const app = express();
const fileuploader = require("express-fileupload");
const mysql2 = require("mysql2");
app.listen(2709, function () {
console.log("Server STARTED at 2709 :)");
});
app.use(express.urlencoded({ extended: true }));
app.use(fileuploader());
app.use(express.static("Frontend"));
const objConfig = {
host: "sql12.freesqldatabase.com",
user: "sql12717182",
password: "PqbuFjwic5",
database: "sql12717182",
dateStrings: true, //isse hum date ko bhi fetch kr paate hain
};
const mysql = mysql2.createConnection(objConfig);
mysql.connect(function (err) {
if (err == null){
console.log("Connected to database");}
else console.log(err.message);
});
app.get("/", function (req, resp) {
let filepath = process.cwd() + "/Frontend/html/login.html";
resp.sendFile(filepath);
});
//create table users (email varchar(100), pwd varchar(100), mobile varchar(20), fullname varchar(100), dob date , bloodgroup varchar(20), gender varchar(30), address varchar(200), city varchar(100), state varchar(100), medhistory varchar(300));
app.get("/sign_up", function (req, resp) {
const email = req.query.kuchEmail;
const pwd = req.query.kuchPass;
const mob = req.query.kuchMob;
console.log(req.query);
mysql.query(
"select * from users where email=?",
[email],
function (err, resultJsonAry) {
if (resultJsonAry.length == 1) {
console.log("Email id already exist");
resp.send("Email id already exist");
} else {
mysql.query(
"insert into users(email,pwd,mobile) values(?,?,?)",
[email, pwd, mob],
function (err) {
if (err == null) {
console.log("Signup Successful");
resp.send("Signup Successful");
} else {
console.log(err.message);
resp.send(err);
}
}
);
}
}
);
});
app.get("/login", function (req, resp) {
console.log(req.query);
//login query
mysql.query(
"select * from users where email=? and pwd=?",
[req.query.loginEmail, req.query.loginPwd],
function (err, resultJsonAry) {
//console.log(JSON.stringify(resultJsonAry));
if (err != null) {
console.log(err);
resp.send(err);
return;
}
if (resultJsonAry.length == 1) {
{
console.log("Login successful");
resp.send("Login Done");
}
} else {
console.log("Invalid email or password.");
resp.send("Invalid Email or Password");
}
}
);
});
app.get("/fetch-contact", function (req, resp) {
console.log(req.query);
mysql.query(
"select * from users where email=?",
[req.query.kuchEmail],
function (err, resultJsonAry) {
if (err != null) {
alert("Invalid Infomation");
console.log(err);
resp.send(err);
return;
}
console.log(resultJsonAry);
resp.send(resultJsonAry);
}
);
});
// create table reviews(rid int auto_increment primary key,email varchar(100), message varchar(1000));
app.get("/message-sent", function (req, resp) {
console.log(req.query);
mysql.query(
"insert into reviews values(?,?,?)",
[0, req.query.kuchEmail, req.query.kuchMsg],
function (err) {
if (err != null) {
// alert("Invalid Infomation");
console.log(err);
resp.send(err);
return;
}
console.log("Response Sent !");
resp.send("Response Sent !");
}
);
});
//create table reviews(rid int auto_increment primary key,email varchar(100), message varchar(1000));
app.get("/fetch-one", function (req, resp) {
console.log(req.query);
mysql.query(
"select * from users where email=?",
[req.query.kuchEmail],
function (err, resultJsonAry) {
if (err != null) {
alert("Invalid Infomation");
// console.log(err);
resp.send(err);
return;
}
console.log(resultJsonAry);
resp.send(resultJsonAry);
}
);
});
app.post("/profile-save", function (req, resp) {
const email = req.body.txtEmail;
const fullname = req.body.txtName;
const mobile = req.body.txtMobile;
const address = req.body.txtAdd;
const city = req.body.selCity;
const state = req.body.selState;
const gender = req.body.selGender1;
const bloodgroup = req.body.selBlood;
const medhistory = req.body.txtMedHis;
const dob = req.body.txtDate;
// //pic-uploading
// let filename;
// if (req.files == null) {
// filename = "nopic.jpg";
// } else {
// filename = req.files.ppic.name;
// let path = process.cwd() + "/public/uploads/" + filename;
// req.files.ppic.mv(path);
// }
// req.body.ppic = filename; //why this?
console.log(req.body);
mysql.query(
"update users set fullname=?,dob=?, mobile=?, address=?,gender=? ,city=?, state=?, bloodgroup=?,medhistory=? where email=? ",
[
fullname,
dob,
mobile,
address,
gender,
city,
state,
bloodgroup,
medhistory,
email,
],
function (err, respJson) {
if (err == null) {
// console.log(respJson)
console.log("RECORD UPDATED SUCCESSFULLY");
// window.location = '/Frontend/html/customer-profile.html';
// return;
resp.send("RECORD UPDATED SUCCESSFULLY");
} else {
resp.send(err.message);
}
}
);
});
// create table bloodbanks(bbname varchar(100), city varchar(100), Apos varchar(10),Bpos varchar(10),ABpos varchar(10),Opos varchar(10),Aneg varchar(10),Bneg varchar(10),ABneg varchar(10),Oneg varchar(10));
// app.get("/request-blood",function(req,resp){
// console.log(req.query);
// const units=req.query.kuchUnits;
// const bloodgroup=req.query.bloodgroup;
// const city= req.query.city;
// mysql.query("SELECT * FROM bloodbanks WHERE city=? and CASE WHEN ? = 'A+' THEN Apos WHEN ? = 'B+' THEN Bpos WHEN ? = 'AB+' THEN ABpos WHEN ? = 'O+' THEN Opos WHEN ? = 'A-' THEN Aneg WHEN ? = 'B-' THEN Bneg WHEN ? = 'AB-' THEN ABneg WHEN ? = 'O-' THEN Oneg END >= ?;",[city,bloodgroup,bloodgroup,bloodgroup,bloodgroup,bloodgroup,bloodgroup,bloodgroup,bloodgroup,units],function(err,respJsonAry){
// console.log("i am here")
// if(err!=null){
// resp.send(err);
// }
// console.log(respJsonAry);
// resp.send(respJsonAry);
// })
// })
// //create table requests(rid int auto_increment primary key,email varchar(100), fullname varchar(100), mobile varchar(20), gender varchar(10), city varchar(100),state varchar(100), bloodgroup varchar(10), dob date, hospitalname varchar(100), hospitalid varchar(100), medhistory varchar(1000));
app.get("/search-blood", function (req, resp) {
console.log(req.query);
// const units = req.query.kuchUnits;
const bloodgroup = req.query.kuchBlood;
const city = req.query.kuchCity;
mysql.query(
"SELECT * FROM bloodbanks WHERE city=? and CASE WHEN ? = 'Apos' THEN Apos WHEN ? = 'Bpos' THEN Bpos WHEN ? = 'ABpos' THEN ABpos WHEN ? = 'Opos' THEN Opos WHEN ? = 'Aneg' THEN Aneg WHEN ? = 'Bneg' THEN Bneg WHEN ? = 'ABneg' THEN ABneg WHEN ? = 'Oneg' THEN Oneg END >= 0;",
[
city,
bloodgroup,
bloodgroup,
bloodgroup,
bloodgroup,
bloodgroup,
bloodgroup,
bloodgroup,
bloodgroup
],
function (err, respJsonAry) {
console.log("i am here");
if (err != null) {
resp.send(err);
}
console.log(respJsonAry);
resp.send(respJsonAry);
}
);
});
app.get("/save-donation", function (req,resp) {
const email = req.query.kuchEmail;
const fullname = req.query.kuchName;
const mobile = req.query.kuchMobile;
const address = req.query.kuchAdd;
const city = req.query.kuchCity;
const state = req.query.kuchState;
const gender = req.query.kuchGender;
const bloodgroup = req.query.kuchBlood;
const medhistory = req.query.kuchMedHis;
const dob = req.query.kuchDate;
// //pic-uploading
// let filename;
// if (req.files == null) {
// filename = "nopic.jpg";
// } else {
// filename = req.files.ppic.name;
// let path = process.cwd() + "/public/uploads/" + filename;
// req.files.ppic.mv(path);
// }
// req.body.ppic = filename; //why this?
mysql.query(
"insert into bloodDonations values(0,?,?,?,?,?,?,?,?,?,current_date); ",
[
email,
mobile,
fullname,
dob,
bloodgroup,
gender,
city,
state,
medhistory,
],
function (err, respJson) {
if (err == null) {
console.log("Registered Successfully");
// window.location = '/Frontend/html/customer-profile.html';
// return
resp.send("Registered Successfully");
} else {
resp.send(err.message);
}
}
);
});
app.get("/save-request",function(req,resp){
const email = req.query.kuchEmail;
const fullname = req.query.kuchName;
const mobile = req.query.kuchMobile;
// const address = req.query.kuchAdd;
const city = req.query.kuchCity;
const state = req.query.kuchState;
const gender = req.query.kuchGender;
const bloodgroup = req.query.kuchBlood;
const medhistory = req.query.kuchMedHis;
const dob = req.query.kuchDate;
const hospitalname=req.query.kuchHospitalName;
const hospitalid=req.query.kuchHospitalId;
const units=req.query.kuchUnits;
// //pic-uploading
// let filename;
// if (req.files == null) {
// filename = "nopic.jpg";
// } else {
// filename = req.files.ppic.name;
// let path = process.cwd() + "/public/uploads/" + filename;
// req.files.ppic.mv(path);
// }
// req.body.ppic = filename; //why this?
console.log(req.query);
mysql.query(
"insert into requests values(0,?,?,?,?,?,?,?,?,?,?,?,current_date); ",
[
email,
fullname,
mobile,
gender,
city,
state,
bloodgroup,
dob,
hospitalname,
hospitalid,
medhistory,
units
],
function (err, respJson) {
console.log("hii, main aagya")
if (err == null) {
console.log("Request sent Successfully");
// window.location = '/Frontend/html/customer-profile.html';
// return
resp.send("Request sent Successfully");
} else {
console.log(err);
resp.send(err);
}
}
);
})