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> {
|
||||
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' });
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -3,15 +3,16 @@ import { Question } from '../../entities/questions/question.entity.js';
|
|||
import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier.js';
|
||||
import { Student } from '../../entities/users/student.entity.js';
|
||||
import { LearningObject } from '../../entities/content/learning-object.entity.js';
|
||||
import {Group} from "../../entities/assignments/group.entity";
|
||||
|
||||
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({
|
||||
learningObjectHruid: question.loId.hruid,
|
||||
learningObjectLanguage: question.loId.language,
|
||||
learningObjectVersion: question.loId.version,
|
||||
author: question.author,
|
||||
group: question.group,
|
||||
inGroup: question.inGroup,
|
||||
content: question.content,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
|
@ -19,7 +20,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
|||
questionEntity.learningObjectLanguage = question.loId.language;
|
||||
questionEntity.learningObjectVersion = question.loId.version;
|
||||
questionEntity.author = question.author;
|
||||
questionEntity.group = question.group;
|
||||
questionEntity.inGroup = question.inGroup;
|
||||
questionEntity.content = question.content;
|
||||
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 { QuestionRepository } from '../../data/questions/question-repository.js';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import {Group} from "../assignments/group.entity";
|
||||
|
||||
@Entity({ repository: () => QuestionRepository })
|
||||
export class Question {
|
||||
|
@ -21,7 +22,7 @@ export class Question {
|
|||
sequenceNumber?: number;
|
||||
|
||||
@ManyToOne({ entity: () => Group, primary: true })
|
||||
inGroup: Group;
|
||||
inGroup!: Group;
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Student,
|
||||
|
|
|
@ -80,6 +80,7 @@ export async function createQuestion(questionDTO: QuestionDTO): Promise<Question
|
|||
await questionRepository.createQuestion({
|
||||
loId,
|
||||
author,
|
||||
inGroup: questionDTO.inGroup,
|
||||
content: questionDTO.content,
|
||||
});
|
||||
} catch (_) {
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import { LearningObjectIdentifier } from './learning-content';
|
||||
import { StudentDTO } from './student';
|
||||
import {GroupDTO} from "./group";
|
||||
|
||||
export interface QuestionDTO {
|
||||
learningObjectIdentifier: LearningObjectIdentifier;
|
||||
sequenceNumber?: number;
|
||||
author: StudentDTO;
|
||||
inGroup: GroupDTO;
|
||||
timestamp?: string;
|
||||
content: string;
|
||||
}
|
||||
|
@ -12,4 +14,5 @@ export interface QuestionDTO {
|
|||
export interface QuestionId {
|
||||
learningObjectIdentifier: LearningObjectIdentifier;
|
||||
sequenceNumber: number;
|
||||
inGroup: GroupDTO;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ export interface SubmissionDTO {
|
|||
submissionNumber?: number;
|
||||
submitter: StudentDTO;
|
||||
time?: Date;
|
||||
group?: GroupDTO;
|
||||
group: GroupDTO;
|
||||
content: string;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue