-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.js
64 lines (52 loc) · 1.96 KB
/
routes.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
const express = require("express");
const router = express.Router();
const {doctors, keywords} = require("./model")
router.get("/doctorsList", async (req, res) => {
try {const query = req.query;
const search = req.query.search;
const filter = {};
for(const key in query){
switch (key){
case "specialization":
if(query[key] == "others") break;
filter.specialization = query[key].toUpperCase();
break;
case "fee":
filter.fee = {$lte: parseInt(query[key])}
break;
case "education":
if(query[key] == "others") break;
filter.education = {$in: [query[key]]}
break;
case "search":
filter.$or = [ {name : {$regex: new RegExp(`\\b${search}`, "i") }},
{keywords : {$in: [new RegExp(`\\b${search}`, "i") ]}},
{education : {$in: [new RegExp(`\\b${search}`, "i") ]}},
{designation : {$in:[new RegExp(`\\b${search}`, "i") ]}},
]
break;
default :
break;
}}
const list = await doctors.find(filter);
res.send(JSON.stringify(list));
}catch(err){
console.log(err)
}
})
router.get("/search", async (req, res)=> {
try{
const search = req.query.search;
const Result1 = await keywords.find({
word : {$regex: new RegExp(`\\b${search}`, "i") }
});
const Result2 = await doctors.find({
name : {$regex: new RegExp(`\\b${search}`, "i") }
});
const searchResult = [...Result1, ...Result2]
res.send(JSON.stringify(searchResult));
}catch(err){
console.log(err);
}
})
module.exports = router;