2025SELab2-project-Dwengo/backend/src/data/classes/class-repository.ts
2025-03-07 23:09:51 +01:00

29 lines
1 KiB
TypeScript

import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
import { Class } from '../../entities/classes/class.entity.js';
import { Student } from '../../entities/users/student.entity.js';
import {Teacher} from "../../entities/users/teacher.entity";
export class ClassRepository extends DwengoEntityRepository<Class> {
public findById(id: string): Promise<Class | null> {
return this.findOne(
{ classId: id },
{ populate: ["students", "teachers"] },
);
}
public deleteById(id: string): Promise<void> {
return this.deleteWhere({ classId: id });
}
public findByStudent(student: Student): Promise<Class[]> {
return this.find(
{ students: student },
{ populate: ["students", "teachers"] } // voegt student en teacher objecten toe
)
}
public findByTeacher(teacher: Teacher): Promise<Class[]> {
return this.find(
{ teachers: teacher },
{ populate: ["students", "teachers"] }
);
}
}