feat: POST method voor class geimplementeerd
This commit is contained in:
parent
a1aaf342d7
commit
79422ab854
8 changed files with 85 additions and 8 deletions
|
@ -1,7 +1,10 @@
|
|||
import {
|
||||
getClassRepository,
|
||||
getStudentRepository,
|
||||
getTeacherInvitationRepository,
|
||||
getTeacherRepository,
|
||||
} from '../data/repositories.js';
|
||||
import { Class } from '../entities/classes/class.entity.js';
|
||||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
||||
import { mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
||||
import {
|
||||
|
@ -27,10 +30,39 @@ export async function getAllClasses(
|
|||
return classes.map(mapToClassDTO);
|
||||
}
|
||||
return classes.map((cls) => {
|
||||
return cls.classId;
|
||||
return cls.classId!;
|
||||
});
|
||||
}
|
||||
|
||||
export async function createClass(classData: ClassDTO): Promise<Class | null> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
const teacherUsernames = classData.teachers || [];
|
||||
const teachers = (await Promise.all(teacherUsernames.map(id => teacherRepository.findByUsername(id))))
|
||||
.filter(teacher => teacher != null);
|
||||
|
||||
const studentRepository = getStudentRepository();
|
||||
const studentUsernames = classData.students || [];
|
||||
const students = (await Promise.all(studentUsernames.map(id => studentRepository.findByUsername(id))))
|
||||
.filter(student => student != null);
|
||||
|
||||
//const cls = mapToClass(classData, teachers, students);
|
||||
|
||||
const classRepository = getClassRepository();
|
||||
|
||||
try {
|
||||
const newClass = classRepository.create({
|
||||
displayName: classData.displayName,
|
||||
teachers: teachers,
|
||||
students: students,
|
||||
});
|
||||
await classRepository.save(newClass);
|
||||
|
||||
return newClass;
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getClass(classId: string): Promise<ClassDTO | null> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classId);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue