Merge remote-tracking branch 'origin/dev' into feat/endpoints-beschermen-met-authenticatie-#105
# Conflicts: # backend/src/services/questions.ts
This commit is contained in:
commit
e799705a09
32 changed files with 579 additions and 8874 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@dwengo-1/backend",
|
||||
"version": "0.1.1",
|
||||
"version": "0.2.0",
|
||||
"description": "Backend for Dwengo-1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
|
|
@ -31,7 +31,7 @@ export function getQuestionId(learningObjectIdentifier: LearningObjectIdentifier
|
|||
export async function getAllQuestionsHandler(req: Request, res: Response): Promise<void> {
|
||||
const hruid = req.params.hruid;
|
||||
const version = req.params.version;
|
||||
const language = req.query.lang as string;
|
||||
const language = (req.query.lang ? req.query.lang : FALLBACK_LANG) as string;
|
||||
const full = req.query.full === 'true';
|
||||
requireFields({ hruid });
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ export async function getStudentAssignmentsHandler(req: Request, res: Response):
|
|||
const username = req.params.username;
|
||||
requireFields({ username });
|
||||
|
||||
const assignments = getStudentAssignments(username, full);
|
||||
const assignments = await getStudentAssignments(username, full);
|
||||
|
||||
res.json({ assignments });
|
||||
}
|
||||
|
|
|
@ -12,7 +12,11 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> {
|
|||
content: answer.content,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
return this.insert(answerEntity);
|
||||
await this.insert(answerEntity);
|
||||
answerEntity.toQuestion = answer.toQuestion;
|
||||
answerEntity.author = answer.author;
|
||||
answerEntity.content = answer.content;
|
||||
return answerEntity;
|
||||
}
|
||||
public async findAllAnswersToQuestion(question: Question): Promise<Answer[]> {
|
||||
return this.findAll({
|
||||
|
|
|
@ -24,7 +24,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
|
|||
questionEntity.author = question.author;
|
||||
questionEntity.inGroup = question.inGroup;
|
||||
questionEntity.content = question.content;
|
||||
return this.insert(questionEntity);
|
||||
return await this.insert(questionEntity);
|
||||
}
|
||||
public async findAllQuestionsAboutLearningObject(loId: LearningObjectIdentifier): Promise<Question[]> {
|
||||
return this.findAll({
|
||||
|
|
|
@ -12,6 +12,7 @@ import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
|
|||
import { fetchStudent } from './students.js';
|
||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||
import { FALLBACK_VERSION_NUM } from '../config.js';
|
||||
import { fetchAssignment } from './assignments.js';
|
||||
import { ConflictException } from '../exceptions/conflict-exception.js';
|
||||
|
||||
export async function getQuestionsAboutLearningObjectInAssignment(
|
||||
|
@ -87,22 +88,30 @@ export async function createQuestion(loId: LearningObjectIdentifier, questionDat
|
|||
const author = await fetchStudent(questionData.author!);
|
||||
const content = questionData.content;
|
||||
|
||||
const clazz = await getClassRepository().findById((questionData.inGroup.assignment as AssignmentDTO).within);
|
||||
const assignment = mapToAssignment(questionData.inGroup.assignment as AssignmentDTO, clazz!);
|
||||
const group = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionData.inGroup.groupNumber);
|
||||
let assignment;
|
||||
|
||||
if (!group) {
|
||||
if (typeof questionData.inGroup.assignment === 'number' && typeof questionData.inGroup.class === 'string') {
|
||||
assignment = await fetchAssignment(questionData.inGroup.class, questionData.inGroup.assignment);
|
||||
} else {
|
||||
// TODO check if necessary and no conflicts to delete this if
|
||||
const clazz = await getClassRepository().findById((questionData.inGroup.assignment as AssignmentDTO).within);
|
||||
assignment = mapToAssignment(questionData.inGroup.assignment as AssignmentDTO, clazz!);
|
||||
}
|
||||
|
||||
const inGroup = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionData.inGroup.groupNumber);
|
||||
|
||||
if (!inGroup) {
|
||||
throw new NotFoundException('Group with id and assignment not found');
|
||||
}
|
||||
|
||||
if (!group.members.contains(author)) {
|
||||
if (!inGroup.members.contains(author)) {
|
||||
throw new ConflictException('Author is not part of this group');
|
||||
}
|
||||
|
||||
const question = await questionRepository.createQuestion({
|
||||
loId,
|
||||
author,
|
||||
inGroup: group,
|
||||
inGroup: inGroup!,
|
||||
content,
|
||||
});
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ import { EntityManager } from '@mikro-orm/core';
|
|||
import { Answer } from '../../../src/entities/questions/answer.entity';
|
||||
import { Teacher } from '../../../src/entities/users/teacher.entity';
|
||||
import { Question } from '../../../src/entities/questions/question.entity';
|
||||
import { getTestleerkracht1 } from '../users/teachers.testdata';
|
||||
import { getQuestion07 } from './questions.testdata';
|
||||
|
||||
export function makeTestAnswers(em: EntityManager, teachers: Teacher[], questions: Question[]): Answer[] {
|
||||
const answer01 = em.create(Answer, {
|
||||
|
@ -28,5 +30,21 @@ export function makeTestAnswers(em: EntityManager, teachers: Teacher[], question
|
|||
content: 'answer3',
|
||||
});
|
||||
|
||||
return [answer01, answer02, answer03];
|
||||
const answer04 = em.create(Answer, {
|
||||
author: getTestleerkracht1(),
|
||||
toQuestion: getQuestion07(),
|
||||
sequenceNumber: 1,
|
||||
timestamp: new Date(),
|
||||
content: 'this is a test answer',
|
||||
});
|
||||
|
||||
const answer05 = em.create(Answer, {
|
||||
author: getTestleerkracht1(),
|
||||
toQuestion: getQuestion07(),
|
||||
sequenceNumber: 2,
|
||||
timestamp: new Date(),
|
||||
content: 'this is a test answer',
|
||||
});
|
||||
|
||||
return [answer01, answer02, answer03, answer04, answer05];
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@ import { Question } from '../../../src/entities/questions/question.entity';
|
|||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { Student } from '../../../src/entities/users/student.entity';
|
||||
import { Group } from '../../../src/entities/assignments/group.entity';
|
||||
import { getTestleerling1 } from '../users/students.testdata';
|
||||
import { testLearningObjectMultipleChoice } from '../content/learning-objects.testdata';
|
||||
import { getGroup1ConditionalLearningPath } from '../assignments/groups.testdata';
|
||||
|
||||
export function makeTestQuestions(em: EntityManager, students: Student[], groups: Group[]): Question[] {
|
||||
const question01 = em.create(Question, {
|
||||
|
@ -66,10 +69,43 @@ export function makeTestQuestions(em: EntityManager, students: Student[], groups
|
|||
learningObjectHruid: 'id05',
|
||||
sequenceNumber: 4,
|
||||
author: students[2],
|
||||
inGroup: groups[3], // Group #4 for Assignment #2 in class 'id02'
|
||||
inGroup: groups[5], // Group #4 for Assignment #2 in class 'id02'
|
||||
timestamp: new Date(),
|
||||
content: 'question',
|
||||
});
|
||||
|
||||
return [question01, question02, question03, question04, question05, question06];
|
||||
question07 = em.create(Question, {
|
||||
learningObjectLanguage: Language.English,
|
||||
learningObjectVersion: 1,
|
||||
learningObjectHruid: testLearningObjectMultipleChoice.hruid,
|
||||
sequenceNumber: 1,
|
||||
author: getTestleerling1(),
|
||||
inGroup: getGroup1ConditionalLearningPath(),
|
||||
timestamp: new Date(),
|
||||
content: 'this is a test question',
|
||||
});
|
||||
|
||||
question08 = em.create(Question, {
|
||||
learningObjectLanguage: Language.English,
|
||||
learningObjectVersion: 1,
|
||||
learningObjectHruid: testLearningObjectMultipleChoice.hruid,
|
||||
sequenceNumber: 2,
|
||||
author: getTestleerling1(),
|
||||
inGroup: getGroup1ConditionalLearningPath(),
|
||||
timestamp: new Date(),
|
||||
content: 'this is a second test question',
|
||||
});
|
||||
|
||||
return [question01, question02, question03, question04, question05, question06, question07, question08];
|
||||
}
|
||||
|
||||
let question08: Question;
|
||||
let question07: Question;
|
||||
|
||||
export function getQuestion07(): Question {
|
||||
return question07;
|
||||
}
|
||||
|
||||
export function getQuestion08(): Question {
|
||||
return question08;
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ export function makeTestTeachers(em: EntityManager): Teacher[] {
|
|||
// Makes sure when logged in as testleerkracht1, there exists a corresponding user
|
||||
testleerkracht1 = em.create(Teacher, {
|
||||
username: 'testleerkracht1',
|
||||
firstName: 'Kris',
|
||||
lastName: 'Coolsaet',
|
||||
firstName: 'David',
|
||||
lastName: 'Bowie',
|
||||
});
|
||||
|
||||
return [teacher01, teacher02, teacher03, teacher04, testleerkracht1];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue