박기홍

mongoose added

1 +node_modules/
2 +yarn.lock
...\ No newline at end of file ...\ No newline at end of file
1 # khusat_server 1 # khusat_server
2 +
3 +type yarn
4 +type yarn start or yarn start:dev
......
1 +{
2 + "name": "khusat_server",
3 + "version": "1.0.0",
4 + "main": "index.js",
5 + "repository": "https://github.com/KHUSAT/khusat_server.git",
6 + "author": "kyhong222 <kyhong222@naver.com>",
7 + "license": "MIT",
8 + "dependencies": {
9 + "body-parser": "^1.19.0",
10 + "express": "^4.17.1",
11 + "mongoose": "^5.10.14",
12 + "nodemon": "^2.0.6"
13 + },
14 + "scripts": {
15 + "start": "NODE_PATH=src node src",
16 + "start:dev": "NODE_PATH=src nodemon --watch src/ src/index.js"
17 + }
18 +}
1 +const express = require('express');
2 +const app = express();
3 +const port = 3000;
4 +
5 +let questions = [];
6 +let jobList = [];
7 +
8 +app.get('/', (req, res, next) => {
9 + res.send('hello world!');
10 +});
11 +
12 +app.get('/getQuestions', (req, res, next) => {
13 +
14 +
15 + /**
16 + * 질문 폼
17 + * 번호 질문내용 답1 답2 가중치1, 가중치2
18 + */
19 +
20 + let questionNums = [];
21 + const numOfQuestions = 25;
22 + for(let i=0; i<numOfQuestions; i++){
23 + questionNums[i] = i;
24 + }
25 + // shuffle(questionNums);
26 + questionNums.sort(function () {
27 + return Math.round(Math.random()) - 0.5
28 + });
29 +
30 + questionNums = questionNums.slice(0, 10);
31 +
32 + let sendQuestions = [];
33 + for(let i=0; i<10; i++){
34 + sendQuestions.push(questions[questionNums[i]]);
35 + }
36 + res.send(sendQuestions);
37 +});
38 +
39 +app.post('/submit', (req, res, next) => {
40 + const {answer} = req.body;
41 + console.log(answer);
42 +
43 + const answerArray = [];
44 +
45 + let score = 50;
46 +
47 + /**
48 + * 정답 폼
49 + * 문항 번호 정답 고른것
50 + */
51 +
52 + for(let i=0; i< answerArray.length; i++){
53 + if(answerArray[i][1] === 0){
54 + // 1번답 골랐을때
55 + score += questions[answerArray[i]][3];
56 + }
57 + else{
58 + score += questions[answerArray[i]][4];
59 + }
60 + }
61 +
62 + const recommendedJob = jobList[score%jobList.length];
63 +
64 + res.send(recommendedJob);
65 +});
66 +
67 +app.listen(port, () => {
68 + console.log(`Server is running at ${port}`);
69 +});
...\ No newline at end of file ...\ No newline at end of file