Skip to content

Commit ddd7619

Browse files
unknownunknown
authored andcommitted
Actually pushing the meteor server code this time
1 parent 9115569 commit ddd7619

File tree

882 files changed

+151928
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

882 files changed

+151928
-0
lines changed

.meteor/.finished-upgraders

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file contains information which helps Meteor properly upgrade your
2+
# app when you run 'meteor update'. You should check it into version control
3+
# with your project.
4+
5+
notices-for-0.9.0
6+
notices-for-0.9.1
7+
0.9.4-platform-file
8+
notices-for-facebook-graph-api-2

.meteor/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
local

.meteor/.id

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file contains a token that is unique to your project.
2+
# Check it into your repository along with the rest of this directory.
3+
# It can be used for purposes such as:
4+
# - ensuring you don't accidentally deploy one app on top of another
5+
# - providing package authors with aggregated statistics
6+
7+
1h3i3mkm8h0pe1syij69

.meteor/packages

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Meteor packages used by this project, one per line.
2+
# Check this file (and the other files in this directory) into your repository.
3+
#
4+
# 'meteor add' and 'meteor remove' will edit this file for you,
5+
# but you can also edit it by hand.
6+
7+
meteor-platform
8+
iron:router

.meteor/platforms

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server
2+
browser

.meteor/release

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

lib/collections.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Metadata = new Meteor.Collection('metadata');
2+
Project = new Meteor.Collection('project');
3+
Channel = new Meteor.Collection('channel');

