Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
survey
Commits
94aeb983
Commit
94aeb983
authored
Jul 06, 2022
by
Jiwon Yoon
Browse files
question DB
parent
7650280d
Changes
11
Hide whitespace changes
Inline
Side-by-side
frontend/src/CreateSurveyForm/CreateSurveyFormPage.tsx
View file @
94aeb983
import
React
,
{
useState
}
from
"
react
"
;
import
{
Question
}
from
"
./Question
"
;
import
axios
from
"
axios
"
;
export
interface
BasicQuestionType
{
type
:
string
;
...
...
@@ -119,6 +120,9 @@ const RatingQ: RatingType = {
export
const
CreateSurveyForm
=
()
=>
{
const
[
currentId
,
setCurrentId
]
=
useState
<
string
>
(
""
);
const
[
error
,
setError
]
=
useState
(
""
);
const
[
disabled
,
setDisabled
]
=
useState
(
false
);
const
[
success
,
setSuccess
]
=
useState
(
false
);
const
[
questionList
,
setQuestionList
]
=
useState
<
Array
<
BasicQuestionType
>>
([
EssayQ
,
RadioQ
,
...
...
@@ -138,7 +142,20 @@ export const CreateSurveyForm = () => {
setQuestionList
(
newList
);
}
function
addQuestion
():
void
{
async
function
addQuestion
(
event
:
React
.
MouseEvent
<
HTMLButtonElement
>
)
{
event
.
preventDefault
();
try
{
const
res
=
await
axios
.
post
(
"
/api/question/create
"
);
console
.
log
(
"
서버연결됬나요
"
,
res
);
console
.
log
(
"
회원가입
"
);
setSuccess
(
true
);
setError
(
""
);
}
catch
(
error
)
{
console
.
log
(
"
에러발생
"
);
// catchErrors(error, setError)
}
finally
{
// setLoading(false);
}
//무작위로 12자리 ID제공, 추후에 질문을 DB에 생성하고 _id를 DB에서 가져오는 것으로 교체할 예정
function
getRandomInt
(
min
:
number
,
max
:
number
):
string
{
min
=
Math
.
ceil
(
min
);
...
...
frontend/src/CreateSurveyForm/Question.tsx
View file @
94aeb983
...
...
@@ -10,7 +10,7 @@ import { QRating } from "./QRating";
type
Props
=
{
questionList
:
BasicQuestionType
[];
QuestionListChange
:
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
void
;
addQuestion
:
()
=>
void
;
addQuestion
:
(
event
:
React
.
MouseEvent
<
HTMLButtonElement
>
)
=>
void
;
changeCurrentId
:
(
event
:
React
.
MouseEvent
<
HTMLButtonElement
>
)
=>
void
;
};
...
...
src/controllers/index.ts
View file @
94aeb983
export
*
as
userCtrl
from
"
./user.controller
"
;
export
*
as
authCtrl
from
"
./auth.controller
"
;
export
*
as
questionCtrl
from
"
./question.controller
"
;
src/controllers/question.controller.ts
0 → 100644
View file @
94aeb983
import
{
questionDb
}
from
"
../db
"
;
import
{
asyncWrap
}
from
"
../helpers/asyncWrap
"
;
export
const
createQuestion
=
asyncWrap
(
async
(
req
,
res
)
=>
{
const
question
=
req
.
body
;
console
.
log
(
"
question body
"
,
question
);
const
newQuestion
=
await
questionDb
.
createQuestion
(
question
);
return
res
.
json
(
question
);
});
src/db/index.ts
View file @
94aeb983
export
*
as
userDb
from
"
./user.db
"
;
export
*
as
questionDb
from
"
./question.db
"
;
src/db/question.db.ts
0 → 100644
View file @
94aeb983
import
{
Question
,
IQuestion
}
from
"
../models
"
;
export
const
createQuestion
=
async
(
question
:
IQuestion
)
=>
{
const
newQuestion
=
await
Question
.
create
(
question
);
return
newQuestion
;
};
src/models/index.ts
View file @
94aeb983
export
{
default
as
User
,
IUser
}
from
"
./user.model
"
;
export
{
default
as
Question
,
IQuestion
}
from
"
./question.model
"
;
src/models/question.model.ts
0 → 100644
View file @
94aeb983
import
{
model
,
Schema
,
Types
}
from
"
mongoose
"
;
export
interface
IQuestion
{
type
:
string
;
id
:
string
;
title
?:
string
;
isRequired
:
boolean
;
comment
?:
string
;
content
?:
any
;
}
const
schema
=
new
Schema
<
IQuestion
>
({
id
:
{
type
:
String
},
type
:{
type
:
String
},
title
:
{
type
:
String
},
isRequired
:
{
type
:
Boolean
},
comment
:{
type
:
String
},
content
:{
type
:
Object
},
});
export
default
model
<
IQuestion
>
(
"
Question
"
,
schema
);
\ No newline at end of file
src/models/user.model.ts
View file @
94aeb983
...
...
@@ -15,7 +15,7 @@ const validateEmail = (email: string) => {
const
schema
=
new
Schema
<
IUser
>
({
email
:
{
type
:
String
,
rquired
:
true
,
r
e
quired
:
true
,
unique
:
true
,
validate
:
[
validateEmail
,
"
이메일을 입력해주세요
"
],
},
...
...
src/routes/index.ts
View file @
94aeb983
import
express
from
"
express
"
;
import
userRouter
from
"
./user.route
"
;
import
authRouter
from
"
./auth.route
"
;
import
questionRouter
from
"
./question.route
"
;
const
router
=
express
.
Router
();
router
.
use
(
"
/users
"
,
userRouter
);
router
.
use
(
"
/auth
"
,
authRouter
);
router
.
use
(
"
/question
"
,
questionRouter
)
export
default
router
;
src/routes/question.route.ts
0 → 100644
View file @
94aeb983
import
express
from
"
express
"
;
import
{
questionCtrl
}
from
"
../controllers
"
;
const
router
=
express
.
Router
();
router
.
route
(
"
/create
"
)
.
get
()
.
post
(
questionCtrl
.
createQuestion
);
export
default
router
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment