Toggle navigation
Toggle navigation
This project
Loading...
Sign in
khusat
/
khusat-server
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박기홍
2020-11-13 22:31:13 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7d157a7dfe9f7c0093a3b4c783426be07778d7bf
7d157a7d
1 parent
11615e6c
added schemes, router
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
155 additions
and
57 deletions
src/index.js
src/models/jobs.js
src/models/questions.js
src/router/index.js
src/index.js
View file @
7d157a7
...
...
@@ -2,67 +2,20 @@ const express = require('express');
const
app
=
express
();
const
port
=
3000
;
let
questions
=
[]
;
let
jobList
=
[]
;
const
mongoose
=
require
(
'mongoose'
)
;
const
bodyParser
=
require
(
'body-parser'
)
;
app
.
get
(
'/'
,
(
req
,
res
,
next
)
=>
{
res
.
send
(
'hello world!'
);
});
app
.
get
(
'/getQuestions'
,
(
req
,
res
,
next
)
=>
{
/**
* 질문 폼
* 번호 질문내용 답1 답2 가중치1, 가중치2
*/
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
use
(
bodyParser
.
json
());
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
);
const
db
=
mongoose
.
connection
;
db
.
on
(
'error'
,
console
.
error
);
db
.
once
(
'open'
,
function
(){
// CONNECTED TO MONGODB SERVER
console
.
log
(
"Connected to mongod server"
);
});
app
.
post
(
'/submit'
,
(
req
,
res
,
next
)
=>
{
const
{
answer
}
=
req
.
body
;
console
.
log
(
answer
);
const
answerArray
=
[];
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
);
});
mongoose
.
connect
(
'mongodb://localhost/khusat'
);
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`Server is running at
${
port
}
`
);
...
...
src/models/jobs.js
0 → 100644
View file @
7d157a7
const
mongoose
=
require
(
'mongoose'
);
const
schema
=
mongoose
.
Schema
;
const
jobSchema
=
new
schema
({
/**
* 특기병 폼
* 번호, 대분류, 중분류, 소분류, 설명, 사진
*/
num
:{
type
:
Number
,
default
:
-
1
},
high
:{
type
:
String
,
default
:
"대분류를 입력하세요"
,
},
middle
:{
type
:
String
,
default
:
"중분류를 입력하세요"
,
},
low
:{
type
:
String
,
default
:
"소분류를 입력하세요"
,
},
description
:{
type
:
String
,
default
:
"보직 설명"
,
},
image
:{
type
:
String
,
default
:
"???/???"
}
});
module
.
exports
=
mongoose
.
model
(
'job'
,
jobSchema
);
\ No newline at end of file
src/models/questions.js
0 → 100644
View file @
7d157a7
const
mongoose
=
require
(
'mongoose'
);
const
schema
=
mongoose
.
Schema
;
const
questionSchema
=
new
schema
({
/**
* 질문 폼
* 번호 질문내용 답1 답2 가중치1, 가중치2
*/
questionNum
:{
type
:
Number
,
default
:
-
1
},
question
:
{
type
:
String
,
default
:
"질문"
,
},
answer1
:
{
type
:
String
,
default
:
"그렇다"
},
answer2
:
{
type
:
String
,
default
:
"아니다"
},
score1
:
{
type
:
Number
,
default
:
50
,
},
score2
:
{
type
:
Number
,
default
:
-
50
,
},
});
module
.
exports
=
mongoose
.
model
(
'question'
,
questionSchema
);
\ No newline at end of file
src/router/index.js
0 → 100644
View file @
7d157a7
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
);
});
}
\ No newline at end of file
Please
register
or
login
to post a comment