fix(backend): Merge-conflicten opgelost.
This commit is contained in:
		
							parent
							
								
									8c387d6811
								
							
						
					
					
						commit
						fb3c37ce5a
					
				
					 8 changed files with 79 additions and 49 deletions
				
			
		|  | @ -7,11 +7,12 @@ import { | ||||||
|     getQuestion, |     getQuestion, | ||||||
|     getQuestionsAboutLearningObjectInAssignment, updateQuestion, |     getQuestionsAboutLearningObjectInAssignment, updateQuestion, | ||||||
| } from '../services/questions.js'; | } from '../services/questions.js'; | ||||||
| import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js'; | import {FALLBACK_LANG, FALLBACK_SEQ_NUM, FALLBACK_VERSION_NUM} from '../config.js'; | ||||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||||
| import { QuestionData, QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | import { QuestionData, QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||||
| import { Language } from '@dwengo-1/common/util/language'; | import { Language } from '@dwengo-1/common/util/language'; | ||||||
| import {requireFields} from "./error-helper"; | import {requireFields} from "./error-helper"; | ||||||
|  | import {BadRequestException} from "../exceptions/bad-request-exception"; | ||||||
| 
 | 
 | ||||||
| export function getLearningObjectId(hruid: string, version: string, lang: string): LearningObjectIdentifier { | export function getLearningObjectId(hruid: string, version: string, lang: string): LearningObjectIdentifier { | ||||||
|     return { |     return { | ||||||
|  | @ -28,7 +29,7 @@ export function getQuestionId(learningObjectIdentifier: LearningObjectIdentifier | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function getQuestionId(req: Request, res: Response): QuestionId | null { | function getQuestionIdFromRequest(req: Request): QuestionId | null { | ||||||
|     const seq = req.params.seq; |     const seq = req.params.seq; | ||||||
|     const hruid = req.params.hruid; |     const hruid = req.params.hruid; | ||||||
|     const version = req.params.version; |     const version = req.params.version; | ||||||
|  | @ -39,10 +40,7 @@ function getQuestionId(req: Request, res: Response): QuestionId | null { | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return { |     return getQuestionId(learningObjectIdentifier, seq); | ||||||
|         learningObjectIdentifier, |  | ||||||
|         sequenceNumber: seq ? Number(seq) : FALLBACK_SEQ_NUM, |  | ||||||
|     }; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getAllQuestionsHandler(req: Request, res: Response): Promise<void> { | export async function getAllQuestionsHandler(req: Request, res: Response): Promise<void> { | ||||||
|  | @ -52,16 +50,22 @@ export async function getAllQuestionsHandler(req: Request, res: Response): Promi | ||||||
|     const full = req.query.full === 'true'; |     const full = req.query.full === 'true'; | ||||||
|     requireFields({ hruid }); |     requireFields({ hruid }); | ||||||
| 
 | 
 | ||||||
|  |     const assignmentId = parseInt(req.query.assignmentId as string); | ||||||
|  | 
 | ||||||
|  |     if (isNaN(assignmentId)) { | ||||||
|  |         throw new BadRequestException("The assignment ID must be a number."); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     const learningObjectId = getLearningObjectId(hruid, version, language); |     const learningObjectId = getLearningObjectId(hruid, version, language); | ||||||
| 
 | 
 | ||||||
|     let questions: QuestionDTO[] | QuestionId[]; |     let questions: QuestionDTO[] | QuestionId[]; | ||||||
|     if (req.query.classId && req.query.assignmentId) { |     if (req.query.classId && req.query.assignmentId) { | ||||||
|         questions = await getQuestionsAboutLearningObjectInAssignment( |         questions = await getQuestionsAboutLearningObjectInAssignment( | ||||||
|             learningObjectId, |             learningObjectId, | ||||||
|             req.query.classId, |             req.query.classId as string, | ||||||
|             req.query.assignmentId, |             parseInt(req.query.assignmentId as string), | ||||||
|             full ?? false, |             full ?? false, | ||||||
|             req.query.forStudent |             req.query.forStudent as string | undefined | ||||||
|         ); |         ); | ||||||
|     } else { |     } else { | ||||||
|         questions = await getAllQuestions(learningObjectId, full ?? false); |         questions = await getAllQuestions(learningObjectId, full ?? false); | ||||||
|  | @ -85,18 +89,15 @@ export async function getAllQuestionsHandler(req: Request, res: Response): Promi | ||||||
|     res.json({ question }); |     res.json({ question }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|     export async function getQuestionAnswersHandler( | export async function getQuestionAnswersHandler(req: Request, res: Response): Promise<void> { | ||||||
|         req: Request<GetQuestionIdPathParams, { answers: AnswerDTO[] | AnswerId[] }, unknown, GetQuestionAnswersQueryParams>, |     const questionId = getQuestionIdFromRequest(req); | ||||||
|         res: Response |  | ||||||
|     ): Promise<void> { |  | ||||||
|         const questionId = getQuestionId(req, res); |  | ||||||
|     const full = req.query.full; |     const full = req.query.full; | ||||||
| 
 | 
 | ||||||
|     if (!questionId) { |     if (!questionId) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|         const answers = await getAnswersByQuestion(questionId, full); |     const answers = await getAnswersByQuestion(questionId, full === "true"); | ||||||
| 
 | 
 | ||||||
|     if (!answers) { |     if (!answers) { | ||||||
|         res.status(404).json({ error: `Questions not found` }); |         res.status(404).json({ error: `Questions not found` }); | ||||||
|  |  | ||||||
|  | @ -1,9 +1,9 @@ | ||||||
| import { Question } from '../entities/questions/question.entity.js'; | import { Question } from '../entities/questions/question.entity.js'; | ||||||
| import { mapToStudentDTO } from './student.js'; | import { mapToStudentDTO } from './student.js'; | ||||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||||
| import { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content'; |  | ||||||
| import { mapToGroupDTOId } from './group'; | import { mapToGroupDTOId } from './group'; | ||||||
| import { LearningObjectIdentifierDTO } from '@dwengo-1/common/interfaces/learning-content'; | import { LearningObjectIdentifierDTO } from '@dwengo-1/common/interfaces/learning-content'; | ||||||
|  | import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier"; | ||||||
| 
 | 
 | ||||||
| function getLearningObjectIdentifier(question: Question): LearningObjectIdentifierDTO { | function getLearningObjectIdentifier(question: Question): LearningObjectIdentifierDTO { | ||||||
|     return { |     return { | ||||||
|  |  | ||||||
|  | @ -0,0 +1,23 @@ | ||||||
|  | import {authorize} from "./auth-checks"; | ||||||
|  | import {AuthenticationInfo} from "../authentication-info"; | ||||||
|  | import {AuthenticatedRequest} from "../authenticated-request"; | ||||||
|  | import {getGroup} from "../../../services/groups"; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Only allows requests whose learning path personalization query parameters ('forGroup' / 'assignmentNo' / 'classId') | ||||||
|  |  * are | ||||||
|  |  * - either not set | ||||||
|  |  * - or set to a group the user is in, | ||||||
|  |  * - or set to anything if the user is a teacher. | ||||||
|  |  */ | ||||||
|  | export const onlyAllowPersonalizationForOwnGroup = authorize( | ||||||
|  |     async (auth: AuthenticationInfo, req: AuthenticatedRequest) => { | ||||||
|  |         const {forGroup, assignmentNo, classId} = req.params; | ||||||
|  |         if (forGroup && assignmentNo && classId) { | ||||||
|  |             const group = getGroup(forGroup, parseInt(assignmentNo), classId, false); | ||||||
|  | 
 | ||||||
|  |         } else { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | ); | ||||||
|  | @ -1,13 +1,15 @@ | ||||||
| import express from 'express'; | import express from 'express'; | ||||||
| import { createGroupHandler, getAllGroupsHandler, getGroupHandler, getGroupSubmissionsHandler } from '../controllers/groups.js'; | import { createGroupHandler, getAllGroupsHandler, getGroupHandler, getGroupSubmissionsHandler } from '../controllers/groups.js'; | ||||||
| import {onlyAllowIfHasAccessToGroup} from "../middleware/auth/checks/group-auth-checker"; | import {onlyAllowIfHasAccessToGroup} from "../middleware/auth/checks/group-auth-checker"; | ||||||
|  | import {teachersOnly} from "../middleware/auth/checks/auth-checks"; | ||||||
|  | import {onlyAllowIfHasAccessToAssignment} from "../middleware/auth/checks/assignment-auth-checks"; | ||||||
| 
 | 
 | ||||||
| const router = express.Router({ mergeParams: true }); | const router = express.Router({ mergeParams: true }); | ||||||
| 
 | 
 | ||||||
| // Root endpoint used to search objects
 | // Root endpoint used to search objects
 | ||||||
| router.get('/', getAllGroupsHandler); | router.get('/', onlyAllowIfHasAccessToAssignment, getAllGroupsHandler); | ||||||
| 
 | 
 | ||||||
| router.post('/', createGroupHandler); | router.post('/', teachersOnly, onlyAllowIfHasAccessToAssignment, createGroupHandler); | ||||||
| 
 | 
 | ||||||
| // Information about a group (members, ... [TODO DOC])
 | // Information about a group (members, ... [TODO DOC])
 | ||||||
| router.get('/:groupid', onlyAllowIfHasAccessToGroup, getGroupHandler); | router.get('/:groupid', onlyAllowIfHasAccessToGroup, getGroupHandler); | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ import { getAllLearningObjects, getAttachment, getLearningObject, getLearningObj | ||||||
| 
 | 
 | ||||||
| import submissionRoutes from './submissions.js'; | import submissionRoutes from './submissions.js'; | ||||||
| import questionRoutes from './questions.js'; | import questionRoutes from './questions.js'; | ||||||
|  | import {authenticatedOnly} from "../middleware/auth/checks/auth-checks"; | ||||||
| 
 | 
 | ||||||
| const router = express.Router(); | const router = express.Router(); | ||||||
| 
 | 
 | ||||||
|  | @ -16,13 +17,13 @@ const router = express.Router(); | ||||||
| 
 | 
 | ||||||
| // Route 2: list of object data
 | // Route 2: list of object data
 | ||||||
| // Example 2: http://localhost:3000/learningObject?full=true&hruid=un_artificiele_intelligentie
 | // Example 2: http://localhost:3000/learningObject?full=true&hruid=un_artificiele_intelligentie
 | ||||||
| router.get('/', getAllLearningObjects); | router.get('/', authenticatedOnly, getAllLearningObjects); | ||||||
| 
 | 
 | ||||||
| // Parameter: hruid of learning object
 | // Parameter: hruid of learning object
 | ||||||
| // Query: language
 | // Query: language
 | ||||||
| // Route to fetch data of one learning object based on its hruid
 | // Route to fetch data of one learning object based on its hruid
 | ||||||
| // Example: http://localhost:3000/learningObject/un_ai7
 | // Example: http://localhost:3000/learningObject/un_ai7
 | ||||||
| router.get('/:hruid', getLearningObject); | router.get('/:hruid', authenticatedOnly, getLearningObject); | ||||||
| 
 | 
 | ||||||
| router.use('/:hruid/submissions', submissionRoutes); | router.use('/:hruid/submissions', submissionRoutes); | ||||||
| 
 | 
 | ||||||
|  | @ -32,12 +33,12 @@ router.use('/:hruid/:version/questions', questionRoutes); | ||||||
| // Query: language, version (optional)
 | // Query: language, version (optional)
 | ||||||
| // Route to fetch the HTML rendering of one learning object based on its hruid.
 | // Route to fetch the HTML rendering of one learning object based on its hruid.
 | ||||||
| // Example: http://localhost:3000/learningObject/un_ai7/html
 | // Example: http://localhost:3000/learningObject/un_ai7/html
 | ||||||
| router.get('/:hruid/html', getLearningObjectHTML); | router.get('/:hruid/html', authenticatedOnly, getLearningObjectHTML); | ||||||
| 
 | 
 | ||||||
| // Parameter: hruid of learning object, name of attachment.
 | // Parameter: hruid of learning object, name of attachment.
 | ||||||
| // Query: language, version (optional).
 | // Query: language, version (optional).
 | ||||||
| // Route to get the raw data of the attachment for one learning object based on its hruid.
 | // Route to get the raw data of the attachment for one learning object based on its hruid.
 | ||||||
| // Example: http://localhost:3000/learningObject/u_test/attachment/testimage.png
 | // Example: http://localhost:3000/learningObject/u_test/attachment/testimage.png
 | ||||||
| router.get('/:hruid/html/:attachmentName', getAttachment); | router.get('/:hruid/html/:attachmentName', authenticatedOnly, getAttachment); | ||||||
| 
 | 
 | ||||||
| export default router; | export default router; | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| import express from 'express'; | import express from 'express'; | ||||||
| import { getLearningPaths } from '../controllers/learning-paths.js'; | import { getLearningPaths } from '../controllers/learning-paths.js'; | ||||||
|  | import {authenticatedOnly} from "../middleware/auth/checks/auth-checks"; | ||||||
| 
 | 
 | ||||||
| const router = express.Router(); | const router = express.Router(); | ||||||
| 
 | 
 | ||||||
|  | @ -22,6 +23,6 @@ const router = express.Router(); | ||||||
| // Route to fetch learning paths based on a theme
 | // Route to fetch learning paths based on a theme
 | ||||||
| // Example: http://localhost:3000/learningPath?theme=kiks
 | // Example: http://localhost:3000/learningPath?theme=kiks
 | ||||||
| 
 | 
 | ||||||
| router.get('/', getLearningPaths); | router.get('/', authenticatedOnly, getLearningPaths); | ||||||
| 
 | 
 | ||||||
| export default router; | export default router; | ||||||
|  |  | ||||||
|  | @ -11,11 +11,13 @@ import { mapToAnswerDTO, mapToAnswerDTOId } from '../interfaces/answer.js'; | ||||||
| import { QuestionRepository } from '../data/questions/question-repository.js'; | import { QuestionRepository } from '../data/questions/question-repository.js'; | ||||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||||
| import { mapToStudent } from '../interfaces/student.js'; | import { mapToStudent } from '../interfaces/student.js'; | ||||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | import {QuestionData, QuestionDTO, QuestionId} from '@dwengo-1/common/interfaces/question'; | ||||||
| import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer'; | import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer'; | ||||||
| import {fetchStudent} from "./students"; | import {fetchStudent} from "./students"; | ||||||
| import {mapToAssignment} from "../interfaces/assignment"; | import {mapToAssignment} from "../interfaces/assignment"; | ||||||
| import { NotFoundException } from '../exceptions/not-found-exception.js'; | import { NotFoundException } from '../exceptions/not-found-exception.js'; | ||||||
|  | import {AssignmentDTO} from "@dwengo-1/common/interfaces/assignment"; | ||||||
|  | import {FALLBACK_VERSION_NUM} from "../config"; | ||||||
| 
 | 
 | ||||||
| export async function getQuestionsAboutLearningObjectInAssignment( | export async function getQuestionsAboutLearningObjectInAssignment( | ||||||
|     loId: LearningObjectIdentifier, |     loId: LearningObjectIdentifier, | ||||||
|  | @ -90,10 +92,9 @@ export async function createQuestion(loId: LearningObjectIdentifier, questionDat | ||||||
|     const author = await fetchStudent(questionData.author!); |     const author = await fetchStudent(questionData.author!); | ||||||
|     const content = questionData.content; |     const content = questionData.content; | ||||||
| 
 | 
 | ||||||
|     const clazz = await getClassRepository().findById((questionDTO.inGroup.assignment as AssignmentDTO).class); |     const clazz = await getClassRepository().findById((questionData.inGroup.assignment as AssignmentDTO).class); | ||||||
|     let questionDTO; |     const assignment = mapToAssignment(questionData.inGroup.assignment as AssignmentDTO, clazz!); | ||||||
|     const assignment = mapToAssignment(questionDTO.inGroup.assignment as AssignmentDTO, clazz!); |     const inGroup = (await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionData.inGroup.groupNumber))!; | ||||||
|     const inGroup = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionDTO.inGroup.groupNumber); |  | ||||||
| 
 | 
 | ||||||
|     const question = await questionRepository.createQuestion({ |     const question = await questionRepository.createQuestion({ | ||||||
|         loId, |         loId, | ||||||
|  |  | ||||||
|  | @ -13,6 +13,7 @@ export interface QuestionDTO { | ||||||
| 
 | 
 | ||||||
| export interface QuestionData { | export interface QuestionData { | ||||||
|     author?: string; |     author?: string; | ||||||
|  |     inGroup: GroupDTO; | ||||||
|     content: string; |     content: string; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger