-
Notifications
You must be signed in to change notification settings - Fork 0
/
contactserver.js
617 lines (598 loc) · 15.5 KB
/
contactserver.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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
// mongoose.connect('mongodb://localhost/okcoders'); // for localhost-ing for deveolpment
mongoose.connect('mongodb://okcoders:[email protected]/shane'); //for live public hosting
mongoose.Promise = Promise;
var app = express();
app.use(express.static('./public'));
app.use(bodyParser());
var ContactEntry = require('./models/contactmodel');
var port = process.env.PORT || 8080; //for live public hosting
app.listen(port, function() {
console.log('App listening at http://localhost:' + port);
});
app.get('/listReturn', function(req,res){
ContactEntry.find().sort({lastName:1}).exec().then(function(returnedList){
res.json(returnedList);
});
});
app.get('/listReturn/byId/:id', function(req,res){
var findMe = req.params.id;
ContactEntry.find({_id:findMe}).exec().then(function(foundMe){
res.json(foundMe);
});
});
app.post('/listReturn', function(req,res){
var newEntry = req.body;
if(newEntry._id) {
ContactEntry.findOneAndUpdate({_id:newEntry._id}, newEntry).exec().then(function(){
res.json(true);
});
} else {
var sendEntry = new ContactEntry(newEntry);
sendEntry.save().then(function(){
res.json(true);
});
}
});
app.delete('/listReturn/:id', function(req,res){
var killMe = req.params.id;
ContactEntry.findOneAndRemove({_id:killMe}).exec().then(function(){
res.json(true);
});
});
function initContactList() {
return ContactEntry.count().then(function(count){
if(count) return;
var dummyList = [
{
firstName: "Genevieve",
lastName: "Sellers",
phone: "(562) 685-5202",
email: "[email protected]",
image: "images/5.png"
},
{
firstName: "Shaine",
lastName: "Cherry",
phone: "(891) 288-4323",
email: "[email protected]",
image: "images/6.png"
},
{
firstName: "Buffy",
lastName: "Pierce",
phone: "(836) 912-5474",
email: "[email protected]",
image: "images/7.png"
},
{
firstName: "Kaye",
lastName: "Carlson",
phone: "(512) 714-7883",
email: "[email protected]",
image: "images/8.png"
},
{
firstName: "Oliver",
lastName: "Shields",
phone: "(195) 839-6644",
email: "[email protected]",
image: "images/9.png"
},
{
firstName: "Phyllis",
lastName: "Ashley",
phone: "(499) 489-0014",
email: "[email protected]",
image: "images/10.png"
},
{
firstName: "Jamal",
lastName: "Wilson",
phone: "(657) 227-8536",
email: "[email protected]",
image: "images/11.png"
},
{
firstName: "Hiram",
lastName: "Holder",
phone: "(223) 385-2814",
email: "[email protected]",
image: "images/12.png"
},
{
firstName: "Addison",
lastName: "Barr",
phone: "(229) 644-8333",
email: "[email protected]",
image: "images/1.png"
},
{
firstName: "Benjamin",
lastName: "Stephens",
phone: "(411) 817-1815",
email: "[email protected]",
image: "images/2.png"
},
{
firstName: "Xyla",
lastName: "Everett",
phone: "(904) 836-8543",
email: "[email protected]",
image: "images/3.png"
},
{
firstName: "Colby",
lastName: "Hester",
phone: "(468) 245-7261",
email: "[email protected]",
image: "images/4.png"
},
{
firstName: "Joy",
lastName: "Burris",
phone: "(138) 555-2678",
email: "[email protected]",
image: "images/5.png"
},
{
firstName: "Chastity",
lastName: "Briggs",
phone: "(475) 636-0318",
email: "[email protected]",
image: "images/6.png"
},
{
firstName: "Kenneth",
lastName: "Williams",
phone: "(929) 955-6258",
email: "[email protected]",
image: "images/7.png"
},
{
firstName: "Carter",
lastName: "Craft",
phone: "(679) 127-7962",
email: "[email protected]",
image: "images/8.png"
},
{
firstName: "Harper",
lastName: "Good",
phone: "(260) 105-1048",
email: "[email protected]",
image: "images/9.png"
},
{
firstName: "Nora",
lastName: "Macdonald",
phone: "(446) 538-8445",
email: "[email protected]",
image: "images/10.png"
},
{
firstName: "Lunea",
lastName: "Pittman",
phone: "(923) 798-6603",
email: "[email protected]",
image: "images/11.png"
},
{
firstName: "Rae",
lastName: "Vargas",
phone: "(666) 237-9649",
email: "[email protected]",
image: "images/12.png"
},
{
firstName: "Hermione",
lastName: "Walls",
phone: "(485) 791-4559",
email: "[email protected]",
image: "images/1.png"
},
{
firstName: "Britanni",
lastName: "Jarvis",
phone: "(797) 547-3242",
email: "[email protected]",
image: "images/2.png"
},
{
firstName: "Graham",
lastName: "Mclaughlin",
phone: "(587) 949-6238",
email: "[email protected]",
image: "images/3.png"
},
{
firstName: "Hannah",
lastName: "Humphrey",
phone: "(499) 285-2511",
email: "[email protected]",
image: "images/4.png"
},
{
firstName: "Jerry",
lastName: "Griffin",
phone: "(413) 395-5898",
email: "[email protected]",
image: "images/1.png",
street: "Ap #774-6097 Vel Rd.",
city: "San Rafael",
state: "Alajuela",
postalCode: "54920"
},
{
firstName: "Alfreda",
lastName: "Frank",
phone: "(482) 488-7650",
email: "[email protected]",
image: "images/2.png",
street: "119-5167 Magna Street",
city: "Issy-les-Moulineaux",
state: "Île-de-France",
postalCode: "62-109"
},
{
firstName: "Kelly",
lastName: "Berry",
phone: "(927) 314-1517",
email: "[email protected]",
image: "images/3.png",
street: "Ap #434-1814 A Avenue",
city: "Carcassonne",
state: "LA",
postalCode: "52842"
},
{
firstName: "Cameron",
lastName: "Ratliff",
phone: "(998) 672-1359",
email: "[email protected]",
image: "images/4.png",
street: "566-7792 Sociis Ave",
city: "Liverpool",
state: "New South Wales",
postalCode: "183063"
},
{
firstName: "Wynter",
lastName: "Wong",
phone: "(726) 107-6672",
email: "[email protected]",
image: "images/5.png",
street: "Ap #104-9473 Parturient Road",
city: "Tarsus",
state: "Mer",
postalCode: "737776"
},
{
firstName: "Sydney",
lastName: "Miranda",
phone: "(592) 809-3310",
email: "[email protected]",
image: "images/6.png",
street: "P.O. Box 880, 5825 Sem Ave",
city: "Salem",
state: "OR",
postalCode: "5856"
},
{
firstName: "Ursa",
lastName: "Mcintyre",
phone: "(613) 919-1597",
email: "[email protected]",
image: "images/7.png",
street: "Ap #295-6747 Auctor Road",
city: "Linton",
state: "CA",
postalCode: "61302"
},
{
firstName: "Lila",
lastName: "Glover",
phone: "(582) 388-3232",
email: "[email protected]",
image: "images/8.png",
street: "P.O. Box 931, 9303 Vitae, Avenue",
city: "San José de Alajuela",
state: "A",
postalCode: "8861"
},
{
firstName: "Yardley",
lastName: "Hampton",
phone: "(756) 329-5347",
email: "[email protected]",
image: "images/9.png",
street: "Ap #198-2500 Proin Rd.",
city: "Harlingen",
state: "Fr",
postalCode: "2912"
},
{
firstName: "Lillian",
lastName: "Hoffman",
phone: "(661) 867-6167",
email: "[email protected]",
image: "images/10.png",
street: "685-2666 Non, Street",
city: "Cimitile",
state: "Campania",
postalCode: "K1G 1C3"
},
{
firstName: "Scarlet",
lastName: "Leonard",
phone: "(418) 428-0001",
email: "[email protected]",
image: "images/11.png",
street: "288-8689 Vel Road",
city: "Rutland",
state: "VT",
postalCode: "04-451"
},
{
firstName: "Mufutau",
lastName: "Nicholson",
phone: "(204) 676-1456",
email: "[email protected]",
image: "images/12.png",
street: "949-5330 Faucibus Road",
city: "Pirque",
state: "RM",
postalCode: "623393"
},
{
firstName: "Isaac",
lastName: "Fischer",
phone: "(275) 113-6268",
email: "[email protected]",
image: "images/1.png",
street: "309-7642 Duis Road",
city: "Lincoln",
state: "Nebraska",
postalCode: "88152"
},
{
firstName: "Zachary",
lastName: "Albert",
phone: "(502) 241-2255",
email: "[email protected]",
image: "images/2.png",
street: "Ap #754-6190 Mauris Avenue",
city: "Owen Sound",
state: "Ontario",
postalCode: "40988"
},
{
firstName: "Germaine",
lastName: "Casey",
phone: "(568) 564-0392",
email: "[email protected]",
image: "images/3.png",
street: "Ap #687-8442 Elit, Road",
city: "Orilla",
state: "ON",
postalCode: "6112"
},
{
firstName: "Rhiannon",
lastName: "Bryant",
phone: "(485) 758-4518",
email: "[email protected]",
image: "images/4.png",
street: "479-6852 Lacinia St.",
city: "Blenheim",
state: "South Island",
postalCode: "01042"
},
{
firstName: "Sophia",
lastName: "Rocha",
phone: "(284) 199-4423",
email: "[email protected]",
image: "images/5.png",
street: "P.O. Box 293, 8148 Ornare Rd.",
city: "Bundaberg",
state: "Queensland",
postalCode: "627098"
},
{
firstName: "Leandra",
lastName: "Kline",
phone: "(458) 104-3447",
email: "[email protected]",
image: "images/6.png",
street: "Ap #724-136 Sit St.",
city: "Henstedt-Ulzburg",
state: "Saarland",
postalCode: "36623"
},
{
firstName: "Fallon",
lastName: "Bender",
phone: "(129) 124-8771",
email: "[email protected]",
image: "images/7.png",
street: "Ap #718-464 Venenatis Avenue",
city: "Noisy-le-Grand",
state: "Île-de-France",
postalCode: "67953"
},
{
firstName: "Reed",
lastName: "Wilkerson",
phone: "(124) 597-7196",
email: "[email protected]",
image: "images/8.png",
street: "Ap #793-8287 Pede Ave",
city: "San Juan de Dios",
state: "San José",
postalCode: "494023"
},
{
firstName: "Noelle",
lastName: "Simmons",
phone: "(838) 633-6613",
email: "[email protected]",
image: "images/9.png",
street: "628-6289 Nullam Rd.",
city: "Pudahuel",
state: "Metropolitana de Santiago",
postalCode: "10773"
},
{
firstName: "Astra",
lastName: "Gonzales",
phone: "(798) 719-6406",
email: "[email protected]",
image: "images/10.png",
street: "356-1650 Venenatis Avenue",
city: "Sprimont",
state: "Luik",
postalCode: "26-484"
},
{
firstName: "Gabriel",
lastName: "West",
phone: "(386) 846-6481",
email: "[email protected]",
image: "images/11.png",
street: "5337 Orci. Street",
city: "Linköping",
state: "E",
postalCode: "1133QD"
},
{
firstName: "Rafael",
lastName: "Kirby",
phone: "(946) 408-1158",
email: "[email protected]",
image: "images/12.png",
street: "157-3076 A, Rd.",
city: "Guadalajara",
state: "Castilla - La Mancha",
postalCode: "86955"
},
{
firstName: "Scarlet",
lastName: "Allison",
phone: "(457) 516-4574",
email: "[email protected]",
image: "images/1.png",
street: "Ap #938-8656 Sit Ave",
city: "Newport News",
state: "Virginia",
postalCode: "40619"
},
{
firstName: "Halee",
lastName: "Flores",
phone: "(484) 842-7746",
email: "[email protected]",
image: "images/2.png",
street: "646-7936 A Rd.",
city: "Cornwall",
state: "ON",
postalCode: "592318"
},
{
firstName: "Audrey",
lastName: "Pittman",
phone: "(915) 630-6428",
email: "[email protected]",
image: "images/3.png",
street: "P.O. Box 993, 2543 Sit Rd.",
city: "Guarulhos",
state: "SP",
postalCode: "325391"
},
{
firstName: "Rose",
lastName: "Hayes",
phone: "(250) 977-9284",
email: "[email protected]",
image: "images/4.png",
street: "8839 Rutrum Av.",
city: "Sogliano Cavour",
state: "PUG",
postalCode: "P2P 2T6"
},
{
firstName: "Evangeline",
lastName: "Tillman",
phone: "(122) 746-4192",
email: "[email protected]",
image: "images/5.png",
street: "Ap #334-7022 Eros. St.",
city: "Grobbendonk",
state: "AN",
postalCode: "192101"
},
{
firstName: "Jacob",
lastName: "York",
phone: "(111) 366-8726",
email: "[email protected]",
image: "images/6.png",
street: "P.O. Box 613, 1709 Purus St.",
city: "Guarapuava",
state: "PR",
postalCode: "37-596"
},
{
firstName: "Thane",
lastName: "David",
phone: "(496) 522-2973",
email: "[email protected]",
image: "images/7.png",
street: "848-2721 Congue, Street",
city: "Dandenong",
state: "Victoria",
postalCode: "984833"
},
{
firstName: "Juliet",
lastName: "Russell",
phone: "(894) 704-9251",
email: "[email protected]",
image: "images/8.png",
street: "Ap #607-2716 Dictum St.",
city: "Alviano",
state: "UMB",
postalCode: "4974"
},
{
firstName: "Kylee",
lastName: "Paul",
phone: "(726) 308-8549",
email: "[email protected]",
image: "images/9.png",
street: "551-3356 Semper Road",
city: "Pironchamps",
state: "HE",
postalCode: "6212"
},
{
firstName: "Harriet",
lastName: "Henderson",
phone: "(610) 603-3826",
email: "[email protected]",
image: "images/10.png",
street: "Ap #345-7762 Amet Rd.",
city: "Forres",
state: "Morayshire",
postalCode: "36559"
}
];
dummyList.forEach(function(dummyEntry) {
dummyEntry = new ContactEntry(dummyEntry);
return dummyEntry.save();
});
});
}
initContactList();