feat(backend): Eigen error handler toegevoegd.
Hiervoor was ook refactoring aan de exception-klassen nodig.
This commit is contained in:
parent
bc94b25a6a
commit
aaa71aa648
14 changed files with 103 additions and 55 deletions
|
@ -5,6 +5,9 @@ import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js
|
|||
import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
||||
import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js';
|
||||
import { getAllAssignments } from './assignments.js';
|
||||
import {UniqueConstraintViolationException} from "@mikro-orm/core";
|
||||
|
||||
import {ConflictException} from "../exceptions/conflict-exception";
|
||||
|
||||
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
|
@ -29,11 +32,12 @@ export async function createStudent(userData: StudentDTO): Promise<StudentDTO |
|
|||
try {
|
||||
const newStudent = mapToStudent(userData);
|
||||
await studentRepository.save(newStudent);
|
||||
|
||||
return mapToStudentDTO(newStudent);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof UniqueConstraintViolationException) {
|
||||
throw new ConflictException(`There is already a user with username '${userData.username}'.`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue