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
7275ba42
Commit
7275ba42
authored
Aug 20, 2022
by
Jiwon Yoon
Browse files
result에 맞게 다시 수정
parent
10f7f53d
Changes
11
Show whitespace changes
Inline
Side-by-side
frontend/src/forms/RCheckbox.tsx
View file @
7275ba42
...
@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
...
@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
type
Props
=
{
type
Props
=
{
question
:
IQuestionData
;
question
:
IQuestionData
;
answers
:
any
;
};
};
export
const
RCheckbox
=
({
question
,
answers
}:
Props
)
=>
{
export
const
RCheckbox
=
({
question
}:
Props
)
=>
{
const
result
=
answers
.
flat
().
reduce
((
acc
:
any
,
cur
:
any
)
=>
{
const
result
=
question
.
answers
.
flat
().
reduce
((
acc
:
any
,
cur
:
any
)
=>
{
acc
[
cur
]
=
(
acc
[
cur
]
||
0
)
+
1
;
acc
[
cur
]
=
(
acc
[
cur
]
||
0
)
+
1
;
return
acc
;
return
acc
;
},
{});
},
{});
...
...
frontend/src/forms/RDate.tsx
View file @
7275ba42
...
@@ -3,13 +3,12 @@ import { IQuestionData } from "../types";
...
@@ -3,13 +3,12 @@ import { IQuestionData } from "../types";
type
Props
=
{
type
Props
=
{
question
:
IQuestionData
;
question
:
IQuestionData
;
answers
:
any
;
};
};
export
const
RDate
=
({
question
,
answers
}:
Props
)
=>
{
export
const
RDate
=
({
question
}:
Props
)
=>
{
return
(
return
(
<
div
className
=
"m-5"
>
<
div
className
=
"m-5"
>
{
answers
.
map
((
answer
:
any
)
=>
(
{
question
.
answers
.
map
((
answer
:
any
)
=>
(
<
div
key
=
{
answer
}
className
=
"font-bold"
>
<
div
key
=
{
answer
}
className
=
"font-bold"
>
{
answer
}
{
answer
}
</
div
>
</
div
>
...
...
frontend/src/forms/RDropdown.tsx
View file @
7275ba42
...
@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
...
@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
type
Props
=
{
type
Props
=
{
question
:
IQuestionData
;
question
:
IQuestionData
;
answers
:
any
;
};
};
export
const
RDropdown
=
({
question
,
answers
}:
Props
)
=>
{
export
const
RDropdown
=
({
question
}:
Props
)
=>
{
const
result
=
answers
.
reduce
((
acc
:
any
,
cur
:
any
)
=>
{
const
result
=
question
.
answers
.
reduce
((
acc
:
any
,
cur
:
any
)
=>
{
acc
[
cur
]
=
(
acc
[
cur
]
||
0
)
+
1
;
acc
[
cur
]
=
(
acc
[
cur
]
||
0
)
+
1
;
return
acc
;
return
acc
;
},
{});
},
{});
...
...
frontend/src/forms/REssay.tsx
View file @
7275ba42
...
@@ -3,13 +3,12 @@ import { IQuestionData } from "../types";
...
@@ -3,13 +3,12 @@ import { IQuestionData } from "../types";
type
Props
=
{
type
Props
=
{
question
:
IQuestionData
;
question
:
IQuestionData
;
answers
:
any
;
};
};
export
const
REssay
=
({
question
,
answers
}:
Props
)
=>
{
export
const
REssay
=
({
question
}:
Props
)
=>
{
return
(
return
(
<
div
className
=
"m-5"
>
<
div
className
=
"m-5"
>
{
answers
.
map
((
answer
:
any
,
index
:
number
)
=>
(
{
question
.
answers
.
map
((
answer
:
any
,
index
:
number
)
=>
(
<
div
key
=
{
index
}
className
=
"font-bold"
>
<
div
key
=
{
index
}
className
=
"font-bold"
>
{
answer
}
{
answer
}
</
div
>
</
div
>
...
...
frontend/src/forms/RFile.tsx
View file @
7275ba42
...
@@ -3,14 +3,13 @@ import { baseImageUrl } from "../apis";
...
@@ -3,14 +3,13 @@ import { baseImageUrl } from "../apis";
type
Props
=
{
type
Props
=
{
question
:
any
;
question
:
any
;
answers
:
any
;
};
};
export
const
RFile
=
({
question
,
answers
}:
Props
)
=>
{
export
const
RFile
=
({
question
}:
Props
)
=>
{
console
.
log
(
"
question
"
,
question
);
console
.
log
(
"
question
"
,
question
);
return
(
return
(
<
div
className
=
"m-5 flex justify-start items-center"
>
<
div
className
=
"m-5 flex justify-start items-center"
>
{
answers
.
map
((
answer
:
any
,
index
:
number
)
=>
(
{
question
.
answers
.
map
((
answer
:
any
,
index
:
number
)
=>
(
<
Fragment
key
=
{
index
}
>
<
Fragment
key
=
{
index
}
>
<
img
<
img
className
=
"h-14"
className
=
"h-14"
...
...
frontend/src/forms/RRadio.tsx
View file @
7275ba42
...
@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
...
@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
type
Props
=
{
type
Props
=
{
question
:
IQuestionData
;
question
:
IQuestionData
;
answers
:
any
;
};
};
export
const
RRadio
=
({
question
,
answers
}:
Props
)
=>
{
export
const
RRadio
=
({
question
}:
Props
)
=>
{
const
result
=
answers
.
reduce
((
acc
:
any
,
cur
:
any
)
=>
{
const
result
=
question
.
answers
.
reduce
((
acc
:
any
,
cur
:
any
)
=>
{
acc
[
cur
]
=
(
acc
[
cur
]
||
0
)
+
1
;
acc
[
cur
]
=
(
acc
[
cur
]
||
0
)
+
1
;
return
acc
;
return
acc
;
},
{});
},
{});
...
...
frontend/src/forms/RRating.tsx
View file @
7275ba42
...
@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
...
@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
type
Props
=
{
type
Props
=
{
question
:
IQuestionData
;
question
:
IQuestionData
;
answers
:
any
;
};
};
export
const
RRating
=
({
question
,
answers
}:
Props
)
=>
{
export
const
RRating
=
({
question
}:
Props
)
=>
{
const
result
=
answers
.
reduce
((
acc
:
any
,
cur
:
any
)
=>
{
const
result
=
question
.
answers
.
reduce
((
acc
:
any
,
cur
:
any
)
=>
{
acc
[
cur
]
=
(
acc
[
cur
]
||
0
)
+
1
;
acc
[
cur
]
=
(
acc
[
cur
]
||
0
)
+
1
;
return
acc
;
return
acc
;
},
{});
},
{});
...
...
frontend/src/helpers/question.helper.tsx
View file @
7275ba42
...
@@ -109,25 +109,22 @@ export const getAnswerElementByType = (
...
@@ -109,25 +109,22 @@ export const getAnswerElementByType = (
}
}
};
};
export
const
getResultElementByType
=
(
export
const
getResultElementByType
=
(
question
:
IQuestionData
)
=>
{
question
:
IQuestionData
,
answers
:
any
)
=>
{
switch
(
question
.
type
)
{
switch
(
question
.
type
)
{
case
"
singletext
"
:
case
"
singletext
"
:
return
<
REssay
question
=
{
question
}
answers
=
{
answers
}
/>;
return
<
REssay
question
=
{
question
}
/>;
case
"
radio
"
:
case
"
radio
"
:
return
<
RRadio
question
=
{
question
}
answers
=
{
answers
}
/>;
return
<
RRadio
question
=
{
question
}
/>;
case
"
checkbox
"
:
case
"
checkbox
"
:
return
<
RCheckbox
question
=
{
question
}
answers
=
{
answers
}
/>;
return
<
RCheckbox
question
=
{
question
}
/>;
case
"
dropdown
"
:
case
"
dropdown
"
:
return
<
RDropdown
question
=
{
question
}
answers
=
{
answers
}
/>;
return
<
RDropdown
question
=
{
question
}
/>;
case
"
file
"
:
case
"
file
"
:
return
<
RFile
question
=
{
question
}
answers
=
{
answers
}
/>;
return
<
RFile
question
=
{
question
}
/>;
case
"
rating
"
:
case
"
rating
"
:
return
<
RRating
question
=
{
question
}
answers
=
{
answers
}
/>;
return
<
RRating
question
=
{
question
}
/>;
case
"
date
"
:
case
"
date
"
:
return
<
RDate
question
=
{
question
}
answers
=
{
answers
}
/>;
return
<
RDate
question
=
{
question
}
/>;
default
:
default
:
return
<></>;
return
<></>;
}
}
...
...
frontend/src/surveys/Accordion.tsx
View file @
7275ba42
...
@@ -4,10 +4,9 @@ import { getResultElementByType } from "../helpers/question.helper";
...
@@ -4,10 +4,9 @@ import { getResultElementByType } from "../helpers/question.helper";
type
AccordionProps
=
{
type
AccordionProps
=
{
question
:
IQuestionData
;
question
:
IQuestionData
;
answers
:
any
;
};
};
export
const
Accordion
=
({
question
,
answers
}:
AccordionProps
)
=>
{
export
const
Accordion
=
({
question
}:
AccordionProps
)
=>
{
const
[
isOpened
,
setOpened
]
=
useState
<
boolean
>
(
false
);
const
[
isOpened
,
setOpened
]
=
useState
<
boolean
>
(
false
);
const
[
height
,
setHeight
]
=
useState
<
string
>
(
"
0px
"
);
const
[
height
,
setHeight
]
=
useState
<
string
>
(
"
0px
"
);
const
contentElement
=
useRef
<
HTMLDivElement
>
(
null
);
const
contentElement
=
useRef
<
HTMLDivElement
>
(
null
);
...
@@ -33,7 +32,7 @@ export const Accordion = ({ question, answers }: AccordionProps) => {
...
@@ -33,7 +32,7 @@ export const Accordion = ({ question, answers }: AccordionProps) => {
style
=
{
{
height
:
height
}
}
style
=
{
{
height
:
height
}
}
className
=
"bg-gray-100 overflow-hidden transition-all duration-300"
className
=
"bg-gray-100 overflow-hidden transition-all duration-300"
>
>
{
answers
&&
getResultElementByType
(
question
,
answers
)
}
{
question
.
answers
&&
getResultElementByType
(
question
)
}
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
...
...
frontend/src/surveys/ResultSurvey.tsx
View file @
7275ba42
...
@@ -51,11 +51,7 @@ export const ResultSurvey = () => {
...
@@ -51,11 +51,7 @@ export const ResultSurvey = () => {
<
div
className
=
"container w-11/12 place-self-center"
>
<
div
className
=
"container w-11/12 place-self-center"
>
{
survey
.
questions
.
map
((
question
)
=>
(
{
survey
.
questions
.
map
((
question
)
=>
(
<
Accordion
<
Accordion
key
=
{
question
.
_id
}
question
=
{
question
}
/>
key
=
{
question
.
_id
}
question
=
{
question
.
questionInfo
}
answers
=
{
question
.
answers
}
/>
))
}
))
}
</
div
>
</
div
>
</
div
>
</
div
>
...
...
src/db/answer.db.ts
View file @
7275ba42
...
@@ -34,6 +34,9 @@ export const getAnswers = async (surveyId: string) => {
...
@@ -34,6 +34,9 @@ export const getAnswers = async (surveyId: string) => {
$unwind
:
"
$questionInfo
"
,
$unwind
:
"
$questionInfo
"
,
},
},
{
$set
:
{
"
questionInfo.answers
"
:
"
$answers
"
}
},
{
$unset
:
"
answers
"
},
// 질문 순서대로 정렬
// 질문 순서대로 정렬
{
$sort
:
{
"
questionInfo.order
"
:
1
}
},
{
$sort
:
{
"
questionInfo.order
"
:
1
}
},
...
@@ -42,7 +45,7 @@ export const getAnswers = async (surveyId: string) => {
...
@@ -42,7 +45,7 @@ export const getAnswers = async (surveyId: string) => {
$group
:
{
$group
:
{
_id
:
"
$surveyId
"
,
_id
:
"
$surveyId
"
,
questions
:
{
questions
:
{
$push
:
{
questionInfo
:
"
$questionInfo
"
,
answers
:
"
$answers
"
}
,
$push
:
"
$questionInfo
"
,
},
},
},
},
},
},
...
...
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