-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
199 lines (131 loc) · 5.2 KB
/
app.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
const express=require('express');
const path=require('path');
const fs=require('fs');
const mongodb=require('mongodb');
const bcrypt=require('bcryptjs');
const multer=require('multer');
const db=require('./data/database');
const upload=multer({dest:'images'});
const app=express();
app.set('views',path.join(__dirname,'views'));
app.set('view engine','ejs');
app.use(express.static('public'));
app.use(express.urlencoded({extended:false}));
app.get('/signuppage',function(req,res){
const pathtosignuppage=path.join(__dirname,'views','signup.html');
res.sendFile(pathtosignuppage);
});
app.post('/signup',async function(req,res){
const givenemail=req.body.enteredemail;
const givenpassword=req.body.enteredpassword;
const hashedpassword=await bcrypt.hash(givenpassword,12);
const user={
email:givenemail,
password:hashedpassword
};
const userarray=await db.getDb().collection('users').find().project({email:1,_id:0}).toArray();
console.log(userarray);
for(a of userarray){
if(a.email==givenemail){
// alert('A user with this emailId already exists.');
return res.redirect('/signuppage');
}
}
await db.getDb().collection('users').insertOne(user);
return res.redirect('/login');
});
app.get('/login',function(req,res){
const pathtologinpage=path.join(__dirname,'views','login.html');
res.sendFile(pathtologinpage);
});
app.post('/loginform',async function(req,res){
const enteredloginemail=req.body.elogaddress;
const enteredloginpassword=req.body.elogpassword;
const boolvar=await db.getDb().collection('users').findOne({email:enteredloginemail});
if(!boolvar){
console.log('Could not log in!unkonwn email');
return res.redirect('/login');
}
const passwordsareequal=await bcrypt.compare(enteredloginpassword,boolvar.password);
if(!passwordsareequal){
console.log('Could not log in! wrong password');
return res.redirect('/login');
}
res.redirect('/');
});
app.get('/',function(req,res){
const pathtoindexpage=path.join(__dirname,'views','index.html');
res.sendFile(pathtoindexpage);
});
app.post('/search',function(req,res){
const enteredtext=req.body.navsearch;
console.log(enteredtext);
if(enteredtext=='medicines'||enteredtext=='products'){
const pathtomedpage=path.join(__dirname,'views','medicine.html');
res.sendFile(pathtomedpage);
}
else if(enteredtext=='labtests'){
const pathtotestpage=path.join(__dirname,'views','labtests1.html');
res.sendFile(pathtotestpage);
}
else if(enteredtext=='doctors'||enteredtext=='appointment'||enteredtext=='doctor'){
const pathtodoctorpage=path.join(__dirname,'views','doctors.html');
res.sendFile(pathtodoctorpage);
}
});
app.get('/doctorsapp',function(req,res){
const pathtodocpage=path.join(__dirname,'views','doctors.html');
res.sendFile(pathtodocpage);
});
app.post('/docgrid',async function(req,res){
const entereddochos=req.body.hospitals;
const entereddoccity=req.body.city;
console.log(entereddoccity);
console.log(entereddochos);
const docdata=await db.getDb().collection('doctors').find({$and:[{hospitals:entereddochos},{city:entereddoccity}]}).project({name:1,yearsofexp:1,speciality:1,fee:1,qualification:1,_id:0}).toArray();
res.render('docgrid',{docdata:docdata});
});
app.post('/docgrid1',async function(req,res){
const entereddocspe=req.body.speciality;
const entereddocpin=req.body.pin;
const docdata=await db.getDb().collection('doctors').find({$and:[{speciality:entereddocspe},{pincode:entereddocpin}]}).project({name:1,yearsofexp:1,fee:1,qualification:1,speciality:1,_id:0}).toArray();
res.render('docgrid1',{docdata:docdata});
});
app.get('/labtests',function(req,res){
const pathtolabpage=path.join(__dirname,'views','labtests1.html');
res.sendFile(pathtolabpage);
});
app.post('/labsearch',async function(req,res){
const testpin=req.body.testplace;
const sym=req.body.Symtest;
const testdata=await db.getDb().collection('labtest').find({$and:[{pincode:testpin},{symptom:sym}]}).project({name:1,price:1,_id:0}).toArray();
res.render('labtestgrid',{test:testdata});
});
app.get('/medicines',function(req,res){
const pathtomedpage=path.join(__dirname,'views','medicine.html');
res.sendFile(pathtomedpage);
});
app.post('/searchmeds',async function(req,res){
const prod=req.body.productname;
const meddata=await db.getDb().collection('meds').find({$or:[{type:prod},{brandname:prod},{name:prod}]}).project({name:1,price:1,image:1,_id:0}).toArray();
res.render('productsgrid',{med:meddata});
});
app.get('/uploadfile',function(req,res){
const pathtouploadpage=path.join(__dirname,'views','uploadpres.html');
res.sendFile(pathtouploadpage);
});
app.post('/reviewsubmit',async function(req,res){
const newreview=req.body.review;
await db.getDb().collection('reviews').insertOne({experience:newreview});
res.redirect('/');
});
app.post('/presupload',upload.single('prescription'), async function(req,res){
const uploadedimg=req.file;
await db.getDb().collection('prescriptions').insertOne({
imagepath:uploadedimg.path
});
res.redirect('/medicines');
});
db.connectToDatabase().then(function (){
app.listen(3000);
});