feat: test service student
This commit is contained in:
parent
5490bd6b86
commit
7ad944c77d
4 changed files with 103 additions and 14 deletions
|
@ -1,7 +1,7 @@
|
|||
import { Request, Response } from 'express';
|
||||
import {
|
||||
createStudent,
|
||||
deleteStudent, getAllStudentIds,
|
||||
deleteStudent,
|
||||
getAllStudents,
|
||||
getStudent,
|
||||
getStudentAssignments,
|
||||
|
@ -16,7 +16,7 @@ import { StudentDTO } from '../interfaces/student.js';
|
|||
export async function getAllStudentsHandler(req: Request, res: Response): Promise<void> {
|
||||
const full = req.query.full === 'true';
|
||||
|
||||
const students: StudentDTO[] | string[] = full ? await getAllStudents() : await getAllStudentIds();
|
||||
const students: StudentDTO[] | string[] = await getAllStudents(full);
|
||||
|
||||
if (!students) {
|
||||
res.status(404).json({ error: `Students not found.` });
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
import { Student } from '../entities/users/student.entity.js';
|
||||
|
||||
export interface StudentDTO {
|
||||
id: string;
|
||||
id?: string;
|
||||
username: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
endpoints?: {
|
||||
classes: string;
|
||||
questions: string;
|
||||
invitations: string;
|
||||
groups: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function mapToStudentDTO(student: Student): StudentDTO {
|
||||
|
|
|
@ -13,14 +13,13 @@ import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
|||
import { getAllAssignments } from './assignments.js';
|
||||
import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from "../interfaces/question";
|
||||
|
||||
export async function getAllStudents(): Promise<StudentDTO[]> {
|
||||
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
const users = await studentRepository.findAll();
|
||||
return users.map(mapToStudentDTO);
|
||||
}
|
||||
|
||||
export async function getAllStudentIds(): Promise<string[]> {
|
||||
const users = await getAllStudents();
|
||||
if (full)
|
||||
return users.map(mapToStudentDTO);
|
||||
|
||||
return users.map((user) => user.username);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue