fix(backend): group toch niet deel van primaire sleutel van vragen en submissions gemaakt, maar verplicht veld
This commit is contained in:
		
							parent
							
								
									b1df95da63
								
							
						
					
					
						commit
						7b79348985
					
				
					 10 changed files with 21 additions and 20 deletions
				
			
		|  | @ -4,7 +4,6 @@ import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js'; | ||||||
| import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js'; | ||||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | import { 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 {getGroup} from "../services/groups"; |  | ||||||
| 
 | 
 | ||||||
| function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null { | function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null { | ||||||
|     const { hruid, version } = req.params; |     const { hruid, version } = req.params; | ||||||
|  | @ -22,18 +21,16 @@ function getObjectId(req: Request, res: Response): LearningObjectIdentifier | nu | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function getQuestionId(req: Request, res: Response): Promise<QuestionId | null> { | function getQuestionId(req: Request, res: Response): QuestionId | null { | ||||||
|     const { seq, classId, assignmentId, groupId } = req.params |     const seq = req.params.seq; | ||||||
|     const learningObjectIdentifier = getObjectId(req, res); |     const learningObjectIdentifier = getObjectId(req, res); | ||||||
|     const groupIdentifier = await getGroup(classId, parseInt(assignmentId), parseInt(groupId), false); |  | ||||||
| 
 | 
 | ||||||
|     if (!learningObjectIdentifier || !groupIdentifier) { |     if (!learningObjectIdentifier) { | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return { |     return { | ||||||
|         learningObjectIdentifier, |         learningObjectIdentifier, | ||||||
|         inGroup: groupIdentifier, |  | ||||||
|         sequenceNumber: seq ? Number(seq) : FALLBACK_SEQ_NUM, |         sequenceNumber: seq ? Number(seq) : FALLBACK_SEQ_NUM, | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  | @ -56,7 +53,7 @@ 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, res: Response): Promise<void> { | ||||||
|     const questionId = await getQuestionId(req, res); |     const questionId = getQuestionId(req, res); | ||||||
| 
 | 
 | ||||||
|     if (!questionId) { |     if (!questionId) { | ||||||
|         return; |         return; | ||||||
|  | @ -72,7 +69,7 @@ export async function getQuestionHandler(req: Request, res: Response): Promise<v | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function getQuestionAnswersHandler(req: Request, res: Response): Promise<void> { | export async function getQuestionAnswersHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const questionId = await getQuestionId(req, res); |     const questionId = getQuestionId(req, res); | ||||||
|     const full = req.query.full === 'true'; |     const full = req.query.full === 'true'; | ||||||
| 
 | 
 | ||||||
|     if (!questionId) { |     if (!questionId) { | ||||||
|  | @ -106,7 +103,7 @@ 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, res: Response): Promise<void> { | ||||||
|     const questionId = await getQuestionId(req, res); |     const questionId = getQuestionId(req, res); | ||||||
| 
 | 
 | ||||||
|     if (!questionId) { |     if (!questionId) { | ||||||
|         return; |         return; | ||||||
|  |  | ||||||
|  | @ -22,8 +22,7 @@ export class Submission { | ||||||
|     submissionNumber?: number; |     submissionNumber?: number; | ||||||
| 
 | 
 | ||||||
|     @ManyToOne({ |     @ManyToOne({ | ||||||
|         entity: () => Group, |         entity: () => Group | ||||||
|         primary: true |  | ||||||
|     }) |     }) | ||||||
|     onBehalfOf!: Group; |     onBehalfOf!: Group; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ export class Question { | ||||||
|     @PrimaryKey({ type: 'integer', autoincrement: true }) |     @PrimaryKey({ type: 'integer', autoincrement: true }) | ||||||
|     sequenceNumber?: number; |     sequenceNumber?: number; | ||||||
| 
 | 
 | ||||||
|     @ManyToOne({ entity: () => Group, primary: true }) |     @ManyToOne({ entity: () => Group }) | ||||||
|     inGroup!: Group; |     inGroup!: Group; | ||||||
| 
 | 
 | ||||||
|     @ManyToOne({ |     @ManyToOne({ | ||||||
|  |  | ||||||
|  | @ -33,7 +33,6 @@ export function mapToQuestionDTOId(question: Question): QuestionId { | ||||||
| 
 | 
 | ||||||
|     return { |     return { | ||||||
|         learningObjectIdentifier, |         learningObjectIdentifier, | ||||||
|         inGroup: mapToGroupDTO(question.inGroup), |  | ||||||
|         sequenceNumber: question.sequenceNumber!, |         sequenceNumber: question.sequenceNumber!, | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -38,7 +38,6 @@ export function mapToSubmission(submissionDTO: SubmissionDTO): Submission { | ||||||
|     submission.submitter = mapToStudent(submissionDTO.submitter); |     submission.submitter = mapToStudent(submissionDTO.submitter); | ||||||
|     // Submission.submissionTime = submissionDTO.time;
 |     // Submission.submissionTime = submissionDTO.time;
 | ||||||
|     // Submission.onBehalfOf =  submissionDTO.group!;
 |     // Submission.onBehalfOf =  submissionDTO.group!;
 | ||||||
|     // TODO fix group
 |  | ||||||
|     submission.content = submissionDTO.content; |     submission.content = submissionDTO.content; | ||||||
| 
 | 
 | ||||||
|     return submission; |     return submission; | ||||||
|  |  | ||||||
|  | @ -15,11 +15,11 @@ router.get('/', getAllQuestionsHandler); | ||||||
| 
 | 
 | ||||||
| router.post('/', createQuestionHandler); | router.post('/', createQuestionHandler); | ||||||
| 
 | 
 | ||||||
| router.delete('/:classId/assignment/:assignmentId/group/:groupId/:seq', deleteQuestionHandler); | router.delete('/:seq', deleteQuestionHandler); | ||||||
| 
 | 
 | ||||||
| // Information about a question with id
 | // Information about a question with id
 | ||||||
| router.get('/:classId/assignment/:assignmentId/group/:groupId/:seq', getQuestionHandler); | router.get('/:seq', getQuestionHandler); | ||||||
| 
 | 
 | ||||||
| router.get('/:classId/assignment/:assignmentId/group/:groupId/answers/:seq', getQuestionAnswersHandler); | router.get('/answers/:seq', getQuestionAnswersHandler); | ||||||
| 
 | 
 | ||||||
| export default router; | export default router; | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ export async function setupTestApp(): Promise<void> { | ||||||
| 
 | 
 | ||||||
|     learningObjects[1].attachments = attachments; |     learningObjects[1].attachments = attachments; | ||||||
| 
 | 
 | ||||||
|     const questions = makeTestQuestions(em, students); |     const questions = makeTestQuestions(em, students, groups); | ||||||
|     const answers = makeTestAnswers(em, teachers, questions); |     const answers = makeTestAnswers(em, teachers, questions); | ||||||
|     const submissions = makeTestSubmissions(em, students, groups); |     const submissions = makeTestSubmissions(em, students, groups); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -34,6 +34,7 @@ export function makeTestSubmissions(em: EntityManager, students: Student[], grou | ||||||
|         submissionNumber: 1, |         submissionNumber: 1, | ||||||
|         submitter: students[0], |         submitter: students[0], | ||||||
|         submissionTime: new Date(2025, 2, 20), |         submissionTime: new Date(2025, 2, 20), | ||||||
|  |         onBehalfOf: groups[0], | ||||||
|         content: '', |         content: '', | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -44,6 +45,7 @@ export function makeTestSubmissions(em: EntityManager, students: Student[], grou | ||||||
|         submissionNumber: 2, |         submissionNumber: 2, | ||||||
|         submitter: students[0], |         submitter: students[0], | ||||||
|         submissionTime: new Date(2025, 2, 25), |         submissionTime: new Date(2025, 2, 25), | ||||||
|  |         onBehalfOf: groups[0], | ||||||
|         content: '', |         content: '', | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -54,6 +56,7 @@ export function makeTestSubmissions(em: EntityManager, students: Student[], grou | ||||||
|         submissionNumber: 1, |         submissionNumber: 1, | ||||||
|         submitter: students[1], |         submitter: students[1], | ||||||
|         submissionTime: new Date(2025, 2, 20), |         submissionTime: new Date(2025, 2, 20), | ||||||
|  |         onBehalfOf: groups[1], | ||||||
|         content: '', |         content: '', | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,12 +2,14 @@ import { EntityManager } from '@mikro-orm/core'; | ||||||
| import { Question } from '../../../src/entities/questions/question.entity'; | import { Question } from '../../../src/entities/questions/question.entity'; | ||||||
| import { Language } from '@dwengo-1/common/util/language'; | import { Language } from '@dwengo-1/common/util/language'; | ||||||
| import { Student } from '../../../src/entities/users/student.entity'; | import { Student } from '../../../src/entities/users/student.entity'; | ||||||
|  | import {Group} from "../../../src/entities/assignments/group.entity"; | ||||||
| 
 | 
 | ||||||
| export function makeTestQuestions(em: EntityManager, students: Student[]): Question[] { | export function makeTestQuestions(em: EntityManager, students: Student[], groups: Group[]): Question[] { | ||||||
|     const question01 = em.create(Question, { |     const question01 = em.create(Question, { | ||||||
|         learningObjectLanguage: Language.English, |         learningObjectLanguage: Language.English, | ||||||
|         learningObjectVersion: 1, |         learningObjectVersion: 1, | ||||||
|         learningObjectHruid: 'id05', |         learningObjectHruid: 'id05', | ||||||
|  |         inGroup: groups[0], | ||||||
|         sequenceNumber: 1, |         sequenceNumber: 1, | ||||||
|         author: students[0], |         author: students[0], | ||||||
|         timestamp: new Date(), |         timestamp: new Date(), | ||||||
|  | @ -18,6 +20,7 @@ export function makeTestQuestions(em: EntityManager, students: Student[]): Quest | ||||||
|         learningObjectLanguage: Language.English, |         learningObjectLanguage: Language.English, | ||||||
|         learningObjectVersion: 1, |         learningObjectVersion: 1, | ||||||
|         learningObjectHruid: 'id05', |         learningObjectHruid: 'id05', | ||||||
|  |         inGroup: groups[0], | ||||||
|         sequenceNumber: 2, |         sequenceNumber: 2, | ||||||
|         author: students[2], |         author: students[2], | ||||||
|         timestamp: new Date(), |         timestamp: new Date(), | ||||||
|  | @ -30,6 +33,7 @@ export function makeTestQuestions(em: EntityManager, students: Student[]): Quest | ||||||
|         learningObjectHruid: 'id04', |         learningObjectHruid: 'id04', | ||||||
|         sequenceNumber: 1, |         sequenceNumber: 1, | ||||||
|         author: students[0], |         author: students[0], | ||||||
|  |         inGroup: groups[0], | ||||||
|         timestamp: new Date(), |         timestamp: new Date(), | ||||||
|         content: 'question', |         content: 'question', | ||||||
|     }); |     }); | ||||||
|  | @ -40,6 +44,7 @@ export function makeTestQuestions(em: EntityManager, students: Student[]): Quest | ||||||
|         learningObjectHruid: 'id01', |         learningObjectHruid: 'id01', | ||||||
|         sequenceNumber: 1, |         sequenceNumber: 1, | ||||||
|         author: students[1], |         author: students[1], | ||||||
|  |         inGroup: groups[1], | ||||||
|         timestamp: new Date(), |         timestamp: new Date(), | ||||||
|         content: 'question', |         content: 'question', | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  | @ -14,5 +14,4 @@ export interface QuestionDTO { | ||||||
| export interface QuestionId { | export interface QuestionId { | ||||||
|     learningObjectIdentifier: LearningObjectIdentifier; |     learningObjectIdentifier: LearningObjectIdentifier; | ||||||
|     sequenceNumber: number; |     sequenceNumber: number; | ||||||
|     inGroup: GroupDTO; |  | ||||||
| } | } | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger