feat: seperate single and multi choice questions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IsNumber, IsOptional } from 'class-validator';
|
||||
import { IsArray, IsInt, IsNumber, IsOptional } from 'class-validator';
|
||||
import { SubmissionAnswer } from '../decorators/submission-answer.decorator';
|
||||
|
||||
export class AnswerSubmissionDTO {
|
||||
@@ -6,6 +6,11 @@ export class AnswerSubmissionDTO {
|
||||
@IsOptional()
|
||||
choiceId?: number;
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
@IsInt({ each: true })
|
||||
choiceIds?: number[];
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
numericValue?: number;
|
||||
|
||||
@@ -28,7 +28,7 @@ export const checkAnswerCorrectness = (
|
||||
}
|
||||
}
|
||||
|
||||
if (question.type === QuestionType.MULTI_CHOICE) {
|
||||
if (question.type === QuestionType.SINGLE_CHOICE) {
|
||||
if (choiceId === undefined || choiceId === null) {
|
||||
throw new BadRequestException('submissions.errors.emptyChoiceId');
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export const getNextTransition = (
|
||||
);
|
||||
|
||||
if (
|
||||
question.type === QuestionType.MULTI_CHOICE &&
|
||||
question.type === QuestionType.SINGLE_CHOICE &&
|
||||
answerSubmissionDto.choiceId !== undefined
|
||||
) {
|
||||
const transition = transitions.find(
|
||||
|
||||
@@ -131,7 +131,7 @@ export class AnswerAuthenticatedProvider {
|
||||
});
|
||||
|
||||
if (
|
||||
currentQuestion.type === QuestionType.MULTI_CHOICE &&
|
||||
currentQuestion.type === QuestionType.SINGLE_CHOICE &&
|
||||
answerSubmissionDto.choiceId !== undefined
|
||||
) {
|
||||
const choice = currentQuestion.choices.find(
|
||||
|
||||
@@ -126,7 +126,7 @@ export class AnswerGuestProvider {
|
||||
};
|
||||
|
||||
if (
|
||||
currentQuestion.type === QuestionType.MULTI_CHOICE &&
|
||||
currentQuestion.type === QuestionType.SINGLE_CHOICE &&
|
||||
answerSubmissionDto.choiceId !== undefined
|
||||
) {
|
||||
const choice = currentQuestion.choices.find(
|
||||
|
||||
@@ -162,7 +162,7 @@ export class CalculateResultProvider {
|
||||
if (!question) continue;
|
||||
|
||||
if (
|
||||
question.type === QuestionType.MULTI_CHOICE &&
|
||||
question.type === QuestionType.SINGLE_CHOICE &&
|
||||
answer.choiceId !== undefined
|
||||
) {
|
||||
const choice =
|
||||
@@ -192,7 +192,7 @@ export class CalculateResultProvider {
|
||||
questions.forEach((question) => {
|
||||
const answerScores: number[] = [];
|
||||
|
||||
if (question.type === QuestionType.MULTI_CHOICE) {
|
||||
if (question.type === QuestionType.SINGLE_CHOICE) {
|
||||
question.choices.forEach((choice) => {
|
||||
answerScores.push(choice.score);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user