fix: juiste responsecodes en messages toegevoegd
This commit is contained in:
parent
59e8f2fcf2
commit
1664642940
9 changed files with 61 additions and 17 deletions
|
@ -21,7 +21,7 @@ export async function getAllAssignments(classid: string, full: boolean): Promise
|
|||
return assignments.map(mapToAssignmentDTOId);
|
||||
}
|
||||
|
||||
export async function createAssignment(classid: string, assignmentData: AssignmentDTO): Promise<Assignment | null> {
|
||||
export async function createAssignment(classid: string, assignmentData: AssignmentDTO): Promise<AssignmentDTO | null> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classid);
|
||||
|
||||
|
@ -36,7 +36,7 @@ export async function createAssignment(classid: string, assignmentData: Assignme
|
|||
const newAssignment = assignmentRepository.create(assignment);
|
||||
await assignmentRepository.save(newAssignment);
|
||||
|
||||
return newAssignment;
|
||||
return mapToAssignmentDTO(newAssignment);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ export async function getAllClasses(full: boolean): Promise<ClassDTO[] | string[
|
|||
return classes.map((cls) => cls.classId!);
|
||||
}
|
||||
|
||||
export async function createClass(classData: ClassDTO): Promise<Class | null> {
|
||||
export async function createClass(classData: ClassDTO): Promise<ClassDTO | null> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
const teacherUsernames = classData.teachers || [];
|
||||
const teachers = (await Promise.all(teacherUsernames.map((id) => teacherRepository.findByUsername(id)))).filter((teacher) => teacher != null);
|
||||
|
@ -42,7 +42,7 @@ export async function createClass(classData: ClassDTO): Promise<Class | null> {
|
|||
});
|
||||
await classRepository.save(newClass);
|
||||
|
||||
return newClass;
|
||||
return mapToClassDTO(newClass);
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
return null;
|
||||
|
|
|
@ -103,5 +103,5 @@ export async function deleteQuestion(questionId: QuestionId) {
|
|||
return null;
|
||||
}
|
||||
|
||||
return question;
|
||||
return mapToQuestionDTO(question);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ export async function createSubmission(submissionDTO: SubmissionDTO) {
|
|||
return null;
|
||||
}
|
||||
|
||||
return submission;
|
||||
return mapToSubmissionDTO(submission);
|
||||
}
|
||||
|
||||
export async function deleteSubmission(learningObjectHruid: string, language: Language, version: number, submissionNumber: number) {
|
||||
|
|
|
@ -64,11 +64,11 @@ export async function deleteTeacher(username: string): Promise<TeacherDTO | null
|
|||
}
|
||||
}
|
||||
|
||||
export async function fetchClassesByTeacher(username: string): Promise<ClassDTO[]> {
|
||||
export async function fetchClassesByTeacher(username: string): Promise<ClassDTO[] | null> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
const teacher = await teacherRepository.findByUsername(username);
|
||||
if (!teacher) {
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
const classRepository = getClassRepository();
|
||||
|
@ -76,9 +76,13 @@ export async function fetchClassesByTeacher(username: string): Promise<ClassDTO[
|
|||
return classes.map(mapToClassDTO);
|
||||
}
|
||||
|
||||
export async function getClassesByTeacher(username: string, full: boolean): Promise<ClassDTO[] | string[]> {
|
||||
export async function getClassesByTeacher(username: string, full: boolean): Promise<ClassDTO[] | string[] | null> {
|
||||
const classes = await fetchClassesByTeacher(username);
|
||||
|
||||
if (!classes) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (full) {
|
||||
return classes;
|
||||
}
|
||||
|
@ -86,15 +90,23 @@ export async function getClassesByTeacher(username: string, full: boolean): Prom
|
|||
return classes.map((cls) => cls.id);
|
||||
}
|
||||
|
||||
export async function fetchStudentsByTeacher(username: string) {
|
||||
export async function fetchStudentsByTeacher(username: string): Promise<StudentDTO[] | null> {
|
||||
const classes = (await getClassesByTeacher(username, false)) as string[];
|
||||
|
||||
if (!classes) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (await Promise.all(classes.map(async (id) => getClassStudents(id)))).flat();
|
||||
}
|
||||
|
||||
export async function getStudentsByTeacher(username: string, full: boolean): Promise<StudentDTO[] | string[]> {
|
||||
export async function getStudentsByTeacher(username: string, full: boolean): Promise<StudentDTO[] | string[] | null> {
|
||||
const students = await fetchStudentsByTeacher(username);
|
||||
|
||||
if (!students) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (full) {
|
||||
return students;
|
||||
}
|
||||
|
@ -102,11 +114,11 @@ export async function getStudentsByTeacher(username: string, full: boolean): Pro
|
|||
return students.map((student) => student.username);
|
||||
}
|
||||
|
||||
export async function fetchTeacherQuestions(username: string): Promise<QuestionDTO[]> {
|
||||
export async function fetchTeacherQuestions(username: string): Promise<QuestionDTO[] | null> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
const teacher = await teacherRepository.findByUsername(username);
|
||||
if (!teacher) {
|
||||
throw new Error(`Teacher with username '${username}' not found.`);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Find all learning objects that this teacher manages
|
||||
|
@ -120,9 +132,13 @@ export async function fetchTeacherQuestions(username: string): Promise<QuestionD
|
|||
return questions.map(mapToQuestionDTO);
|
||||
}
|
||||
|
||||
export async function getQuestionsByTeacher(username: string, full: boolean): Promise<QuestionDTO[] | QuestionId[]> {
|
||||
export async function getQuestionsByTeacher(username: string, full: boolean): Promise<QuestionDTO[] | QuestionId[] | null> {
|
||||
const questions = await fetchTeacherQuestions(username);
|
||||
|
||||
if (!questions) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (full) {
|
||||
return questions;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue