-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdbquery.js
101 lines (73 loc) · 2.69 KB
/
dbquery.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
var VisitorDetail = require('./models/VisitorDetail.model');
var HostDetail = require('./models/HostDetail.model');
var mongoose = require('mongoose');
exports.CheckIn = function (req, res) {
var obj = req.body;
HostDetail.findOne({ 'Email': obj.hostemail })
.then((hostinfo) => {
if (hostinfo) {
//console.log(hostinfo);
qid = hostinfo._id;
qid = mongoose.Types.ObjectId(qid);
var obj = {
Name: req.body.Name,
Phone: req.body.Phone,
Email: req.body.Email,
Address: req.body.Address,
HostId: qid,
CheckInTime: req.body.CheckInTime,
CheckOutTime: null,
}
var success = {
outcome: "CheckIn Successfull",
hostemail: hostinfo.Email,
hostphone: hostinfo.Phone,
done: 1,
}
const newObj = new VisitorDetail(obj);
newObj.save()
.then((data) => {
res.json(success);
}).catch((err) => {
res.json(err);
});
}
else { console.log("No data exist for this id"); res.send("Host Details not found"); }
}).catch((err) => { res.send("Some techncal error") });
}
exports.CheckOut = (req, res) => {
var obj = req.body;
VisitorDetail.findOne({ 'Email': obj.Email })
.then((visitorinfo) => {
if (visitorinfo) {
VisitorDetail.findByIdAndUpdate(visitorinfo._id, { 'CheckOutTime': new Date() }, { new: true }, (err, todo) => {
if (err) return res.status(500).send(err);
var success = {
outcome: "Checkout Successfull",
vdetail: visitorinfo,
done: 1,
}
return res.send(success);
})
} else {
res.send("User not found")
}
}).catch((err) => {
res.send(" Some technical issue");
});
}
exports.AddHost = (req, res) => {
const newObj = new HostDetail(req.body);
newObj.save(err => {
if (err) return res.status(500).send(err);
return res.status(200).send("SUCCESS");
});
}
exports.HostList = (req, res) => {
HostDetail.find({}).then((hostdata) => {
if (hostdata) { res.status(200).send(hostdata); }
else { res.status(500).send('Error'); }
}).catch((err) => {
console.log("error")
});
}