feat: groepen van een leerling geimplmenteerd in backend
This commit is contained in:
parent
1b096b411b
commit
22cdf58fed
3 changed files with 71 additions and 28 deletions
|
@ -1,10 +1,14 @@
|
|||
import {
|
||||
getClassRepository,
|
||||
getGroupRepository,
|
||||
getStudentRepository,
|
||||
} from '../data/repositories.js';
|
||||
import { Class } from '../entities/classes/class.entity.js';
|
||||
import { Student } from '../entities/users/student.entity.js';
|
||||
import { AssignmentDTO } from '../interfaces/assignment.js';
|
||||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
||||
import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||
import { getAllAssignments } from './assignments.js';
|
||||
import { UserService } from './users.js';
|
||||
|
||||
export class StudentService extends UserService<Student> {
|
||||
|
@ -13,7 +17,7 @@ export class StudentService extends UserService<Student> {
|
|||
}
|
||||
}
|
||||
|
||||
async function fetchStudentClasses(username: string): Promise<Class[]> {
|
||||
export async function getStudentClasses(username: string, full: boolean): Promise<ClassDTO[] | string[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
const student = await studentRepository.findByUsername(username);
|
||||
|
||||
|
@ -24,21 +28,49 @@ async function fetchStudentClasses(username: string): Promise<Class[]> {
|
|||
const classRepository = getClassRepository();
|
||||
const classes = await classRepository.findByStudent(student);
|
||||
|
||||
if (!classes) {
|
||||
if (full) {
|
||||
return classes.map(mapToClassDTO);
|
||||
}
|
||||
|
||||
return classes.map((cls) => cls.classId);
|
||||
}
|
||||
|
||||
export async function getStudentAssignments(username: string, full: boolean): Promise<AssignmentDTO[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
const student = await studentRepository.findByUsername(username);
|
||||
|
||||
if (!student) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return classes;
|
||||
const classRepository = getClassRepository();
|
||||
const classes = await classRepository.findByStudent(student);
|
||||
|
||||
const assignments = (
|
||||
await Promise.all(
|
||||
classes.map(async (cls) => {
|
||||
return await getAllAssignments(cls.classId, full);
|
||||
})
|
||||
)
|
||||
).flat();
|
||||
|
||||
return assignments;
|
||||
}
|
||||
|
||||
export async function getStudentClasses(username: string): Promise<ClassDTO[]> {
|
||||
const classes = await fetchStudentClasses(username);
|
||||
return classes.map(mapToClassDTO);
|
||||
}
|
||||
export async function getStudentGroups(username: string, full: boolean): Promise<GroupDTO[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
const student = await studentRepository.findByUsername(username);
|
||||
|
||||
export async function getStudentClassIds(username: string): Promise<string[]> {
|
||||
const classes = await fetchStudentClasses(username);
|
||||
return classes.map((cls) => {
|
||||
return cls.classId;
|
||||
}); // 'class' is a native keyword
|
||||
if (!student) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const groupRepository = getGroupRepository();
|
||||
const groups = await groupRepository.findAllGroupsWithStudent(student);
|
||||
|
||||
if (full) {
|
||||
return groups.map(mapToGroupDTO);
|
||||
}
|
||||
|
||||
return groups.map(mapToGroupDTOId);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue