Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 485 drag and drop #312

Merged
merged 14 commits into from
Dec 24, 2024
Merged
3 changes: 2 additions & 1 deletion apps/api/src/chapter/repositories/adminChapter.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ export class AdminChapterRepository {
'type', ${questions.type},
'description', ${questions.description},
'photoS3Key', ${questions.photoS3Key},
'displayOrder', ${questions.displayOrder},
'photoQuestionType', ${questions.photoQuestionType},
'options', (
SELECT ARRAY(
SELECT json_build_object(
'id', ${questionAnswerOptions.id},
'optionText', ${questionAnswerOptions.optionText},
'isCorrect', ${questionAnswerOptions.isCorrect},
'position', ${questionAnswerOptions.position}
'displayOrder', ${questionAnswerOptions.displayOrder}
)
FROM ${questionAnswerOptions} questionAnswerOptions
WHERE questionAnswerOptions.question_id = questions.id
Expand Down
5 changes: 4 additions & 1 deletion apps/api/src/lesson/lesson.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import type { Static } from "@sinclair/typebox";
export const optionSchema = Type.Object({
id: Type.Optional(UUIDSchema),
optionText: Type.String(),
displayOrder: Type.Union([Type.Number(), Type.Null()]),
isStudentAnswer: Type.Optional(Type.Boolean()),
isCorrect: Type.Boolean(),
position: Type.Number(),
questionId: Type.Optional(UUIDSchema),
});

export const questionSchema = Type.Object({
id: Type.Optional(UUIDSchema),
type: Type.Enum(QuestionType),
description: Type.Optional(Type.String()),
title: Type.String(),
displayOrder: Type.Optional(Type.Number()),
photoQuestionType: Type.Optional(Type.Enum(PhotoQuestionType)),
photoS3Key: Type.Optional(Type.String()),
options: Type.Optional(Type.Array(optionSchema)),
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/lesson/lesson.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export enum QuestionType {
MultipleChoice = "multiple_choice",
TrueOrFalse = "true_or_false",
PhotoQuestion = "photo_question",
FillInTheBlanks = "fill_in_the_blanks",
FillInTheBlanksText = "fill_in_the_blanks_text",
FillInTheBlanksDnd = "fill_in_the_blanks_dnd",
BriefResponse = "brief_response",
DetailedResponse = "detailed_response",
}
Expand Down
9 changes: 5 additions & 4 deletions apps/api/src/lesson/repositories/adminLesson.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export class AdminLessonRepository {
id: questionAnswerOptions.id,
optionText: questionAnswerOptions.optionText,
isCorrect: questionAnswerOptions.isCorrect,
position: questionAnswerOptions.position,
displayOrder: questionAnswerOptions.displayOrder,
questionId: questionAnswerOptions.questionId,
})
.from(questionAnswerOptions)
.where(eq(questionAnswerOptions.questionId, questionId));
Expand Down Expand Up @@ -390,7 +391,7 @@ export class AdminLessonRepository {
id?: string;
optionText: string;
isCorrect: boolean;
position: number;
displayOrder: number;
},
trx?: PostgresJsDatabase<typeof schema>,
) {
Expand All @@ -402,14 +403,14 @@ export class AdminLessonRepository {
questionId,
optionText: option.optionText,
isCorrect: option.isCorrect,
position: option.position,
displayOrder: option.displayOrder,
})
.onConflictDoUpdate({
target: questionAnswerOptions.id,
set: {
optionText: option.optionText,
isCorrect: option.isCorrect,
position: option.position,
displayOrder: option.displayOrder,
},
});
}
Expand Down
6 changes: 4 additions & 2 deletions apps/api/src/lesson/services/adminLesson.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class AdminLessonService {
type: question.type,
description: question.description || null,
title: question.title,
displayOrder: question.displayOrder,
photoS3Key: question.photoS3Key,
photoQuestionType: question.photoQuestionType || null,
}));
Expand All @@ -162,7 +163,7 @@ export class AdminLessonService {
questionId: question.id,
optionText: option.optionText,
isCorrect: option.isCorrect,
position: option.position,
displayOrder: option.displayOrder,
})) || [],
);

Expand Down Expand Up @@ -212,6 +213,7 @@ export class AdminLessonService {
type: question.type,
description: question.description || null,
title: question.title,
displayOrder: question.displayOrder,
photoS3Key: question.photoS3Key,
photoQuestionType: question.photoQuestionType || null,
};
Expand Down Expand Up @@ -258,7 +260,7 @@ export class AdminLessonService {
const optionData = {
optionText: option.optionText,
isCorrect: option.isCorrect,
position: option.position,
displayOrder: option.displayOrder,
};

// TODO: extract to repository
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/lesson/services/lesson.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ export class LessonService {
${questionAnswerOptions.id} AS id,
${questionAnswerOptions.optionText} AS optionText,
${questionAnswerOptions.isCorrect} AS "isCorrect",
${questionAnswerOptions.position} AS "position",
${questionAnswerOptions.displayOrder} AS "displayOrder",
FROM ${questionAnswerOptions}
WHERE ${questionAnswerOptions.questionId} = ${questions.id}
GROUP BY
${questionAnswerOptions.id},
${questionAnswerOptions.optionText},
${questionAnswerOptions.isCorrect},
${questionAnswerOptions.position},
ORDER BY ${questionAnswerOptions.position}
${questionAnswerOptions.displayOrder},
ORDER BY ${questionAnswerOptions.displayOrder}
) AS question_options
),
undefined
Expand Down
12 changes: 6 additions & 6 deletions apps/api/src/seed/e2e-data-seeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const e2eCourses: NiceCourseData[] = [
{
optionText: "E2E Testing Answer",
isCorrect: true,
position: 0,
displayOrder: 0,
},
],
},
Expand All @@ -57,12 +57,12 @@ export const e2eCourses: NiceCourseData[] = [
{
optionText: "single true",
isCorrect: true,
position: 0,
displayOrder: 0,
},
{
optionText: "single false",
isCorrect: false,
position: 1,
displayOrder: 1,
},
],
},
Expand All @@ -74,17 +74,17 @@ export const e2eCourses: NiceCourseData[] = [
{
optionText: "multiple true a",
isCorrect: true,
position: 0,
displayOrder: 0,
},
{
optionText: "multiple true b",
isCorrect: false,
position: 1,
displayOrder: 1,
},
{
optionText: "multiple false c",
isCorrect: false,
position: 2,
displayOrder: 2,
},
],
},
Expand Down
Loading
Loading