-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
148 lines (127 loc) · 3.92 KB
/
index.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const express = require("express");
const app = express();
const port = process.env.PORT || 9000;
const cors = require("cors");
const corsOptions = {
origin: "*",
credentials: true, //access-control-allow-credentials:true
optionSuccessStatus: 200,
};
app.use(cors(corsOptions));
app.listen(port, () => console.log(`listening on port: ${port}`));
const queries = require("./queries");
app.get("/", (request, response) => {
queries.getAll().then((results) => response.send(results));
});
app.get("/difficulties/:type", (request, response) => {
queries
.getDifficulties(request.params.type)
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/questions/:lesson_id", (request, response) => {
queries
.getQuestions(request.params.lesson_id)
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/lesson/:lesson_id", (request, response) => {
queries
.getLesson(request.params.lesson_id)
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/lessons/:rank_id", (request, response) => {
queries
.getLessons(request.params.rank_id)
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/lessonID/:type/:difficulty/:level/:lesson_number", (req, res) => {
queries
.getLessonID(
req.params.type,
req.params.difficulty,
req.params.level,
req.params.lesson_number,
)
.then((results) => res.send(results))
.catch((error) => res.send(error));
});
app.get("/rankID/:type/:difficulty/:level", (request, response) => {
queries
.getRankID(
request.params.type,
request.params.difficulty,
request.params.level,
)
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/scores/:rank_id", (request, response) => {
queries
.getScores(request.params.rank_id)
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/ranks", (request, response) => {
queries
.getAllRanks()
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/maxRanks", (request, response) => {
queries
.getMaxRanks()
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/typeScores", (request, response) => {
queries
.getTypeTotalScores()
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/challengeQuestions/:rank_id", (request, response) => {
queries
.getChallengeQuestions(request.params.rank_id)
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/showRankChallenge/:rank_id", (request, response) => {
queries
.getShowRankChallenge(request.params.rank_id)
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/userCurrentLevel", (request, response) => {
queries
.getCurrentLevel()
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.get("/nextRank/:rank_id", (request, response) => {
queries
.getNextRank(request.params.rank_id)
.then((results) => response.send(results))
.catch((error) => response.send(error));
});
app.post(
"/updateLessonScore/:lesson_id/:score/:rank_id",
(request, response) => {
queries
.updateLessonScore(
request.params.lesson_id,
request.params.score,
request.params.rank_id,
)
.then((results) => response.send(results))
.catch((error) => response.send(error));
},
);
app.post("/updateRank/:rank_id", (request, response) => {
queries
.updateRankCompleted(request.params.rank_id)
.then((results) => response.send(results))
.catch((error) => response.send(error));
});