박기홍

db fixed

1 node_modules/ 1 node_modules/
2 yarn.lock 2 yarn.lock
3 +.DS_Store
...\ No newline at end of file ...\ No newline at end of file
......
No preview for this file type
No preview for this file type
1 const express = require('express'); 1 const express = require('express');
2 const app = express(); 2 const app = express();
3 -const port = 3000; 3 +const port = 8000;
4 4
5 const mongoose = require('mongoose'); 5 const mongoose = require('mongoose');
6 const bodyParser = require('body-parser'); 6 const bodyParser = require('body-parser');
7 -const router = require('./router')(app);
8 7
9 app.use(bodyParser.urlencoded({extended:true})); 8 app.use(bodyParser.urlencoded({extended:true}));
10 app.use(bodyParser.json()); 9 app.use(bodyParser.json());
...@@ -16,6 +15,8 @@ db.once('open', function(){ ...@@ -16,6 +15,8 @@ db.once('open', function(){
16 console.log("Connected to mongod server"); 15 console.log("Connected to mongod server");
17 }); 16 });
18 17
18 +const router = require('./router')(app);
19 +
19 20
20 mongoose.connect('mongodb://localhost/khusat'); 21 mongoose.connect('mongodb://localhost/khusat');
21 22
......
1 const Question = require('../models/questions'); 1 const Question = require('../models/questions');
2 const Job = require('../models/jobs'); 2 const Job = require('../models/jobs');
3 +const bodyParser = require('body-parser');
3 4
5 +bodyParser.json();
4 6
5 -module.exports = function(app) 7 +async function jobRecommend(fight, detail, traffic, control, support, activity){
6 -{ 8 + const jobs = await Job.find().exec();
9 +
10 + let scores = [fight, detail, traffic, control, support];
11 + const bar = 50;
12 +
13 + // 내림차순 정렬
14 + scores.sort(function(a, b) {
15 + return b-a;
16 + });
17 +
18 + if(activity >= bar){
19 + // 동적
20 + if(scores[0] === fight){
21 + // 전투성향 높음 : 보병, 기갑
22 + if(detail >= bar){
23 + return "포병";
24 + }
25 + else if(traffic >= bar){
26 + // 기갑
27 + return "기갑";
28 + }
29 + return "보병";
30 + }
31 + else if(scores[0] === detail){
32 + return "포병";
33 + }
34 + else if(scores[0] === traffic){
35 + if(fight >= bar){
36 + return "기갑";
37 + }
38 + else{
39 + return "수송";
40 + }
41 + }
42 + else if(scores[0] === control){
43 + return "헌병";
44 + }
45 + else{
46 + return "의무";
47 + }
48 + }
49 + else{
50 + //정적
51 + if(scores[0] === fight){
52 + // 전투성향 높음
53 + if(detail >= bar){
54 + return "방공";
55 + }
56 + return "화생방";
57 + }
58 + else if(scores[0] === detail){
59 + if(fight >= bar){
60 + return "방공";
61 + }
62 + return "공병";
63 + }
64 + else if(scores[0] === traffic){
65 + return "보급";
66 + }
67 + else if(scores[0] === control){
68 + if(support >= bar){
69 + return "정보통신";
70 + }
71 + return "인사";
72 + }
73 + else{
74 + if(control>=bar){
75 + return "정보통신";
76 + }
77 + else if(fight >= bar){
78 + return "화생방";
79 + }
80 + else if(traffic >= bar){
81 + return "보급";
82 + }
83 + else{
84 + return "정보";
85 + }
86 + }
87 + }
7 88
8 - // let questions = []; 89 + return "보병";
9 - // let jobList = []; 90 +}
10 91
92 +module.exports = function(app)
93 +{
11 app.get('/', (req, res, next) => { 94 app.get('/', (req, res, next) => {
12 res.send('hello world!'); 95 res.send('hello world!');
13 }); 96 });
...@@ -42,31 +125,53 @@ module.exports = function(app) ...@@ -42,31 +125,53 @@ module.exports = function(app)
42 }); 125 });
43 126
44 app.post('/submit', async (req, res, next) => { 127 app.post('/submit', async (req, res, next) => {
45 - const {answer} = req.body; 128 + const answers = req.body;
46 - console.log(answer); 129 + // console.log(answers);
47 -
48 - const answerArray = await Job.find().exec();
49 130
50 - let score = 50; 131 + let fight = 50;
132 + let detail = 50;
133 + let traffic = 50;
134 + let control = 50;
135 + let support = 50;
136 + let activity = 50;
51 137
52 /** 138 /**
53 * 정답 폼 139 * 정답 폼
54 * 문항 번호 정답 고른것 140 * 문항 번호 정답 고른것
55 */ 141 */
56 142
57 - for(let i=0; i< answerArray.length; i++){ 143 + for(let i=0; i<answers.length; i++){
58 - if(answerArray[i][1] === 0){ 144 + const question = await Question.findOne({num: answers[i].num}).exec();
59 - // 1번답 골랐을때 145 + if(question.choice === 0){
60 - score += questions[answerArray[i]][3]; 146 + fight += question.fight;
147 + detail += question.detail;
148 + traffic += question.traffic;
149 + control += question.control;
150 + support += question.support;
151 + activity += question.activity;
61 } 152 }
62 else{ 153 else{
63 - score += questions[answerArray[i]][4]; 154 + fight -= question.fight;
155 + detail -= question.detail;
156 + traffic -= question.traffic;
157 + control -= question.control;
158 + support -= question.support;
159 + activity -= question.activity;
64 } 160 }
65 } 161 }
66 162
67 - const recommendedJob = jobList[score%jobList.length]; 163 + console.log(fight, detail, traffic, control, support, activity);
164 + const recommandedJob = await jobRecommend(fight, detail, traffic, control, support, activity);
165 +
166 + // TODO : recommand job
167 + // const jobList = await Job.find({high: recommandedJob}).exec();
168 +
169 + // const rand = Math.floor(Math.random() * jobList.length);
170 + // const result = jobList[rand];
171 +
172 + res.send(recommandedJob);
173 + // res.send(result);
68 174
69 - res.send(recommendedJob);
70 }); 175 });
71 176
72 app.post('/addJobs', async(req, res, next) => { 177 app.post('/addJobs', async(req, res, next) => {
...@@ -75,11 +180,10 @@ module.exports = function(app) ...@@ -75,11 +180,10 @@ module.exports = function(app)
75 180
76 181
77 }); 182 });
78 -
79 app.post('/addQuestions', async(req, res, next) => { 183 app.post('/addQuestions', async(req, res, next) => {
80 // 질문 추가하는 api 184 // 질문 추가하는 api
81 const datas = req.body; 185 const datas = req.body;
82 - console.log(datas); 186 + // console.log(datas);
83 console.log(typeof(datas)); 187 console.log(typeof(datas));
84 188
85 for(let i=0; i<datas.length; i++){ 189 for(let i=0; i<datas.length; i++){
...@@ -96,9 +200,12 @@ module.exports = function(app) ...@@ -96,9 +200,12 @@ module.exports = function(app)
96 data.support = datas[i].support; 200 data.support = datas[i].support;
97 data.activity = datas[i].activity; 201 data.activity = datas[i].activity;
98 202
99 - console.log(data); 203 + // console.log(data);
100 204
101 await data.save(); 205 await data.save();
102 } 206 }
207 +
208 + res.send(req.body);
103 }); 209 });
210 +
104 } 211 }
...\ No newline at end of file ...\ No newline at end of file
......