fix(backend): Verdere door de aanpassingen veroorzaakte compilatiefouten opgelost
This commit is contained in:
parent
f9b83bc4af
commit
b1df95da63
7 changed files with 46 additions and 15 deletions
|
@ -4,6 +4,7 @@ import { FALLBACK_LANG, FALLBACK_SEQ_NUM } from '../config.js';
|
|||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import {getGroup} from "../services/groups";
|
||||
|
||||
function getObjectId(req: Request, res: Response): LearningObjectIdentifier | null {
|
||||
const { hruid, version } = req.params;
|
||||
|
@ -21,16 +22,18 @@ function getObjectId(req: Request, res: Response): LearningObjectIdentifier | nu
|
|||
};
|
||||
}
|
||||
|
||||
function getQuestionId(req: Request, res: Response): QuestionId | null {
|
||||
const seq = req.params.seq;
|
||||
async function getQuestionId(req: Request, res: Response): Promise<QuestionId | null> {
|
||||
const { seq, classId, assignmentId, groupId } = req.params
|
||||
const learningObjectIdentifier = getObjectId(req, res);
|
||||
const groupIdentifier = await getGroup(classId, parseInt(assignmentId), parseInt(groupId), false);
|
||||
|
||||
if (!learningObjectIdentifier) {
|
||||
if (!learningObjectIdentifier || !groupIdentifier) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
learningObjectIdentifier,
|
||||
inGroup: groupIdentifier,
|
||||
sequenceNumber: seq ? Number(seq) : FALLBACK_SEQ_NUM,
|
||||
};
|
||||
}
|
||||
|
@ -53,7 +56,7 @@ export async function getAllQuestionsHandler(req: Request, res: Response): Promi
|
|||
}
|
||||
|
||||
export async function getQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
const questionId = await getQuestionId(req, res);
|
||||
|
||||
if (!questionId) {
|
||||
return;
|
||||
|
@ -69,7 +72,7 @@ export async function getQuestionHandler(req: Request, res: Response): Promise<v
|
|||
}
|
||||
|
||||
export async function getQuestionAnswersHandler(req: Request, res: Response): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
const questionId = await getQuestionId(req, res);
|
||||
const full = req.query.full === 'true';
|
||||
|
||||
if (!questionId) {
|
||||
|
@ -103,7 +106,7 @@ export async function createQuestionHandler(req: Request, res: Response): Promis
|
|||
}
|
||||
|
||||
export async function deleteQuestionHandler(req: Request, res: Response): Promise<void> {
|
||||
const questionId = getQuestionId(req, res);
|
||||
const questionId = await getQuestionId(req, res);
|
||||
|
||||
if (!questionId) {
|
||||
return;
|
||||
|
|
|
@ -25,7 +25,7 @@ export class Submission {
|
|||
entity: () => Group,
|
||||
primary: true
|
||||
})
|
||||
onBehalfOf: Group;
|
||||
onBehalfOf!: Group;
|
||||
|
||||
@ManyToOne({
|
||||
entity: () => Student,
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
import { Group } from '../entities/assignments/group.entity.js';
|
||||
import { mapToAssignmentDTO } from './assignment.js';
|
||||
import { mapToStudentDTO } from './student.js';
|
||||
import {mapToAssignment, mapToAssignmentDTO} from './assignment.js';
|
||||
import {mapToStudent, mapToStudentDTO} from './student.js';
|
||||
import { GroupDTO } from '@dwengo-1/common/interfaces/group';
|
||||
import {getGroupRepository} from "../data/repositories";
|
||||
import {AssignmentDTO} from "@dwengo-1/common/interfaces/assignment";
|
||||
import {Class} from "../entities/classes/class.entity";
|
||||
import {StudentDTO} from "@dwengo-1/common/interfaces/student";
|
||||
|
||||
export function mapToGroup(groupDto: GroupDTO, clazz: Class): Group {
|
||||
const assignmentDto = groupDto.assignment as AssignmentDTO;
|
||||
|
||||
return getGroupRepository().create({
|
||||
groupNumber: groupDto.groupNumber,
|
||||
assignment: mapToAssignment(assignmentDto, clazz!),
|
||||
members: groupDto.members.map(studentDto => mapToStudent(studentDto as StudentDTO))
|
||||
});
|
||||
}
|
||||
|
||||
export function mapToGroupDTO(group: Group): GroupDTO {
|
||||
return {
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Question } from '../entities/questions/question.entity.js';
|
|||
import { mapToStudentDTO } from './student.js';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { LearningObjectIdentifier } from '@dwengo-1/common/interfaces/learning-content';
|
||||
import {mapToGroupDTO} from "./group";
|
||||
|
||||
function getLearningObjectIdentifier(question: Question): LearningObjectIdentifier {
|
||||
return {
|
||||
|
@ -21,6 +22,7 @@ export function mapToQuestionDTO(question: Question): QuestionDTO {
|
|||
learningObjectIdentifier,
|
||||
sequenceNumber: question.sequenceNumber!,
|
||||
author: mapToStudentDTO(question.author),
|
||||
inGroup: mapToGroupDTO(question.inGroup),
|
||||
timestamp: question.timestamp.toISOString(),
|
||||
content: question.content,
|
||||
};
|
||||
|
@ -31,6 +33,7 @@ export function mapToQuestionDTOId(question: Question): QuestionId {
|
|||
|
||||
return {
|
||||
learningObjectIdentifier,
|
||||
inGroup: mapToGroupDTO(question.inGroup),
|
||||
sequenceNumber: question.sequenceNumber!,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ export function mapToSubmissionDTO(submission: Submission): SubmissionDTO {
|
|||
submissionNumber: submission.submissionNumber,
|
||||
submitter: mapToStudentDTO(submission.submitter),
|
||||
time: submission.submissionTime,
|
||||
group: submission.onBehalfOf ? mapToGroupDTO(submission.onBehalfOf) : undefined,
|
||||
group: mapToGroupDTO(submission.onBehalfOf),
|
||||
content: submission.content,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ router.get('/', getAllQuestionsHandler);
|
|||
|
||||
router.post('/', createQuestionHandler);
|
||||
|
||||
router.delete('/:seq', deleteQuestionHandler);
|
||||
router.delete('/:classId/assignment/:assignmentId/group/:groupId/:seq', deleteQuestionHandler);
|
||||
|
||||
// Information about a question with id
|
||||
router.get('/:seq', getQuestionHandler);
|
||||
router.get('/:classId/assignment/:assignmentId/group/:groupId/:seq', getQuestionHandler);
|
||||
|
||||
router.get('/answers/:seq', getQuestionAnswersHandler);
|
||||
router.get('/:classId/assignment/:assignmentId/group/:groupId/answers/:seq', getQuestionAnswersHandler);
|
||||
|
||||
export default router;
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js';
|
||||
import {
|
||||
getAnswerRepository,
|
||||
getClassRepository,
|
||||
getGroupRepository,
|
||||
getQuestionRepository
|
||||
} from '../data/repositories.js';
|
||||
import { mapToQuestionDTO, mapToQuestionDTOId } from '../interfaces/question.js';
|
||||
import { Question } from '../entities/questions/question.entity.js';
|
||||
import { Answer } from '../entities/questions/answer.entity.js';
|
||||
|
@ -8,6 +13,8 @@ import { LearningObjectIdentifier } from '../entities/content/learning-object-id
|
|||
import { mapToStudent } from '../interfaces/student.js';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { AnswerDTO, AnswerId } from '@dwengo-1/common/interfaces/answer';
|
||||
import {AssignmentDTO} from "@dwengo-1/common/interfaces/assignment";
|
||||
import {mapToAssignment} from "../interfaces/assignment";
|
||||
|
||||
export async function getAllQuestions(id: LearningObjectIdentifier, full: boolean): Promise<QuestionDTO[] | QuestionId[]> {
|
||||
const questionRepository: QuestionRepository = getQuestionRepository();
|
||||
|
@ -76,11 +83,15 @@ export async function createQuestion(questionDTO: QuestionDTO): Promise<Question
|
|||
version: questionDTO.learningObjectIdentifier.version ?? 1,
|
||||
};
|
||||
|
||||
const clazz = await getClassRepository().findById((questionDTO.inGroup.assignment as AssignmentDTO).class)
|
||||
const assignment = mapToAssignment(questionDTO.inGroup.assignment as AssignmentDTO, clazz!);
|
||||
const inGroup = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionDTO.inGroup.groupNumber);
|
||||
|
||||
try {
|
||||
await questionRepository.createQuestion({
|
||||
loId,
|
||||
author,
|
||||
inGroup: questionDTO.inGroup,
|
||||
inGroup: inGroup!,
|
||||
content: questionDTO.content,
|
||||
});
|
||||
} catch (_) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue