-
Notifications
You must be signed in to change notification settings - Fork 1
/
ftMongoServ.js
108 lines (84 loc) · 2.19 KB
/
ftMongoServ.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
var express = require('express');
var url = require('url');
var mongoose = require('mongoose');
var bodyParser = require('body-parser')
var app = express();
// create application/json parser
var jsonParser = bodyParser.json();
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false });
var Users;
var Calendars;
//put config url behind file to hide passwords and username
var mongoDBConnection = require('./db.ftSample.config');
console.log(mongoDBConnection.uri);
mongoose.connect(mongoDBConnection.uri);
mongoose.connection.on('open', function() {
var Schema = mongoose.Schema;
var UserSchema = new Schema(
{
name: String,
uID: Number,
calendarId: Number,
fcalendarIDs[
fID: Number
]
},
{collection: 'users'}
);
Users = mongoose.model('Users', UserSchema);
var calendarSchema = new Schema(
{
calendarId: Number,
events: [ {
title: String,
description: String,
//eventId listed as ID
id: Number,
privacy: String,
start: String
}]
},
{collection: 'calendars'}
);
Calendars = mongoose.model('Calendars', calendarIdSchema);
console.log('models have been created');
});
function getAllEvents(res){
console.log("inside get all events");
var query = Events.find({});
query.exec(function (err, itemArray) {
res.json(itemArray);
});
}
function getMyEvents(res){
console.log("inside get my events");
var query = Events.find({eventListId:1});
query.exec(function (err, itemArray) {
res.json(itemArray);
});
}
function getFriendEvents(res){
console.log("inside get friend events");
var query = Events.find({eventListId:2});
query.exec(function (err, itemArray) {
res.json(itemArray);
});
}
app.use('/', express.static('./apps/'));
app.use('/eventSources/', express.static('./eventsources'));
app.get('/:uId/', function(req,res){
});
app.get('/events/', function (req, res){
console.log("get all events");
getAllEvents(res);
});
app.get('/events/self', function (req, res){
console.log("get my events");
getMyEvents(res);
});
app.get('/events/friend', function (req, res){
console.log("get friend events");
getFriendEvents(res);
});
app.listen(80);