index.js
2.27 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
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
const Question = require('../models/questions');
const Job = require('../models/jobs');
module.exports = function(app)
{
// let questions = [];
// let jobList = [];
app.get('/', (req, res, next) => {
res.send('hello world!');
});
app.get('/getQuestions', async (req, res, next) => {
/**
* 질문 폼
* 번호 질문내용 답1 답2 가중치1, 가중치2
*/
const questions = await Question.find().exec();
let questionNums = [];
const numOfQuestions = 25;
for(let i=0; i<numOfQuestions; i++){
questionNums[i] = i;
}
// shuffle(questionNums);
questionNums.sort(function () {
return Math.round(Math.random()) - 0.5
});
questionNums = questionNums.slice(0, 10);
let sendQuestions = [];
for(let i=0; i<10; i++){
sendQuestions.push(questions[questionNums[i]]);
}
res.send(sendQuestions);
});
app.post('/submit', async (req, res, next) => {
const {answer} = req.body;
console.log(answer);
const answerArray = await Job.find().exec();
let score = 50;
/**
* 정답 폼
* 문항 번호 정답 고른것
*/
for(let i=0; i< answerArray.length; i++){
if(answerArray[i][1] === 0){
// 1번답 골랐을때
score += questions[answerArray[i]][3];
}
else{
score += questions[answerArray[i]][4];
}
}
const recommendedJob = jobList[score%jobList.length];
res.send(recommendedJob);
});
app.post('/addJobs', async(req, res, next) => {
// 보직 추가하는 api
});
app.post('/addQuestions', async(req, res, next) => {
// 질문 추가하는 api
const datas = req.body;
console.log(datas);
console.log(typeof(datas));
for(let i=0; i<datas.length; i++){
const data = new Question();
data.num = datas[i].num;
data.question = datas[i].question;
data.answer1 = datas[i].answer1;
data.answer2 = datas[i].answer2;
data.fight = datas[i].fight;
data.detail = datas[i].detail;
data.traffic = datas[i].traffic;
data.control = datas[i].control;
data.support = datas[i].support;
data.activity = datas[i].activity;
console.log(data);
await data.save();
}
});
}