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
4f7388bd
Commit
4f7388bd
authored
Jul 15, 2022
by
jang dong hyeok
Browse files
프로필에서 Card에 DB에 있는 데이터 가져다넣기
parent
80a2b663
Changes
6
Show whitespace changes
Inline
Side-by-side
frontend/src/apis/survey.api.ts
View file @
4f7388bd
...
...
@@ -11,6 +11,11 @@ export const getSurvey = async (surveyId: string) => {
const
{
data
}
=
await
axios
.
get
(
`
${
baseUrl
}
/surveys/edit/
${
surveyId
}
`
);
return
data
;
};
//동혁
export
const
getSurveys
=
async
()
=>
{
const
{
data
}
=
await
axios
.
get
(
`
${
baseUrl
}
/surveys/`
);
return
data
;
};
export
const
editSurvey
=
async
(
survey
:
SurveyType
)
=>
{
const
{
data
}
=
await
axios
.
put
(
...
...
frontend/src/profile/MySurvey.tsx
0 → 100644
View file @
4f7388bd
import
React
from
"
react
"
;
import
{
BasicQuestionType
,
SurveyType
}
from
"
../types
"
;
type
Props
=
{
data
:
SurveyType
;
};
export
const
MySurveyCard
=
({
data
}:
Props
)
=>
{
return
(
<
div
className
=
"w-48 h-60 rounded overflow-hidden border-2"
>
<
div
className
=
"px-6 py-4"
>
<
p
className
=
"text-gray-700 text-base"
>
{
data
.
comment
}
</
p
>
</
div
>
<
div
className
=
"flex flex-col py-6"
>
<
div
className
=
"px-2 py-2"
>
<
label
>
{
data
.
title
}
</
label
>
</
div
>
<
div
className
=
"flex justify-end"
>
<
select
className
=
"py-2 w-14 bg-themeColor rounded text-white"
//value={}
//onChange={}
>
<
option
value
=
"option"
>
옵션
</
option
>
<
option
value
=
"option"
>
삭제
</
option
>
<
option
value
=
"option"
>
이름 바꾸기
</
option
>
</
select
>
</
div
>
</
div
>
</
div
>
);
};
frontend/src/profile/Profile.tsx
View file @
4f7388bd
import
React
,
{
useState
}
from
"
react
"
;
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useNavigate
}
from
"
react-router-dom
"
;
import
{
surveyApi
}
from
"
../apis
"
;
import
{
SurveyType
}
from
"
../types
"
;
import
{
MySurveyCard
}
from
"
./MySurvey
"
;
const
testData
=
[
{
id
:
0
,
name
:
"
이름1
"
,
description
:
"
설명1
"
},
{
id
:
1
,
name
:
"
이름2
"
,
description
:
"
설명2
"
},
{
id
:
2
,
name
:
"
이름3
"
,
description
:
"
설명3
"
},
];
export
const
Profile
=
()
=>
{
const
navigate
=
useNavigate
();
const
[
survey
,
setSurvey
]
=
useState
<
SurveyType
>
({
...
...
@@ -11,6 +17,11 @@ export const Profile = () => {
comment
:
""
,
questions
:
[],
});
const
[
cardDatas
,
setCardDatas
]
=
useState
<
SurveyType
[]
>
([]);
useEffect
(()
=>
{
getSurveys
();
},
[
cardDatas
]);
async
function
createSurvey
()
{
const
newSurvey
:
SurveyType
=
await
surveyApi
.
createSurvey
(
survey
);
navigate
(
`/surveys/edit/
${
newSurvey
.
_id
}
`
,
{
...
...
@@ -18,6 +29,12 @@ export const Profile = () => {
});
}
async
function
getSurveys
()
{
const
surveys
:
SurveyType
[]
=
await
surveyApi
.
getSurveys
();
setCardDatas
(
surveys
);
}
// let surveys = getSurvey(_id);
return
(
<
div
className
=
"flex flex-col items-center"
>
<
div
className
=
"m-5"
>
나의 설문조사
</
div
>
...
...
@@ -30,82 +47,9 @@ export const Profile = () => {
CREATE NEW SURVEY!
</
div
>
</
button
>
<
div
className
=
"w-48 h-60 rounded overflow-hidden border-2"
>
<
div
className
=
"px-6 py-4"
>
<
p
className
=
"text-gray-700 text-base"
>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</
p
>
</
div
>
<
div
className
=
"flex flex-col py-6"
>
<
div
className
=
"px-2 py-2"
>
<
label
>
설문조사 이름
</
label
>
</
div
>
<
div
className
=
"flex justify-end"
>
<
select
className
=
"py-2 w-14 bg-themeColor rounded text-white"
>
<
option
selected
>
옵션
</
option
>
<
option
>
삭제
</
option
>
<
option
>
이름 바꾸기
</
option
>
</
select
>
</
div
>
</
div
>
</
div
>
<
div
className
=
"w-48 h-60 rounded overflow-hidden border-2"
>
<
div
className
=
"px-6 py-4"
>
<
p
className
=
"text-gray-700 text-base"
>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</
p
>
</
div
>
<
div
className
=
"flex flex-col py-6"
>
<
div
className
=
"px-2 py-2"
>
<
label
>
설문조사이름
</
label
>
</
div
>
<
div
className
=
"flex justify-end"
>
<
select
className
=
"py-2 w-14 bg-themeColor rounded text-white"
>
<
option
selected
>
옵션
</
option
>
<
option
>
삭제
</
option
>
<
option
>
이름 바꾸기
</
option
>
</
select
>
</
div
>
</
div
>
</
div
>
<
div
className
=
"w-48 h-60 rounded overflow-hidden border-2"
>
<
div
className
=
"px-6 py-4"
>
<
p
className
=
"text-gray-700 text-base"
>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</
p
>
</
div
>
<
div
className
=
"flex flex-col py-6"
>
<
div
className
=
"px-2 py-2"
>
<
label
>
설문조사 이름
</
label
>
</
div
>
<
div
className
=
"flex justify-end"
>
<
select
className
=
"py-2 w-14 bg-themeColor rounded text-white"
>
<
option
selected
>
옵션
</
option
>
<
option
>
삭제
</
option
>
<
option
>
이름 바꾸기
</
option
>
</
select
>
</
div
>
</
div
>
</
div
>
<
div
className
=
"w-48 h-60 rounded overflow-hidden border-2"
>
<
div
className
=
"px-6 py-4"
>
<
p
className
=
"text-gray-700 text-base"
>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</
p
>
</
div
>
<
div
className
=
"flex flex-col py-6"
>
<
div
className
=
"px-2 py-2"
>
<
label
>
설문조사 이름
</
label
>
</
div
>
<
div
className
=
"flex justify-end"
>
<
select
className
=
"py-2 w-14 bg-themeColor rounded text-white"
>
<
option
selected
>
옵션
</
option
>
<
option
>
삭제
</
option
>
<
option
>
이름 바꾸기
</
option
>
</
select
>
</
div
>
</
div
>
</
div
>
{
cardDatas
.
map
((
data
,
i
)
=>
{
return
<
MySurveyCard
data
=
{
data
}
key
=
{
i
}
/>;
})
}
</
div
>
</
div
>
);
...
...
src/controllers/survey.controller.ts
View file @
4f7388bd
...
...
@@ -26,6 +26,12 @@ export const getSurveyById = asyncWrap(async (req, res) => {
return
res
.
json
(
survey
);
});
//동혁
export
const
getSurveys
=
asyncWrap
(
async
(
req
,
res
)
=>
{
const
surveys
=
await
surveyDb
.
getSurveys
();
return
res
.
json
(
surveys
);
});
export
const
updateSurvey
=
asyncWrap
(
async
(
req
,
res
)
=>
{
const
survey
=
req
.
body
;
const
newSurvey
=
await
surveyDb
.
updateSurvey
(
survey
);
...
...
src/db/survey.db.ts
View file @
4f7388bd
...
...
@@ -20,6 +20,10 @@ export const getSurveyById = async (surveyId: string) => {
const
survey
=
await
Survey
.
findById
(
surveyId
).
populate
(
"
questions
"
);
return
survey
;
};
export
const
getSurveys
=
async
()
=>
{
const
surveys
=
await
Survey
.
find
();
return
surveys
;
};
export
const
updateSurvey
=
async
(
survey
:
ISurvey
)
=>
{
const
newSurvey
=
await
Survey
.
findOneAndUpdate
({
_id
:
survey
.
_id
},
survey
);
...
...
src/routes/survey.route.ts
View file @
4f7388bd
...
...
@@ -8,7 +8,8 @@ router
.
route
(
"
/edit/:surveyId
"
)
.
get
(
authCtrl
.
requireLogin
,
authCtrl
.
authenticate
,
surveyCtrl
.
getSurveyById
)
.
put
(
authCtrl
.
requireLogin
,
authCtrl
.
authenticate
,
surveyCtrl
.
updateSurvey
);
router
.
route
(
"
/
"
)
.
get
(
authCtrl
.
requireLogin
,
surveyCtrl
.
getSurveys
);
router
.
param
(
"
surveyId
"
,
surveyCtrl
.
userBySurveyId
);
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