-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.js
62 lines (53 loc) · 1.7 KB
/
actions.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
var fs = require('fs');
var Document = require("./modules/models/document").Document;
var Category = require("./modules/models/category").Category;
var Stem = require("./modules/models/stem").Stem;
function index(response, postData) {
fs.readFile('./public/index.html', function(error, content) {
if (error) {
response.writeHead(500);
response.end();
}
else {
response.writeHead(200, {'Content-Type': 'text/html'});
response.end(content, 'utf-8');
}
});
}
function getMainInfo(response, postData) {
var resp = new Object();
Document.getDocumentsCount({
end: function(count) {
resp["docsCount"] = count;
Stem.getStemsCount({
end: function(count) {
resp["stemsCount"] = count;
response.writeHead(200, {'Content-Type': 'text/json'});
response.end(JSON.stringify(resp), 'utf-8');
}
})
},
error: function(error) {
response.writeHead(500);
response.end();
}
})
}
function getCategories (response, postData) {
Category.getActive({
end: function(data) {
var resp = new Object();
resp["identifier"] = "id",
resp["label"] = "name",
resp["items"] = data
response.writeHead(200, {'Content-Type': 'text/json'});
response.end(JSON.stringify(resp), 'utf-8');
}
})
}
function proccessDocument(response, postData) {
console.log(postData)
}
exports.index = index;
exports.get_main_info = getMainInfo;
exports.get_categories = getCategories;