lib/routes.js

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
Router.route('/api/metadata/get/:id', {where: 'server'})
2+
.get(function () {
3+
var req = this.request.body;
4+
var res = this.response;
5+
var idToGet = this.params.id;
6+
var rowQuery = {};
7+
rowQuery['_id'] = idToGet;
8+
9+
var data = Metadata.find(rowQuery).fetch();
10+
11+
if (data) {
12+
res.statusCode = 200;
13+
res.setHeader("Content-Type","application/json");
14+
res.end(JSON.stringify(data));
15+
} else {
16+
res.statusCode = 400;
17+
res.setHeader("Content-Type","text/plain");
18+
this.response.end("Sorry, that particular document could not found!");
19+
}
20+
});
21+
22+
Router.route('/api/metadata/delete/:id/', {where: 'server'})
23+
.get(function () {
24+
// this api takes an id of a record of a particular collection and deletes it
25+
var req = this.request.body;
26+
var res = this.response;
27+
var idToDelete = this.params.id;
28+
var rowQuery = {};
29+
rowQuery['_id'] = idToDelete;
30+
31+
num = Metadata.remove(rowQuery);
32+
33+
if (parseInt(num) == 0) {
34+
res.statusCode = 400;
35+
res.setHeader("Content-Type","text/plain");
36+
res.end("Sorry, there was an error deleting your document!");
37+
}
38+
else {
39+
res.statusCode = 200;
40+
res.setHeader("Content-Type","text/plain");
41+
res.end("Success!");
42+
}
43+
});
44+
45+
Router.route('/api/metadata/unset/:id/:field_name', {where: 'server'})
46+
.get(function () {
47+
// this api takes a record with a particular id (:id) from a collection and removes a particular field (:field_name)
48+
var req = this.request.body;
49+
var res = this.response;
50+
var collName = this.params.coll_name;
51+
var idVal = this.params.id;
52+
var fieldToSet = this.params.field_name;
53+
var rowQuery = {};
54+
rowQuery['_id'] = idVal;
55+
var updateQuery = {};
56+
updateQuery[fieldToSet] = "";
57+
58+
num = Metadata.update(rowQuery,{$unset:updateQuery});
59+
60+
console.log(num);
61+
console.log(typeof(num));
62+
63+
if (parseInt(num) == 0) {
64+
res.statusCode = 400;
65+
res.setHeader("Content-Type","text/plain");
66+
res.end("Sorry, there was an error with your unset command!");
67+
}
68+
else {
69+
res.statusCode = 200;
70+
res.setHeader("Content-Type","text/plain");
71+
res.end("Success!");
72+
}
73+
});
74+
75+
Router.route('/api/metadata/set/:id/:field_name', {where: 'server'})
76+
.get(function () {
77+
// this api takes a record with a particular id (:id) from a collection and adds a particular field (:field_name) with a value parameter
78+
var req = this.request.body;
79+
var res = this.response;
80+
var collName = this.params.coll_name;
81+
var idVal = this.params.id;
82+
var fieldToSet = this.params.field_name;
83+
var valueToSet = this.params.query.value;
84+
var rowQuery = {};
85+
rowQuery['_id'] = idVal;
86+
var updateQuery = {};
87+
updateQuery[fieldToSet] = valueToSet;
88+
89+
num = Metadata.update(rowQuery,{$set:updateQuery});
90+
91+
console.log(num);
92+
console.log(typeof(num));
93+
94+
if (parseInt(num) == 0) {
95+
res.statusCode = 400;
96+
res.setHeader("Content-Type","text/plain");
97+
res.end("Sorry, there was an error with your set command!");
98+
}
99+
else {
100+
res.statusCode = 200;
101+
res.setHeader("Content-Type","text/plain");
102+
res.end("Success!");
103+
}
104+
});
105+
106+
Router.route('/api/metadata/exists/:field_name', {where: 'server'})
107+
.get(function () {
108+
// check to see if a field exists in a particular collection, if so, return it
109+
var req = this.request.body;
110+
var res = this.response;
111+
var fieldName = this.params.field_name;
112+
var query = {};
113+
query[fieldName] = {};
114+
query[fieldName]['$exists'] = true;
115+
116+
var data = Metadata.find(query).fetch();
117+
118+
if(!data) {
119+
res.statusCode = 400;
120+
res.setHeader("Content-Type","text/plain");
121+
res.end("Sorry, bad query!");
122+
}
123+
else if(!data[0]) {
124+
res.statusCode = 200;
125+
res.setHeader("Content-Type","text/plain");
126+
res.end("Sorry, no field by that name exists!");
127+
}
128+
else {
129+
res.statusCode = 200;
130+
res.setHeader('Content-Type', 'application/json');
131+
res.end(JSON.stringify(data));
132+
}
133+
134+
});
135+
136+
Router.route('/api/metadata/get', {where: 'server'})
137+
.get(function () {
138+
var req = this.request.body;
139+
var res = this.response;
140+
var query;
141+
142+
parseQueryParams(this.params.query, function(err, params) {
143+
query = params;
144+
console.log(params);
145+
146+
});
147+
148+
var data = Metadata.find(query).fetch();
149+
150+
if (data) {
151+
res.statusCode = 200;
152+
res.setHeader("Content-Type","application/json");
153+
res.end(JSON.stringify(data));
154+
} else {
155+
res.statusCode = 400;
156+
res.setHeader("Content-Type","text/plain");
157+
this.response.end("Metadata not found!");
158+
}
159+
});
160+
161+
Router.route('/api/metadata/set', { where: 'server' })
162+
.post(function () {
163+
var res = this.response;
164+
var newMD = this.request.body.metadata;
165+
var newId = '';
166+
var resObj = {};
167+
168+
if(newMD) {
169+
newId = Metadata.insert(newMD);
170+
resObj['_id'] = newId;
171+
res.statusCode = 200;
172+
res.setHeader("Content-Type","application/json");
173+
res.end(JSON.stringify(resObj));
174+
}
175+
else {
176+
resObj['_id'] = newId;
177+
res.statusCode = 400;
178+
res.setHeader("Content-Type","text/plain");
179+
res.end("Improper JSON - expected metadata field!");
180+
}
181+
182+
res.end();
183+
});
184+
185+
186+
function parseQueryParams(urlQueryParams, callback) { // parses query parameters
187+
var mongoQuery = {};
188+
189+
console.log(JSON.stringify(urlQueryParams));
190+
191+
if(urlQueryParams.age) {
192+
urlQueryParams.age = parseInt(urlQueryParams['age']);
193+
}
194+
195+
if(urlQueryParams.ageRange) {
196+
var ages = urlQueryParams.ageRange.split(",");
197+
var age1 = parseInt(ages[0]);
198+
var age2 = parseInt(ages[1]);
199+
200+
if(age2 > age1) {
201+
urlQueryParams['age'] = {};
202+
urlQueryParams['age']['$lte'] = age2;
203+
urlQueryParams['age']['$gte'] = age1;
204+
205+
console.log(urlQueryParams);
206+
207+
delete urlQueryParams.ageRange;
208+
}
209+
else if(age1 == age2) {
210+
urlQueryParams.age = age1;
211+
delete urlQueryParams.ageRange;
212+
}
213+
else {
214+
urlQueryParams['age'] = {};
215+
urlQueryParams['age']['$lte'] = age1;
216+
urlQueryParams['age']['$gte'] = age2;
217+
218+
console.log(urlQueryParams);
219+
220+
delete urlQueryParams.ageRange;
221+
}
222+
}
223+
224+
if(urlQueryParams.subj_num) {
225+
urlQueryParams.subj_num = parseInt(urlQueryParams['subj_num']);
226+
}
227+
if(urlQueryParams._id) {
228+
urlQueryParams._id = parseInt(urlQueryParams['_id']);
229+
}
230+
if(urlQueryParams.subj_id) {
231+
urlQueryParams.subj_id = parseInt(urlQueryParams['subj_id']);
232+
}
233+
if(urlQueryParams.group) {
234+
urlQueryParams.group = parseInt(urlQueryParams['group']);
235+
}
236+
console.log(JSON.stringify(urlQueryParams));
237+
238+
mongoQuery = urlQueryParams;
239+
240+
callback(null, mongoQuery);
241+
}

0 commit comments

Comments
 (0)