fix: integratie user + errors gefixt zodat het runt + format
This commit is contained in:
parent
6c4ea0eefb
commit
1b096b411b
55 changed files with 858 additions and 594 deletions
|
@ -2,43 +2,62 @@ import { Request, Response } from 'express';
|
|||
import {
|
||||
getStudentClasses,
|
||||
getStudentClassIds,
|
||||
StudentService
|
||||
StudentService,
|
||||
} from '../services/students.js';
|
||||
import { ClassDTO } from '../interfaces/classes.js';
|
||||
import { ClassDTO } from '../interfaces/class.js';
|
||||
import { getAllAssignments } from '../services/assignments.js';
|
||||
import {createUserHandler, deleteUserHandler, getAllUsersHandler, getUserHandler} from "./users.js";
|
||||
import { Student } from "../entities/users/student.entity.js";
|
||||
import {
|
||||
createUserHandler,
|
||||
deleteUserHandler,
|
||||
getAllUsersHandler,
|
||||
getUserHandler,
|
||||
} from './users.js';
|
||||
import { Student } from '../entities/users/student.entity.js';
|
||||
|
||||
// TODO: accept arguments (full, ...)
|
||||
// TODO: endpoints
|
||||
export async function getAllStudentsHandler (req: Request, res: Response): Promise<void> {
|
||||
export async function getAllStudentsHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
await getAllUsersHandler<Student>(req, res, new StudentService());
|
||||
}
|
||||
|
||||
export async function getStudentHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function getStudentHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
await getUserHandler<Student>(req, res, new StudentService());
|
||||
}
|
||||
|
||||
export async function createStudentHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function createStudentHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
await createUserHandler<Student>(req, res, new StudentService(), Student);
|
||||
}
|
||||
|
||||
export async function deleteStudentHandler(req: Request, res: Response): Promise<void> {
|
||||
export async function deleteStudentHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
await deleteUserHandler<Student>(req, res, new StudentService());
|
||||
}
|
||||
|
||||
|
||||
export async function getStudentClassesHandler (
|
||||
export async function getStudentClassesHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const full = req.query.full === 'true';
|
||||
const username = req.params.id;
|
||||
|
||||
let classes: ClassDTO[] | string[];
|
||||
if (full) classes = await getStudentClasses(username);
|
||||
else classes = await getStudentClassIds(username);
|
||||
if (full) {
|
||||
classes = await getStudentClasses(username);
|
||||
} else {
|
||||
classes = await getStudentClassIds(username);
|
||||
}
|
||||
|
||||
res.json({
|
||||
classes: classes,
|
||||
|
@ -47,7 +66,7 @@ export async function getStudentClassesHandler (
|
|||
classes: `${req.baseUrl}/${req.params.id}/invitations`,
|
||||
questions: `${req.baseUrl}/${req.params.id}/assignments`,
|
||||
students: `${req.baseUrl}/${req.params.id}/students`,
|
||||
}
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching learning objects:', error);
|
||||
|
@ -57,22 +76,26 @@ export async function getStudentClassesHandler (
|
|||
|
||||
// TODO
|
||||
// Might not be fully correct depending on if
|
||||
// a class has an assignment, that all students
|
||||
// have this assignment.
|
||||
// A class has an assignment, that all students
|
||||
// Have this assignment.
|
||||
export async function getStudentAssignmentsHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
const full = req.query.full === 'true';
|
||||
const username = req.params.id;
|
||||
|
||||
const classes = await getStudentClasses(username);
|
||||
|
||||
const assignments = (await Promise.all(classes.map(async cls => await getAllAssignments(cls.id, full)))).flat();
|
||||
const assignments = (
|
||||
await Promise.all(
|
||||
classes.map(async (cls) => {
|
||||
return await getAllAssignments(cls.id, full);
|
||||
})
|
||||
)
|
||||
).flat();
|
||||
|
||||
res.json({
|
||||
assignments: assignments
|
||||
assignments: assignments,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue