Merge branch 'feat/endpoints-in-backend-om-eigen-leerpaden-en-leerobjecten-toe-te-voegen-aan-de-databank-#248' of https://github.com/SELab-2/Dwengo-1 into feat/endpoints-in-backend-om-eigen-leerpaden-en-leerobjecten-toe-te-voegen-aan-de-databank-#248
This commit is contained in:
commit
e0f6cc4150
72 changed files with 891 additions and 344 deletions
|
@ -34,7 +34,7 @@ export async function createAnswer(questionId: QuestionId, answerData: AnswerDat
|
|||
return mapToAnswerDTO(answer);
|
||||
}
|
||||
|
||||
async function fetchAnswer(questionId: QuestionId, sequenceNumber: number): Promise<Answer> {
|
||||
export async function fetchAnswer(questionId: QuestionId, sequenceNumber: number): Promise<Answer> {
|
||||
const answerRepository = getAnswerRepository();
|
||||
const question = await fetchQuestion(questionId);
|
||||
const answer = await answerRepository.findAnswer(question, sequenceNumber);
|
||||
|
|
|
@ -34,6 +34,15 @@ export async function fetchGroup(classId: string, assignmentNumber: number, grou
|
|||
return group;
|
||||
}
|
||||
|
||||
export async function fetchAllGroups(classId: string, assignmentNumber: number): Promise<Group[]> {
|
||||
const assignment = await fetchAssignment(classId, assignmentNumber);
|
||||
|
||||
const groupRepository = getGroupRepository();
|
||||
const groups = await groupRepository.findAllGroupsForAssignment(assignment);
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
export async function getGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<GroupDTO> {
|
||||
const group = await fetchGroup(classId, assignmentNumber, groupNumber);
|
||||
return mapToGroupDTO(group, group.assignment.within);
|
||||
|
|
|
@ -141,11 +141,11 @@ const learningPathService = {
|
|||
|
||||
// Verify that all specified learning objects actually exist.
|
||||
const learningObjectsOnPath = await Promise.all(
|
||||
path.nodes.map(async node =>
|
||||
path.nodes.map(async (node) =>
|
||||
learningObjectService.getLearningObjectById({
|
||||
hruid: node.learningObjectHruid,
|
||||
language: node.language,
|
||||
version: node.version
|
||||
version: node.version,
|
||||
})
|
||||
)
|
||||
);
|
||||
|
|
|
@ -13,6 +13,7 @@ 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(
|
||||
loId: LearningObjectIdentifier,
|
||||
|
@ -99,10 +100,18 @@ export async function createQuestion(loId: LearningObjectIdentifier, questionDat
|
|||
|
||||
const inGroup = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionData.inGroup.groupNumber);
|
||||
|
||||
if (!inGroup) {
|
||||
throw new NotFoundException('Group with id and assignment not found');
|
||||
}
|
||||
|
||||
if (!inGroup.members.contains(author)) {
|
||||
throw new ConflictException('Author is not part of this group');
|
||||
}
|
||||
|
||||
const question = await questionRepository.createQuestion({
|
||||
loId,
|
||||
author,
|
||||
inGroup: inGroup!,
|
||||
inGroup: inGroup,
|
||||
content,
|
||||
});
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/subm
|
|||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request';
|
||||
import { ConflictException } from '../exceptions/conflict-exception.js';
|
||||
import { Submission } from '../entities/assignments/submission.entity';
|
||||
import { Submission } from '../entities/assignments/submission.entity.js';
|
||||
import { mapToUsername } from '../interfaces/user.js';
|
||||
|
||||
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
|
@ -34,7 +35,7 @@ export async function getAllStudents(full: boolean): Promise<StudentDTO[] | stri
|
|||
return users.map(mapToStudentDTO);
|
||||
}
|
||||
|
||||
return users.map((user) => user.username);
|
||||
return users.map(mapToUsername);
|
||||
}
|
||||
|
||||
export async function fetchStudent(username: string): Promise<Student> {
|
||||
|
@ -64,7 +65,7 @@ export async function createStudent(userData: StudentDTO): Promise<StudentDTO> {
|
|||
const newStudent = mapToStudent(userData);
|
||||
await studentRepository.save(newStudent, { preventOverwrite: true });
|
||||
|
||||
return userData;
|
||||
return mapToStudentDTO(newStudent);
|
||||
}
|
||||
|
||||
export async function createOrUpdateStudent(userData: StudentDTO): Promise<StudentDTO> {
|
||||
|
|
|
@ -32,6 +32,10 @@ export async function createInvitation(data: TeacherInvitationData): Promise<Tea
|
|||
throw new ConflictException('The teacher sending the invite is not part of the class');
|
||||
}
|
||||
|
||||
if (cls.teachers.contains(receiver)) {
|
||||
throw new ConflictException('The teacher receiving the invite is already part of the class');
|
||||
}
|
||||
|
||||
const newInvitation = mapToInvitation(sender, receiver, cls);
|
||||
await teacherInvitationRepository.save(newInvitation, { preventOverwrite: true });
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import { StudentDTO } from '@dwengo-1/common/interfaces/student';
|
|||
import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request';
|
||||
import { ClassStatus } from '@dwengo-1/common/util/class-join-request';
|
||||
import { ConflictException } from '../exceptions/conflict-exception.js';
|
||||
import { mapToUsername } from '../interfaces/user.js';
|
||||
|
||||
export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> {
|
||||
const teacherRepository: TeacherRepository = getTeacherRepository();
|
||||
|
@ -26,7 +27,7 @@ export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | stri
|
|||
if (full) {
|
||||
return users.map(mapToTeacherDTO);
|
||||
}
|
||||
return users.map((user) => user.username);
|
||||
return users.map(mapToUsername);
|
||||
}
|
||||
|
||||
export async function fetchTeacher(username: string): Promise<Teacher> {
|
||||
|
@ -45,7 +46,8 @@ export async function getTeacher(username: string): Promise<TeacherDTO> {
|
|||
return mapToTeacherDTO(user);
|
||||
}
|
||||
|
||||
export async function createTeacher(userData: TeacherDTO): Promise<TeacherDTO> {
|
||||
// TODO update parameter
|
||||
export async function createTeacher(userData: TeacherDTO, _update?: boolean): Promise<TeacherDTO> {
|
||||
const teacherRepository: TeacherRepository = getTeacherRepository();
|
||||
|
||||
const newTeacher = mapToTeacher(userData);
|
||||
|
@ -98,7 +100,9 @@ export async function getStudentsByTeacher(username: string, full: boolean): Pro
|
|||
|
||||
const classIds: string[] = classes.map((cls) => cls.id);
|
||||
|
||||
const students: StudentDTO[] = (await Promise.all(classIds.map(async (username) => await getClassStudentsDTO(username)))).flat();
|
||||
const students: StudentDTO[] = (await Promise.all(classIds.map(async (classId) => await getClassStudentsDTO(classId))))
|
||||
.flat()
|
||||
.filter((student, index, self) => self.findIndex((s) => s.username === student.username) === index);
|
||||
|
||||
if (full) {
|
||||
return students;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue