Merge remote-tracking branch 'origin/feat/question-routes' into feat/question-routes
# Conflicts: # backend/src/data/questions/answer-repository.ts # backend/src/data/questions/question-repository.ts # backend/src/routes/answers.ts # backend/src/services/answers.ts
This commit is contained in:
		
						commit
						7f7a4fe936
					
				
					 7 changed files with 38 additions and 53 deletions
				
			
		|  | @ -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<void> { | ||||
|     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<void>{ | ||||
| export async function getAnswerHandler(req: Request, res: Response): Promise<void> { | ||||
|     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<void> { | ||||
|     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); | ||||
|  |  | |||
|  | @ -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<v | |||
|     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); | ||||
|  | @ -53,14 +48,13 @@ export async function getQuestionHandler(req: Request, res: Response): Promise<v | |||
|     const question = await getQuestion(questionId); | ||||
| 
 | ||||
|     res.json({ question }); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| export async function createQuestionHandler(req: Request, res: Response): Promise<void> { | ||||
|     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<void> { | ||||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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. | ||||
|  |  | |||
|  | @ -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, | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  |  | |||
|  | @ -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 }); | ||||
|  |  | |||
|  | @ -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<QuestionDTO[] | QuestionId[]> { | ||||
|     const questionRepository: QuestionRepository = getQuestionRepository(); | ||||
|  | @ -26,7 +26,7 @@ export async function fetchQuestion(questionId: QuestionId): Promise<Question> { | |||
|         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); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl