diff --git a/backend/src/controllers/answers.ts b/backend/src/controllers/answers.ts index f605b1a3..eaf51749 100644 --- a/backend/src/controllers/answers.ts +++ b/backend/src/controllers/answers.ts @@ -1,9 +1,9 @@ -import {Request, Response} from "express"; -import {requireFields} from "./error-helper"; -import {getLearningObjectId, getQuestionId} from "./questions"; -import {createAnswer, deleteAnswer, getAnswer, getAnswersByQuestion, updateAnswer} from "../services/answers"; -import {FALLBACK_SEQ_NUM} from "../config"; -import {AnswerData} from "@dwengo-1/common/interfaces/answer"; +import { Request, Response } from 'express'; +import { requireFields } from './error-helper'; +import { getLearningObjectId, getQuestionId } from './questions'; +import { createAnswer, deleteAnswer, getAnswer, getAnswersByQuestion, updateAnswer } from '../services/answers'; +import { FALLBACK_SEQ_NUM } from '../config'; +import { AnswerData } from '@dwengo-1/common/interfaces/answer'; export async function getAllAnswersHandler(req: Request, res: Response): Promise { const hruid = req.params.hruid; @@ -11,7 +11,7 @@ export async function getAllAnswersHandler(req: Request, res: Response): Promise const language = req.query.lang as string; const seq = req.params.seq; const full = req.query.full === 'true'; - requireFields({ hruid }) + requireFields({ hruid }); const learningObjectId = getLearningObjectId(hruid, version, language); const questionId = getQuestionId(learningObjectId, seq); @@ -21,13 +21,13 @@ export async function getAllAnswersHandler(req: Request, res: Response): Promise res.json({ answers }); } -export async function getAnswerHandler(req: Request, res: Response): Promise{ +export async function getAnswerHandler(req: Request, res: Response): Promise { const hruid = req.params.hruid; const version = req.params.version; const language = req.query.lang as string; const seq = req.params.seq; const seqAnswer = req.params.seqAnswer; - requireFields({ hruid }) + requireFields({ hruid }); const learningObjectId = getLearningObjectId(hruid, version, language); const questionId = getQuestionId(learningObjectId, seq); @@ -43,7 +43,7 @@ export async function createAnswerHandler(req: Request, res: Response): Promise< const version = req.params.version; const language = req.query.lang as string; const seq = req.params.seq; - requireFields({ hruid }) + requireFields({ hruid }); const learningObjectId = getLearningObjectId(hruid, version, language); const questionId = getQuestionId(learningObjectId, seq); @@ -65,7 +65,7 @@ export async function deleteAnswerHandler(req: Request, res: Response): Promise< const language = req.query.lang as string; const seq = req.params.seq; const seqAnswer = req.params.seqAnswer; - requireFields({ hruid }) + requireFields({ hruid }); const learningObjectId = getLearningObjectId(hruid, version, language); const questionId = getQuestionId(learningObjectId, seq); @@ -76,15 +76,13 @@ export async function deleteAnswerHandler(req: Request, res: Response): Promise< res.json({ answer }); } - - export async function updateAnswerHandler(req: Request, res: Response): Promise { const hruid = req.params.hruid; const version = req.params.version; const language = req.query.lang as string; const seq = req.params.seq; const seqAnswer = req.params.seqAnswer; - requireFields({ hruid }) + requireFields({ hruid }); const learningObjectId = getLearningObjectId(hruid, version, language); const questionId = getQuestionId(learningObjectId, seq); diff --git a/backend/src/controllers/questions.ts b/backend/src/controllers/questions.ts index e239d9ca..1158e041 100644 --- a/backend/src/controllers/questions.ts +++ b/backend/src/controllers/questions.ts @@ -1,15 +1,10 @@ import { Request, Response } from 'express'; -import { - createQuestion, - deleteQuestion, - getAllQuestions, - getQuestion, updateQuestion -} from '../services/questions.js'; -import {FALLBACK_LANG, FALLBACK_SEQ_NUM, FALLBACK_VERSION_NUM} from '../config.js'; +import { createQuestion, deleteQuestion, getAllQuestions, getQuestion, updateQuestion } from '../services/questions.js'; +import { FALLBACK_LANG, FALLBACK_SEQ_NUM, FALLBACK_VERSION_NUM } from '../config.js'; import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; -import {QuestionData, QuestionId} from '@dwengo-1/common/interfaces/question'; +import { QuestionData, QuestionId } from '@dwengo-1/common/interfaces/question'; import { Language } from '@dwengo-1/common/util/language'; -import {requireFields} from "./error-helper"; +import { requireFields } from './error-helper'; export function getLearningObjectId(hruid: string, version: string, lang: string): LearningObjectIdentifier { return { @@ -31,7 +26,7 @@ export async function getAllQuestionsHandler(req: Request, res: Response): Promi const version = req.params.version; const language = req.query.lang as string; const full = req.query.full === 'true'; - requireFields({ hruid }) + requireFields({ hruid }); const learningObjectId = getLearningObjectId(hruid, version, language); @@ -45,7 +40,7 @@ export async function getQuestionHandler(req: Request, res: Response): Promise { const hruid = req.params.hruid; const version = req.params.version; const language = req.query.lang as string; - requireFields({ hruid }) + requireFields({ hruid }); const loId = getLearningObjectId(hruid, version, language); @@ -73,7 +67,6 @@ export async function createQuestionHandler(req: Request, res: Response): Promis const question = await createQuestion(loId, questionData); res.json({ question }); - } export async function deleteQuestionHandler(req: Request, res: Response): Promise { @@ -81,7 +74,7 @@ export async function deleteQuestionHandler(req: Request, res: Response): Promis const version = req.params.version; const language = req.query.lang as string; const seq = req.params.seq; - requireFields({ hruid }) + requireFields({ hruid }); const learningObjectId = getLearningObjectId(hruid, version, language); const questionId = getQuestionId(learningObjectId, seq); @@ -96,7 +89,7 @@ export async function updateQuestionHandler(req: Request, res: Response): Promis const version = req.params.version; const language = req.query.lang as string; const seq = req.params.seq; - requireFields({ hruid }) + requireFields({ hruid }); const learningObjectId = getLearningObjectId(hruid, version, language); const questionId = getQuestionId(learningObjectId, seq); diff --git a/backend/src/interfaces/answer.ts b/backend/src/interfaces/answer.ts index 87464a0b..b78c579f 100644 --- a/backend/src/interfaces/answer.ts +++ b/backend/src/interfaces/answer.ts @@ -1,7 +1,7 @@ -import {mapToQuestionDTO, mapToQuestionDTOId} from './question.js'; +import { mapToQuestionDTO, mapToQuestionDTOId } from './question.js'; import { Answer } from '../entities/questions/answer.entity.js'; import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer'; -import {mapToTeacherDTO} from "./teacher"; +import { mapToTeacherDTO } from './teacher'; /** * Convert a Question entity to a DTO format. diff --git a/backend/src/interfaces/question.ts b/backend/src/interfaces/question.ts index 46f61825..40642ae7 100644 --- a/backend/src/interfaces/question.ts +++ b/backend/src/interfaces/question.ts @@ -1,10 +1,9 @@ import { Question } from '../entities/questions/question.entity.js'; -import { mapToStudentDTO} from './student.js'; -import { QuestionDTO, QuestionId} from '@dwengo-1/common/interfaces/question'; +import { mapToStudentDTO } from './student.js'; +import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; import { LearningObjectIdentifierDTO } from '@dwengo-1/common/interfaces/learning-content'; import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; - function getLearningObjectIdentifier(question: Question): LearningObjectIdentifierDTO { return { hruid: question.learningObjectHruid, @@ -17,8 +16,8 @@ export function mapToLearningObjectID(loID: LearningObjectIdentifierDTO): Learni return { hruid: loID.hruid, language: loID.language, - version: loID.version ?? 1 - } + version: loID.version ?? 1, + }; } /** diff --git a/backend/src/routes/questions.ts b/backend/src/routes/questions.ts index ba39435c..e3651ba3 100644 --- a/backend/src/routes/questions.ts +++ b/backend/src/routes/questions.ts @@ -1,10 +1,5 @@ import express from 'express'; -import { - createQuestionHandler, - deleteQuestionHandler, - getAllQuestionsHandler, - getQuestionHandler, -} from '../controllers/questions.js'; +import { createQuestionHandler, deleteQuestionHandler, getAllQuestionsHandler, getQuestionHandler } from '../controllers/questions.js'; import answerRoutes from './answers.js'; const router = express.Router({ mergeParams: true }); diff --git a/backend/src/services/questions.ts b/backend/src/services/questions.ts index 71460691..64bf4471 100644 --- a/backend/src/services/questions.ts +++ b/backend/src/services/questions.ts @@ -1,12 +1,12 @@ import { getQuestionRepository } from '../data/repositories.js'; -import {mapToLearningObjectID, mapToQuestionDTO, mapToQuestionDTOId} from '../interfaces/question.js'; +import { mapToLearningObjectID, mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js'; import { Question } from '../entities/questions/question.entity.js'; import { QuestionRepository } from '../data/questions/question-repository.js'; import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; -import {QuestionData, QuestionDTO, QuestionId} from '@dwengo-1/common/interfaces/question'; -import {NotFoundException} from "../exceptions/not-found-exception"; -import {FALLBACK_VERSION_NUM} from "../config"; -import {fetchStudent} from "./students"; +import { QuestionData, QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; +import { NotFoundException } from '../exceptions/not-found-exception'; +import { FALLBACK_VERSION_NUM } from '../config'; +import { fetchStudent } from './students'; export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise { const questionRepository: QuestionRepository = getQuestionRepository(); @@ -26,7 +26,7 @@ export async function fetchQuestion(questionId: QuestionId): Promise { questionId.sequenceNumber ); - if (!question){ + if (!question) { throw new NotFoundException('Question with loID and sequence number not found'); } @@ -44,7 +44,9 @@ export async function createQuestion(loId: LearningObjectIdentifier, questionDat const content = questionData.content; const question = await questionRepository.createQuestion({ - loId, author, content + loId, + author, + content, }); return mapToQuestionDTO(question); @@ -71,5 +73,3 @@ export async function updateQuestion(questionId: QuestionId, questionData: Quest const newQuestion = await questionRepository.updateContent(question, questionData.content); return mapToQuestionDTO(newQuestion); } - - diff --git a/common/src/interfaces/answer.ts b/common/src/interfaces/answer.ts index efba9437..8510ac7b 100644 --- a/common/src/interfaces/answer.ts +++ b/common/src/interfaces/answer.ts @@ -1,5 +1,5 @@ import { QuestionDTO, QuestionId } from './question'; -import {TeacherDTO} from "./teacher"; +import { TeacherDTO } from './teacher'; export interface AnswerDTO { author: TeacherDTO;