-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
235 lines (209 loc) · 6.39 KB
/
Copy pathserver.js
File metadata and controls
235 lines (209 loc) · 6.39 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
var express = require('express'),
restful = require('node-restful'),
mongoose = restful.mongoose,
Schema = mongoose.Schema;
var api = express.Router();
var app = express();
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
//Header for cross domain.
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:1020');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
// load the body-parser middleware
app.use(bodyParser.urlencoded({extended: false}));
app.use(methodOverride());
mongoose.connect('mongodb://localhost/VMS');
// Vistor Type Schema
var VisitorTypeSchema = mongoose.Schema({
typename : String
});
var VistorTypes = restful.model('visitortype',VisitorTypeSchema);
VistorTypes.methods(['get','put','post','delete']);
VistorTypes.register(app,'/api/visitortypes');
// Vistor Type Schema
var VerificationTypeSchema = mongoose.Schema({
typename : String
});
var VerificationTypes = restful.model('verificationtype',VerificationTypeSchema);
VerificationTypes.methods(['get','put','post','delete']);
VerificationTypes.register(app,'/api/verificationtypes');
// Person Details Schema
var PersonDetailSchema = mongoose.Schema({
name : String,
towernumber : String,
faltnumber : String,
gender : String,
contactnumber : String,
photo : String
});
var PersonDetails = restful.model('persondetail',PersonDetailSchema);
PersonDetails.methods(['get','put','post','delete']);
PersonDetails.register(app,'/api/persondetails');
// New Visitor Schema
var NewVisitorSchema = mongoose.Schema({
name : String,
address: String,
gender: String,
contactnumber : String,
verificationtypeid : String,
verificationnumber :String,
towernumber : String,
flatnumber : String,
visitortypeid : String,
photo : String,
photoproof : String
});
var NewVisitors = restful.model('newvisitor',NewVisitorSchema);
NewVisitors.methods(['get','put','post','delete']);
NewVisitors.register(app,'/api/newvisitors');
// Person Details Schema
var VisitorDetailSchema = mongoose.Schema({
visitorid : String,
personid : String,
purpose : String,
checkin : Date,
checkout : Date
});
var VisitorDetails = restful.model('visitordetail',VisitorDetailSchema);
VisitorDetails.methods(['get','put','post','delete']);
VisitorDetails.register(app,'/api/visitordetails');
var person = mongoose.model('persondetails', PersonDetailSchema)
//Get
app.get('/personbytowerandflat/:tower/:flat',function(req,res){
person.find({ $and : [{towernumber : req.params.tower},{faltnumber: req.params.flat}]},function(err,persons){
if(err){
res.send(err);
return;
}
res.json(persons);
}).limit(1);
});
//Get Checkout list.
var visitorcheckout = mongoose.model('visitordetails', VisitorDetailSchema)
app.get('/checkoutlist',function(req,res){
/*var visitortype = "57375b8ae8f44693cbb3e084";
if(req.params.visitorid == 'staff')
{
visitortype ="57375b82e8f44693cbb3e083";
}*/
visitorcheckout.find({chekcout : null},function(err,visitorlist){
if(err){
res.send(err);
return;
}
res.json(visitorlist);
});
});
app.get('/newvisitors/:visitortype/:visitorid',function(req,res){
var visitortypeid = '57375b8ae8f44693cbb3e084';
if(req.params.visitortype == 'staff')
{
visitortypeid ='57375b82e8f44693cbb3e083';
}
//req.params.visitortypeid
NewVisitorList.find({$and : [{visitortypeid : visitortypeid},{_id : req.params.visitorid}]},function(err,visitors){
if(err){
res.send(err);
return;
}
res.json(visitors);
});
});
//Get Newvistior list per vistorid.
var NewVisitorList = mongoose.model('newvisitors', NewVisitorSchema)
app.get('/newvisitorsstaff',function(req,res){
var visitortypeid = '57375b82e8f44693cbb3e083';
//req.params.visitortypeid
NewVisitorList.find({visitortypeid : visitortypeid},function(err,visitors){
if(err){
res.send(err);
return;
}
res.json(visitors);
});
});
//Get visitors and staff by contact number
app.get('/GetVisitorsbycontact/:visitortype/:anydetails',function(req,res){
var visitortypeid = '57375b8ae8f44693cbb3e084';
if(req.params.visitortype == 'staff')
{
visitortypeid ='57375b82e8f44693cbb3e083';
}
//req.params.visitortypeid
//NewVisitorList.find({$and : [{visitortypeid : visitortypeid},{contactnumber : /req.params.contact/}]},function(err,visitors){
NewVisitorList.find({ $and : [{visitortypeid : visitortypeid},{$or :[{contactnumber : new RegExp(req.params.anydetails, 'i')},{name : new RegExp(req.params.anydetails, 'i')}]}]},function(err,visitors){
if(err){
res.send(err);
return;
}
res.json(visitors);
});
});
/*//Get Checkout details.
var CheckinVisitorSchema = mongoose.Schema({
name : String,
address: String,
gender: String,
contactnumber : String,
verificationtypeid : String,
verificationnumber :String,
towernumber : String,
flatnumber : String,
visitortypeid : String,
photo : String,
photoproof : String,
details :[]
});
// visistor Details Schema
var CheckinVisitorDetailSchema = mongoose.Schema({
visitorid : String,
personid : String,
purpose : String,
checkin : Date,
checkout : Date,
checkinmaster : [{{ type : mongoose.Schema.ObjectId, ref:'visitordetails'}}]
});
var CheckinVisitor = mongoose.model('visitordetailscheckin', CheckinVisitorSchema);*/
//Get
/*app.get('/checkinvisitors',function(req,res){
CheckinVisitor.find().populate('details').exec(function(err,persons){
if(err){
res.send(err);
return;
}
res.json(persons);
});
});*/
// filer date by date.
var visitorsbydate = mongoose.model('visitordetails', VisitorDetailSchema)
app.get('/visitorsbydate',function(req,res){
/*var visitortype = "57375b8ae8f44693cbb3e084";
if(req.params.visitorid == 'staff')
{
visitortype ="57375b82e8f44693cbb3e083";
}*/
visitorcheckout.find({checkin: {
//$gte: '2016-05-14T21:26:50.000Z'
$lt: '2016-05-14T21:26:50.000Z'
}},function(err,visitors){
if(err){
res.send(err);
return;
}
res.json(visitors);
});
});
//Initialize app port
app.listen(4030);
console.log('server is running at port 4030');