Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
students
survey
Commits
96d0a352
Commit
96d0a352
authored
Sep 19, 2022
by
Jiwon Yoon
Browse files
Merge branch 'main' into edit-ui
parents
ff284f3c
b9c83052
Changes
5
Hide whitespace changes
Inline
Side-by-side
frontend/src/surveys/EditSurvey.tsx
View file @
96d0a352
...
@@ -26,10 +26,10 @@ export const EditSurvey = () => {
...
@@ -26,10 +26,10 @@ export const EditSurvey = () => {
// return result;
// return result;
// };
// };
const
handleTitle
=
(
title
:
string
)
=>
{
const
handleTitle
Comment
=
(
state
:
{
title
:
string
;
comment
:
string
}
)
=>
{
console
.
log
(
"
title in handle title
:
"
,
titl
e
);
console
.
log
(
"
title in handle title
and comment:
"
,
stat
e
);
// survey.title = title
// survey.title = title
update
({
...
survey
,
title
:
title
});
update
({
...
survey
,
title
:
state
.
title
,
comment
:
state
.
comment
});
};
};
/**
/**
...
@@ -86,7 +86,7 @@ export const EditSurvey = () => {
...
@@ -86,7 +86,7 @@ export const EditSurvey = () => {
addQuestion
=
{
addQuestion
}
addQuestion
=
{
addQuestion
}
deleteQuestion
=
{
deleteQuestion
}
deleteQuestion
=
{
deleteQuestion
}
handleQuestion
=
{
updateQuestion
}
handleQuestion
=
{
updateQuestion
}
handleTitle
=
{
handleTitle
}
handleTitle
Comment
=
{
handleTitle
Comment
}
// callApi={update}
// callApi={update}
/>
/>
);
);
...
...
frontend/src/surveys/ModifySurveyView.tsx
View file @
96d0a352
...
@@ -5,6 +5,7 @@ import { SpinnerIcon } from "../icons";
...
@@ -5,6 +5,7 @@ import { SpinnerIcon } from "../icons";
import
{
CreateQuestionData
,
ISurvey
}
from
"
../types
"
;
import
{
CreateQuestionData
,
ISurvey
}
from
"
../types
"
;
import
{
QuestionsList
}
from
"
./QuestionsList
"
;
import
{
QuestionsList
}
from
"
./QuestionsList
"
;
import
{
SurveyTitle
}
from
"
./SurveyTitle
"
;
import
{
SurveyTitle
}
from
"
./SurveyTitle
"
;
import
{
SurveyTitleAndComment
}
from
"
./SurveyTitleAndComment
"
;
type
Props
=
{
type
Props
=
{
questions
:
CreateQuestionData
[];
questions
:
CreateQuestionData
[];
...
@@ -12,7 +13,7 @@ type Props = {
...
@@ -12,7 +13,7 @@ type Props = {
addQuestion
:
()
=>
void
;
addQuestion
:
()
=>
void
;
deleteQuestion
:
(
id
:
string
)
=>
void
;
deleteQuestion
:
(
id
:
string
)
=>
void
;
handleQuestion
:
(
question
:
CreateQuestionData
)
=>
void
;
handleQuestion
:
(
question
:
CreateQuestionData
)
=>
void
;
handleTitle
:
Function
;
handleTitle
Comment
:
Function
;
// callApi: (surveyData: ISurvey) => Promise<any>;
// callApi: (surveyData: ISurvey) => Promise<any>;
};
};
...
@@ -22,7 +23,7 @@ export const ModifySurveyView = ({
...
@@ -22,7 +23,7 @@ export const ModifySurveyView = ({
addQuestion
,
addQuestion
,
deleteQuestion
,
deleteQuestion
,
handleQuestion
,
handleQuestion
,
handleTitle
,
handleTitle
Comment
,
}:
// callApi,
}:
// callApi,
Props
)
=>
{
Props
)
=>
{
const
[
error
,
setError
]
=
useState
(
""
);
const
[
error
,
setError
]
=
useState
(
""
);
...
@@ -104,8 +105,13 @@ Props) => {
...
@@ -104,8 +105,13 @@ Props) => {
)
}
)
}
<
form
>
<
form
>
<
div
className
=
"flex flex-col place-items-center"
>
<
div
className
=
"flex flex-col place-items-center"
>
<
SurveyTitle
text
=
{
survey
.
title
}
handleTitle
=
{
handleTitle
}
/>
{
/* <SurveyTitle text={survey.title} handleTitle={handleTitle} /> */
}
<
div
className
=
"flex flex-col container place-items-center mt-4"
>
<
SurveyTitleAndComment
title
=
{
survey
.
title
}
comment
=
{
survey
.
comment
}
handleTitleComment
=
{
handleTitleComment
}
/>
{
/* <div className="flex flex-col container place-items-center mt-4">
<input
<input
type="text"
type="text"
name="title"
name="title"
...
@@ -125,7 +131,7 @@ Props) => {
...
@@ -125,7 +131,7 @@ Props) => {
value={survey.comment}
value={survey.comment}
onChange={handleChange}
onChange={handleChange}
></input>
></input>
</
div
>
</div>
*/
}
<
QuestionsList
<
QuestionsList
questions
=
{
questions
}
questions
=
{
questions
}
handleQuestion
=
{
handleQuestion
}
handleQuestion
=
{
handleQuestion
}
...
...
frontend/src/surveys/SurveyTitleAndComment.tsx
0 → 100644
View file @
96d0a352
import
React
,
{
ChangeEvent
,
ChangeEventHandler
,
MouseEventHandler
,
useState
,
}
from
"
react
"
;
type
Props
=
{
// isEditing: boolean;
title
:
string
;
comment
:
string
;
handleTitleComment
:
Function
;
};
export
const
SurveyTitleAndComment
=
({
comment
,
title
,
handleTitleComment
,
}:
Props
)
=>
{
const
[
state
,
setState
]
=
useState
({
title
:
title
,
comment
:
comment
});
const
[
disabled
,
setDisabled
]
=
useState
(
true
);
console
.
log
(
"
title:
"
,
title
,
"
comment:
"
,
comment
,
"
state:
"
,
state
);
const
handleChange
=
(
e
:
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
{
name
,
value
}
=
e
.
target
;
setState
({
...
state
,
[
name
]:
value
});
};
const
onEdit
=
()
=>
{
setDisabled
(
false
);
};
const
onCancel
=
()
=>
{
setDisabled
(
true
);
setState
({
title
,
comment
});
};
const
handleConfirm
=
()
=>
{
setDisabled
(
true
);
handleTitleComment
(
state
);
};
return
(
<
div
className
=
{
`flex flex-col container w-4/5 h-auto border-2 items-center m-3 py-2 rounded-lg
${
disabled
?
"
border-themeColor
"
:
"
border-red-500
"
}
`
}
>
<
input
type
=
"text"
name
=
"title"
className
=
"font-bold text-4xl text-center m-2 border-b-2"
placeholder
=
"설문지 제목"
autoComplete
=
"on"
value
=
{
state
.
title
}
disabled
=
{
disabled
}
onChange
=
{
handleChange
}
/>
<
input
type
=
"text"
name
=
"comment"
className
=
"font-bold text-1xl text-center m-2 border-b-2 resize-none"
placeholder
=
"설문조사에 대한 설명을 입력해주세요"
autoComplete
=
"on"
size
=
{
50
}
value
=
{
state
.
comment
}
disabled
=
{
disabled
}
onChange
=
{
handleChange
}
/>
<
div
className
=
"flex w-11/12 justify-end"
>
{
disabled
?
(
<>
<
button
type
=
"button"
className
=
"px-1"
onClick
=
{
onEdit
}
>
수정
</
button
>
</>
)
:
(
<>
<
button
type
=
"button"
className
=
"px-1"
onClick
=
{
onCancel
}
>
취소
</
button
>
<
button
type
=
"button"
className
=
"px-1"
onClick
=
{
handleConfirm
}
>
확인
</
button
>
</>
)
}
</
div
>
</
div
>
);
};
src/controllers/survey.controller.ts
View file @
96d0a352
...
@@ -67,8 +67,8 @@ export const getSurveys = asyncWrap(async (reqExp: Request, res: Response) => {
...
@@ -67,8 +67,8 @@ export const getSurveys = asyncWrap(async (reqExp: Request, res: Response) => {
export
const
updateSurvey
=
asyncWrap
(
async
(
req
,
res
)
=>
{
export
const
updateSurvey
=
asyncWrap
(
async
(
req
,
res
)
=>
{
const
survey
=
req
.
body
;
const
survey
=
req
.
body
;
const
new
Survey
=
await
surveyDb
.
updateSurvey
(
survey
);
const
updated
Survey
=
await
surveyDb
.
updateSurvey
(
survey
);
return
res
.
json
(
new
Survey
);
return
res
.
json
(
updated
Survey
);
});
});
export
const
userBySurveyId
=
async
(
export
const
userBySurveyId
=
async
(
...
...
src/db/survey.db.ts
View file @
96d0a352
...
@@ -75,18 +75,22 @@ export const getSurveys = async (userId: string) => {
...
@@ -75,18 +75,22 @@ export const getSurveys = async (userId: string) => {
export
const
updateSurvey
=
async
(
survey
:
HydratedDocument
<
ISurvey
>
)
=>
{
export
const
updateSurvey
=
async
(
survey
:
HydratedDocument
<
ISurvey
>
)
=>
{
console
.
log
(
"
update survey
"
,
survey
);
console
.
log
(
"
update survey
"
,
survey
);
await
Promise
.
all
(
// await Promise.all(
survey
.
questions
.
map
(
// survey.questions.map(
async
(
question
)
=>
// async (question) =>
await
Question
.
findOneAndUpdate
({
_id
:
question
.
_id
},
question
,
{
// await Question.findOneAndUpdate({ _id: question._id }, question, {
upsert
:
true
,
// upsert: true,
})
// })
)
// )
);
// );
const
newSurvey
=
await
Survey
.
findOneAndUpdate
({
_id
:
survey
.
_id
},
survey
,
{
const
updatedSurvey
=
await
Survey
.
findOneAndUpdate
(
new
:
true
,
{
_id
:
survey
.
_id
},
}).
populate
(
"
questions
"
);
survey
,
return
newSurvey
;
{
new
:
true
,
}
).
populate
(
"
questions
"
);
return
updatedSurvey
;
};
};
export
const
putNewQuestion
=
async
(
newQuestion
:
any
,
surveyId
:
string
)
=>
{
export
const
putNewQuestion
=
async
(
newQuestion
:
any
,
surveyId
:
string
)
=>
{
...
...
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