feat(backend): Vragen kunnen nu per leerobject, assignment en optioneel groepslid opgevraagd worden
This commit is contained in:
parent
64fd66a1de
commit
c863dc627f
7 changed files with 181 additions and 22 deletions
|
@ -1,11 +1,28 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { createQuestion, deleteQuestion, getAllQuestions, getAnswersByQuestion, getQuestion } from '../services/questions.js';
|
||||
import {
|
||||
createQuestion,
|
||||
deleteQuestion,
|
||||
getAllQuestions,
|
||||
getAnswersByQuestion,
|
||||
getQuestion,
|
||||
getQuestionsAboutLearningObjectInAssignment
|
||||
} from '../services/questions.js';
|
||||
import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import {AnswerDTO, AnswerId} from "@dwengo-1/common/interfaces/answer";
|
||||
|
||||
function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null {
|
||||
interface QuestionPathParams {
|
||||
hruid: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
interface QuestionQueryParams {
|
||||
lang: string;
|
||||
}
|
||||
|
||||
function getObjectId(req: Request<QuestionPathParams, any, any, QuestionQueryParams>, res: Response): LearningObjectIdentifier | null {
|
||||
const { hruid, version } = req.params;
|
||||
const lang = req.query.lang;
|
||||
|
||||
|
@ -21,7 +38,10 @@ function getObjectId(req: Request, res: Response): LearningObjectIdentifier | nu
|
|||
};
|
||||
}
|
||||
|
||||
function getQuestionId(req: Request, res: Response): QuestionId | null {
|
||||
interface GetQuestionIdPathParams extends QuestionPathParams {
|
||||
seq: string;
|
||||
}
|
||||
function getQuestionId(req: Request<GetQuestionIdPathParams, any, any, QuestionQueryParams>, res: Response): QuestionId | null {
|
||||
const seq = req.params.seq;
|
||||
const learningObjectIdentifier = getObjectId(req, res);
|
||||
|
||||
|
@ -35,15 +55,35 @@ function getQuestionId(req: Request, res: Response): QuestionId | null {
|
|||
};
|
||||
}
|
||||
|
||||
export async function getAllQuestionsHandler(req: Request, res: Response): Promise<void> {
|
||||
interface GetAllQuestionsQueryParams extends QuestionQueryParams {
|
||||
classId?: string,
|
||||
assignmentId?: number,
|
||||
forStudent?: string,
|
||||
full?: boolean
|
||||
}
|
||||
|
||||
export async function getAllQuestionsHandler(
|
||||
req: Request<QuestionPathParams, QuestionDTO[] | QuestionId[], unknown, GetAllQuestionsQueryParams>,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const objectId = getObjectId(req, res);
|
||||
const full = req.query.full === 'true';
|
||||
const full = req.query.full;
|
||||
|
||||
if (!objectId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const questions = await getAllQuestions(objectId, full);
|
||||
let questions: QuestionDTO[] | QuestionId[];
|
||||
if (req.query.classId && req.query.assignmentId) {
|
||||
questions = await getQuestionsAboutLearningObjectInAssignment(
|
||||
objectId,
|
||||
req.query.classId,
|
||||
req.query.assignmentId,
|
||||
full ?? false,
|
||||
req.query.forStudent
|
||||
);
|
||||
} else {
|
||||
questions = await getAllQuestions(objectId, full ?? false);
|
||||
}
|
||||
|
||||
if (!questions) {
|
||||
res.status(404).json({ error: `Questions not found.` });
|
||||
|
@ -52,7 +92,10 @@ export async function getAllQuestionsHandler(req: Request, res: Response): Promi
|
|||
}
|
||||
}
|
||||
|
||||
export async function getQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function getQuestionHandler(
|
||||
req: Request<GetQuestionIdPathParams, QuestionDTO[] | QuestionId[], unknown, QuestionQueryParams>,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
|
||||
if (!questionId) {
|
||||
|
@ -68,9 +111,15 @@ export async function getQuestionHandler(req: Request, res: Response): Promise<v
|
|||
}
|
||||
}
|
||||
|
||||
export async function getQuestionAnswersHandler(req: Request, res: Response): Promise<void> {
|
||||
interface GetQuestionAnswersQueryParams extends QuestionQueryParams {
|
||||
full: boolean
|
||||
}
|
||||
export async function getQuestionAnswersHandler(
|
||||
req: Request<GetQuestionIdPathParams, {answers: AnswerDTO[] | AnswerId[]}, unknown, GetQuestionAnswersQueryParams>,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
const full = req.query.full === 'true';
|
||||
const full = req.query.full;
|
||||
|
||||
if (!questionId) {
|
||||
return;
|
||||
|
@ -102,7 +151,10 @@ export async function createQuestionHandler(req: Request, res: Response): Promis
|
|||
}
|
||||
}
|
||||
|
||||
export async function deleteQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function deleteQuestionHandler(
|
||||
req: Request<GetQuestionIdPathParams, QuestionDTO, unknown, QuestionQueryParams>,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
|
||||
if (!questionId) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue