fix(backend): Services en controllers aan gewijzigde primaire sleutel van Question en Submission aangepast.
This commit is contained in:
		
							parent
							
								
									12c1505ba7
								
							
						
					
					
						commit
						f9b83bc4af
					
				
					 6 changed files with 12 additions and 6 deletions
				
			
		|  | @ -88,7 +88,7 @@ export async function getQuestionAnswersHandler(req: Request, res: Response): Pr | ||||||
| export async function createQuestionHandler(req: Request, res: Response): Promise<void> { | export async function createQuestionHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const questionDTO = req.body as QuestionDTO; |     const questionDTO = req.body as QuestionDTO; | ||||||
| 
 | 
 | ||||||
|     if (!questionDTO.learningObjectIdentifier || !questionDTO.author || !questionDTO.content) { |     if (!questionDTO.learningObjectIdentifier || !questionDTO.author || !questionDTO.inGroup || !questionDTO.content) { | ||||||
|         res.status(400).json({ error: 'Missing required fields: identifier and content' }); |         res.status(400).json({ error: 'Missing required fields: identifier and content' }); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -3,15 +3,16 @@ import { Question } from '../../entities/questions/question.entity.js'; | ||||||
| import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; | import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js'; | ||||||
| import { Student } from '../../entities/users/student.entity.js'; | import { Student } from '../../entities/users/student.entity.js'; | ||||||
| import { LearningObject } from '../../entities/content/learning-object.entity.js'; | import { LearningObject } from '../../entities/content/learning-object.entity.js'; | ||||||
|  | import {Group} from "../../entities/assignments/group.entity"; | ||||||
| 
 | 
 | ||||||
| export class QuestionRepository extends DwengoEntityRepository<Question> { | export class QuestionRepository extends DwengoEntityRepository<Question> { | ||||||
|     public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; group: Group, content: string }): Promise<Question> { |     public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; inGroup: Group, content: string }): Promise<Question> { | ||||||
|         const questionEntity = this.create({ |         const questionEntity = this.create({ | ||||||
|             learningObjectHruid: question.loId.hruid, |             learningObjectHruid: question.loId.hruid, | ||||||
|             learningObjectLanguage: question.loId.language, |             learningObjectLanguage: question.loId.language, | ||||||
|             learningObjectVersion: question.loId.version, |             learningObjectVersion: question.loId.version, | ||||||
|             author: question.author, |             author: question.author, | ||||||
|             group: question.group, |             inGroup: question.inGroup, | ||||||
|             content: question.content, |             content: question.content, | ||||||
|             timestamp: new Date(), |             timestamp: new Date(), | ||||||
|         }); |         }); | ||||||
|  | @ -19,7 +20,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> { | ||||||
|         questionEntity.learningObjectLanguage = question.loId.language; |         questionEntity.learningObjectLanguage = question.loId.language; | ||||||
|         questionEntity.learningObjectVersion = question.loId.version; |         questionEntity.learningObjectVersion = question.loId.version; | ||||||
|         questionEntity.author = question.author; |         questionEntity.author = question.author; | ||||||
|         questionEntity.group = question.group; |         questionEntity.inGroup = question.inGroup; | ||||||
|         questionEntity.content = question.content; |         questionEntity.content = question.content; | ||||||
|         return this.insert(questionEntity); |         return this.insert(questionEntity); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ import { Entity, Enum, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; | ||||||
| import { Student } from '../users/student.entity.js'; | import { Student } from '../users/student.entity.js'; | ||||||
| import { QuestionRepository } from '../../data/questions/question-repository.js'; | import { QuestionRepository } from '../../data/questions/question-repository.js'; | ||||||
| import { Language } from '@dwengo-1/common/util/language'; | import { Language } from '@dwengo-1/common/util/language'; | ||||||
|  | import {Group} from "../assignments/group.entity"; | ||||||
| 
 | 
 | ||||||
| @Entity({ repository: () => QuestionRepository }) | @Entity({ repository: () => QuestionRepository }) | ||||||
| export class Question { | export class Question { | ||||||
|  | @ -21,7 +22,7 @@ export class Question { | ||||||
|     sequenceNumber?: number; |     sequenceNumber?: number; | ||||||
| 
 | 
 | ||||||
|     @ManyToOne({ entity: () => Group, primary: true }) |     @ManyToOne({ entity: () => Group, primary: true }) | ||||||
|     inGroup: Group; |     inGroup!: Group; | ||||||
| 
 | 
 | ||||||
|     @ManyToOne({ |     @ManyToOne({ | ||||||
|         entity: () => Student, |         entity: () => Student, | ||||||
|  |  | ||||||
|  | @ -80,6 +80,7 @@ export async function createQuestion(questionDTO: QuestionDTO): Promise<Question | ||||||
|         await questionRepository.createQuestion({ |         await questionRepository.createQuestion({ | ||||||
|             loId, |             loId, | ||||||
|             author, |             author, | ||||||
|  |             inGroup: questionDTO.inGroup, | ||||||
|             content: questionDTO.content, |             content: questionDTO.content, | ||||||
|         }); |         }); | ||||||
|     } catch (_) { |     } catch (_) { | ||||||
|  |  | ||||||
|  | @ -1,10 +1,12 @@ | ||||||
| import { LearningObjectIdentifier } from './learning-content'; | import { LearningObjectIdentifier } from './learning-content'; | ||||||
| import { StudentDTO } from './student'; | import { StudentDTO } from './student'; | ||||||
|  | import {GroupDTO} from "./group"; | ||||||
| 
 | 
 | ||||||
| export interface QuestionDTO { | export interface QuestionDTO { | ||||||
|     learningObjectIdentifier: LearningObjectIdentifier; |     learningObjectIdentifier: LearningObjectIdentifier; | ||||||
|     sequenceNumber?: number; |     sequenceNumber?: number; | ||||||
|     author: StudentDTO; |     author: StudentDTO; | ||||||
|  |     inGroup: GroupDTO; | ||||||
|     timestamp?: string; |     timestamp?: string; | ||||||
|     content: string; |     content: string; | ||||||
| } | } | ||||||
|  | @ -12,4 +14,5 @@ export interface QuestionDTO { | ||||||
| export interface QuestionId { | export interface QuestionId { | ||||||
|     learningObjectIdentifier: LearningObjectIdentifier; |     learningObjectIdentifier: LearningObjectIdentifier; | ||||||
|     sequenceNumber: number; |     sequenceNumber: number; | ||||||
|  |     inGroup: GroupDTO; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ export interface SubmissionDTO { | ||||||
|     submissionNumber?: number; |     submissionNumber?: number; | ||||||
|     submitter: StudentDTO; |     submitter: StudentDTO; | ||||||
|     time?: Date; |     time?: Date; | ||||||
|     group?: GroupDTO; |     group: GroupDTO; | ||||||
|     content: string; |     content: string; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger