-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
182 lines (119 loc) · 3.28 KB
/
Copy pathindex.js
File metadata and controls
182 lines (119 loc) · 3.28 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
var restify = require('restify');
var port = 7000;
server = restify.createServer(
{
name : 'Address API Server'
}
);
var mongoose = require('mongoose');
mongoose.connect('mongodb://tesco:tesco@ds052827.mongolab.com:52827/multivision');
var Schema = mongoose.Schema
, ObjectId = Schema.ObjectId;
var Address = new Schema({
id: ObjectId,
isActive: String,
picture: String,
age: String,
eyeColor: String,
fullname: String,
gender: String,
company: String,
email: String,
phone: String,
street1: String,
buildingname: String,
buildingno: String,
town: String,
city: String,
postcode: String,
registered: Date,
latitude: String,
longitude: String,
favoriteFruit: String
});
var AddressModel = mongoose.model('address', Address);
server.get('/', function(req,res,next)
{
res.send('Address API Server running Successfully');
});
server.get('/address', function(req,res,next)
{
res.send('Address API Server running Successfully');
});
server.get('/address/:postcode/:limit', function(req,res,next)
{
if(req.params.limit=='undefined')
{
req.params.limit=10;
}
AddressModel
.find({"postcode":req.params.postcode})
.sort({'registered': -1})
.limit(req.params.limit)
.exec(function(err, posts) {
res.send(posts);
});
});
server.get('/address/:postcode', function(req,res,next)
{
AddressModel
.find({"postcode":req.params.postcode})
.sort({'registered': -1})
.limit(10)
.exec(function(err, posts) {
res.send(posts);
});
});
function getPostalcode()
{
var PostCodes = ["ASCN 1ZZ","STHL 1ZZ","TDCU 1ZZ","BBND 1ZZ", "WC2A 1QT", "WC2A 1QU", "WC2A 1RP", "WC2A 1PQ", "WC1V 7PB", "EC4Y 9AR"];
postcode=PostCodes[Math.floor((Math.random() * 10))] ;
return postcode;
}
function getLat()
{
var Coordinates = ["100.293","423.567","112.567","345.778", "846.898", "124.678", "148.908", "123.678", "456.346", "123.125"];
coordinate=Coordinates[Math.floor((Math.random() * 10))] ;
return coordinate;
}
function getLag()
{
var Coordinates = ["100.293","423.567","112.567","345.778", "846.898", "124.678", "148.908", "123.678", "456.346", "123.125"];
coordinate=Coordinates[Math.floor((Math.random() * 10))] ;
return coordinate;
}
function getFirstName()
{
var FirstNames = ["Shiley","Safeer","Micheal","Warne", "Willsmith", "Shankar", "Nithya", "Atanu", "Shane", "Campell"];
firstname=FirstNames[Math.floor((Math.random() * 10)) ] ;
return firstname;
}
function getLastName()
{
var LastNames = ["Smith","Benny","Mark","Tommy", "Alexander", "Kamal", "Roshan", "Peter", "Kumar", "Babu"];
lastname=LastNames[Math.floor((Math.random() * 10))] ;
return lastname;
}
function getCity()
{
var Cities = ["ASCN 1ZZ","STHL 1ZZ","TDCU 1ZZ","BBND 1ZZ", "WC2A 1QT", "WC2A 1QU", "WC2A 1RP", "WC2A 1PQ", "WC1V 7PB", "EC4Y 9AR"];
city=Cities[Math.floor((Math.random() * 10)) ] ;
return city;
}
function getStreet()
{
var Streets = ["533 Montgomery Place, Biehle, Louisiana, 9197","49 Featherstone Street","44 Simon Street","A 29 Kingdome Vallace", "34 India Gateway"];
street=Streets[Math.floor((Math.random() * 5)) ] ;
return street;
}
function getGender()
{
var genders = ["Male","Female"];
gender=genders[Math.floor((Math.random() * 2)) ] ;
return gender;
}
server.listen(port, function()
{
console.log('address server started on port ' + port);
}
);