forked from cheekujodhpur/ipho2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheetEditable.txt
72 lines (69 loc) · 2.71 KB
/
sheetEditable.txt
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
app.post('/sheetEditableT1',function(req,res)
{
var country_name ='';
var jsonString = '';
req.on('data',function(data)
{
jsonString += data;
});
req.on('end',function(){
country_name='';
if(jsonString==''){}
else{
var jsonData = JSON.parse('{"' + decodeURI(jsonString).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
var country_name = jsonData['country_name'];
}
MongoClient.connect("mongodb://localhost:27017/test",function(err,db)
{
if(err)
{
console.log(err);
return 0;
}
if(req.ip != null)
{
var ip = req.ip.toString();
}
else
{
console.log("Null IP Error.Carry on");
return;
}
console.log("Connection established to the server at mongodb://localhost:27017/test in response to " + ip.toString());
var subparts = db.collection('subparts');
if(country_name=='')
var marks = db.collection('marks_T1');
else var marks = db.collection('ourMarks_T1');
var users = db.collection('users');
var query = {};
subparts.find({"type":"t1"}).toArray(function(err,items){
var subparts = items[0].subparts;
var maxMarks = items[0].maxMarks;
var query_ob = {};
if(country_name=='')query_ob["ip"] = ip;
else query_ob["country_name"] = country_name;
users.find(query_ob).toArray(function(err,data){
var country_code = data[0].country_code;
//var students = data[0].students;
var students = ['Sirius Sharma','Rigel Armstrong','Saiph Ali Khan'];
var new_ip = data[0].ip;
marks.find({$or:[{"ip":new_ip},{"country_name":country_name}]}).toArray(function(err,items2){
if(items2.length>=1)
{
var leaderMarks = items2[0].leaderMarks;
}
else
var leaderMarks = [];
query['subparts'] = subparts;
query['leaderMarks'] = leaderMarks;
query['maxMarks'] = maxMarks;
query['students'] = students;
query['country_code'] = country_code;
res.json(query);
db.close();
});
});
});
});
});
});