-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (54 loc) · 1.93 KB
/
index.js
File metadata and controls
68 lines (54 loc) · 1.93 KB
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
const app = require('express')();
const bodyParser = require('body-parser');
const http = require('http').Server(app);
const Impl = require('./impl');
app.use(bodyParser.json());
app.post(/CreateFolder/, (req, res) => {
const folderData = req.body;
Impl.createFolder(folderData).then( () => res.status(200).end() );
});
app.post(/ListFolder/, (req, res) => {
const { _id } = req.body;
Impl.listFolder(_id).then(json => res.json(json));
});
app.post(/GetQuestionsByIds/, (req, res) => {
const { _ids } = req.body;
Impl.getQuestionsByIds(_ids).then(questions => res.json(questions));
});
app.post(/GetQuestionsByTags/, (req, res) => {
const { tags, idParent } = req.body;
Impl.getQuestionsByTags(tags, idParent).then(questions => res.json(questions));
});
app.post(/GetTagsStartingWith/, (req, res) => {
const { start } = req.body;
Impl.getTagsStartingWith(start).then(tags => res.json(tags));
});
app.post(/Rename/, (req, res) => {
const { _id, name } = req.body;
Impl.rename(_id, name).then( () => res.status(200).end() );
});
app.post(/Delete/, (req, res) => {
const { _id } = req.body;
Impl.delete(_id).then(() => res.status(200).end());
});
app.post(/SaveQuestion/, (req, res) => {
const questionData = { ...req.body, type: 'question'};
Impl.saveQuestion(questionData).then( () => res.status(200).end() );
});
app.post(/SaveMultipleChoice/, (req, res) => {
const multipleChoiceData = { ...req.body, type: 'qcm'};
Impl.saveMultipleChoice(multipleChoiceData).then( () => res.status(200).end() );
});
app.post('/GenerateLink', (req, res) => {
const { _id } = req.body;
Impl.generateLink(_id).then(() => res.status(200).end());
});
app.post('/GetMultipleChoice', (req, res) => {
const { url } = req.body;
Impl.getByLink(url).then(questions => res.json(questions));
});
app.post('/SaveSession', (req, res) => {
const { url, session } = req.body;
Impl.saveSession(url, session).then(questions => res.json(questions));
});
http.listen(8080);