style: fix linting issues met Prettier

This commit is contained in:
Lint Action 2025-03-30 21:24:37 +00:00
parent 9895d22521
commit ee5f69cbc8
20 changed files with 188 additions and 192 deletions

View file

@ -1,4 +1,4 @@
import {BadRequestException} from "../exceptions/bad-request-exception";
import { BadRequestException } from '../exceptions/bad-request-exception';
/**
* Checks for the presence of required fields and throws a BadRequestException

View file

@ -1,17 +1,20 @@
import { Request, Response } from 'express';
import {
createClassJoinRequest,
createStudent, deleteClassJoinRequest,
createStudent,
deleteClassJoinRequest,
deleteStudent,
getAllStudents, getJoinRequestsByStudent,
getAllStudents,
getJoinRequestsByStudent,
getStudent,
getStudentAssignments,
getStudentClasses,
getStudentGroups, getStudentQuestions,
getStudentGroups,
getStudentQuestions,
getStudentSubmissions,
} from '../services/students.js';
import { StudentDTO } from '../interfaces/student.js';
import {requireFields} from "./error-helper.js";
import { requireFields } from './error-helper.js';
export async function getAllStudentsHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';
@ -128,7 +131,7 @@ export async function getStudentRequestHandler(req: Request, res: Response): Pro
requireFields({ username });
const requests = await getJoinRequestsByStudent(username);
res.status(201).json({ requests })
res.status(201).json({ requests });
}
export async function deleteClassJoinRequestHandler(req: Request, res: Response) {
@ -139,5 +142,3 @@ export async function deleteClassJoinRequestHandler(req: Request, res: Response)
await deleteClassJoinRequest(username, classId);
res.sendStatus(204);
}

View file

@ -3,16 +3,18 @@ import {
createTeacher,
deleteTeacher,
getAllTeachers,
getClassesByTeacher, getJoinRequestsByClass,
getClassesByTeacher,
getJoinRequestsByClass,
getStudentsByTeacher,
getTeacher,
getTeacherQuestions, updateClassJoinRequestStatus
getTeacherQuestions,
updateClassJoinRequestStatus,
} from '../services/teachers.js';
import { ClassDTO } from '../interfaces/class.js';
import { StudentDTO } from '../interfaces/student.js';
import { QuestionDTO, QuestionId } from '../interfaces/question.js';
import { TeacherDTO } from '../interfaces/teacher.js';
import {requireFields} from "./error-helper.js";
import { requireFields } from './error-helper.js';
export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';

View file

@ -1,6 +1,6 @@
import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
import { Class } from '../../entities/classes/class.entity.js';
import {ClassJoinRequest, ClassJoinRequestStatus} from '../../entities/classes/class-join-request.entity.js';
import { ClassJoinRequest, ClassJoinRequestStatus } from '../../entities/classes/class-join-request.entity.js';
import { Student } from '../../entities/users/student.entity.js';
export class ClassJoinRequestRepository extends DwengoEntityRepository<ClassJoinRequest> {
@ -8,7 +8,7 @@ export class ClassJoinRequestRepository extends DwengoEntityRepository<ClassJoin
return this.findAll({ where: { requester: requester } });
}
public findAllOpenRequestsTo(clazz: Class): Promise<ClassJoinRequest[]> {
return this.findAll({ where: { class: clazz, status: ClassJoinRequestStatus.Open, } }); // TODO check if works like this
return this.findAll({ where: { class: clazz, status: ClassJoinRequestStatus.Open } }); // TODO check if works like this
}
public findByStudentAndClass(requester: Student, clazz: Class): Promise<ClassJoinRequest | null> {
return this.findOne({ requester, class: clazz });

View file

@ -1,13 +1,13 @@
import {mapToStudentDTO, StudentDTO} from "./student";
import {ClassJoinRequest, ClassJoinRequestStatus} from "../entities/classes/class-join-request.entity";
import {getClassJoinRequestRepository} from "../data/repositories";
import {Student} from "../entities/users/student.entity";
import {Class} from "../entities/classes/class.entity";
import { mapToStudentDTO, StudentDTO } from './student';
import { ClassJoinRequest, ClassJoinRequestStatus } from '../entities/classes/class-join-request.entity';
import { getClassJoinRequestRepository } from '../data/repositories';
import { Student } from '../entities/users/student.entity';
import { Class } from '../entities/classes/class.entity';
export interface StudentRequestDTO {
requester: StudentDTO;
class: string;
status: ClassJoinRequestStatus
status: ClassJoinRequestStatus;
}
export function mapToStudentRequestDTO(request: ClassJoinRequest): StudentRequestDTO {

View file

@ -1,8 +1,5 @@
import express from "express";
import {
createStudentRequestHandler, deleteClassJoinRequestHandler,
getStudentRequestHandler,
} from "../controllers/students";
import express from 'express';
import { createStudentRequestHandler, deleteClassJoinRequestHandler, getStudentRequestHandler } from '../controllers/students';
const router = express.Router({ mergeParams: true });

View file

@ -10,7 +10,7 @@ import {
getStudentQuestionsHandler,
getStudentSubmissionsHandler,
} from '../controllers/students.js';
import joinRequestRouter from './student-join-requests.js'
import joinRequestRouter from './student-join-requests.js';
const router = express.Router();
@ -39,6 +39,6 @@ router.get('/:username/groups', getStudentGroupsHandler);
// A list of questions a user has created
router.get('/:username/questions', getStudentQuestionsHandler);
router.use('/:username/joinRequests', joinRequestRouter)
router.use('/:username/joinRequests', joinRequestRouter);
export default router;

View file

@ -2,11 +2,13 @@ import express from 'express';
import {
createTeacherHandler,
deleteTeacherHandler,
getAllTeachersHandler, getStudentJoinRequestHandler,
getAllTeachersHandler,
getStudentJoinRequestHandler,
getTeacherClassHandler,
getTeacherHandler,
getTeacherQuestionHandler,
getTeacherStudentHandler, updateStudentJoinRequestHandler,
getTeacherStudentHandler,
updateStudentJoinRequestHandler,
} from '../controllers/teachers.js';
const router = express.Router();

View file

@ -3,8 +3,8 @@ import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
import { mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
import { mapToTeacherInvitationDTO, mapToTeacherInvitationDTOIds, TeacherInvitationDTO } from '../interfaces/teacher-invitation.js';
import { getLogger } from '../logging/initalize.js';
import {NotFoundException} from "../exceptions/not-found-exception";
import {Class} from "../entities/classes/class.entity";
import { NotFoundException } from '../exceptions/not-found-exception';
import { Class } from '../entities/classes/class.entity';
const logger = getLogger();
@ -13,7 +13,7 @@ export async function fetchClass(classId: string): Promise<Class> {
const cls = await classRepository.findById(classId);
if (!cls) {
throw new NotFoundException("Class with id not found");
throw new NotFoundException('Class with id not found');
}
return cls;

View file

@ -4,7 +4,7 @@ import {
getGroupRepository,
getQuestionRepository,
getStudentRepository,
getSubmissionRepository
getSubmissionRepository,
} from '../data/repositories.js';
import { AssignmentDTO } from '../interfaces/assignment.js';
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
@ -13,17 +13,18 @@ import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student
import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js';
import { getAllAssignments } from './assignments.js';
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
import {mapToStudentRequest, mapToStudentRequestDTO} from "../interfaces/student-request.js";
import {Student} from "../entities/users/student.entity.js";
import {NotFoundException} from "../exceptions/not-found-exception.js";
import {fetchClass} from "./classes.js";
import { mapToStudentRequest, mapToStudentRequestDTO } from '../interfaces/student-request.js';
import { Student } from '../entities/users/student.entity.js';
import { NotFoundException } from '../exceptions/not-found-exception.js';
import { fetchClass } from './classes.js';
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
const studentRepository = getStudentRepository();
const users = await studentRepository.findAll();
if (full)
{return users.map(mapToStudentDTO);}
if (full) {
return users.map(mapToStudentDTO);
}
return users.map((user) => user.username);
}
@ -33,7 +34,7 @@ export async function fetchStudent(username: string): Promise<Student> {
const user = await studentRepository.findByUsername(username);
if (!user) {
throw new NotFoundException("Student with username not found");
throw new NotFoundException('Student with username not found');
}
return user;
@ -115,8 +116,9 @@ export async function getStudentQuestions(username: string, full: boolean): Prom
const questionsDTO = questions.map(mapToQuestionDTO);
if (full)
{return questionsDTO;}
if (full) {
return questionsDTO;
}
return questionsDTO.map(mapToQuestionId);
}
@ -146,7 +148,6 @@ export async function deleteClassJoinRequest(studentUsername: string, classId: s
const student = await fetchStudent(studentUsername);
const cls = await fetchClass(classId);
const request = await requestRepo.findByStudentAndClass(student, cls);
if (!request) {

View file

@ -6,24 +6,24 @@ import {
getTeacherRepository,
} from '../data/repositories.js';
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
import {mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId} from '../interfaces/question.js';
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
import {Teacher} from "../entities/users/teacher.entity.js";
import {fetchStudent} from "./students.js";
import {ClassJoinRequest, ClassJoinRequestStatus} from "../entities/classes/class-join-request.entity.js";
import {mapToStudentRequestDTO, StudentRequestDTO} from "../interfaces/student-request.js";
import {TeacherRepository} from "../data/users/teacher-repository.js";
import {ClassRepository} from "../data/classes/class-repository.js";
import {Class} from "../entities/classes/class.entity.js";
import {StudentDTO} from "../interfaces/student.js";
import {LearningObjectRepository} from "../data/content/learning-object-repository.js";
import {LearningObject} from "../entities/content/learning-object.entity.js";
import {QuestionRepository} from "../data/questions/question-repository.js";
import {Question} from "../entities/questions/question.entity.js";
import {ClassJoinRequestRepository} from "../data/classes/class-join-request-repository.js";
import {Student} from "../entities/users/student.entity.js";
import {NotFoundException} from "../exceptions/not-found-exception.js";
import {getClassStudents} from "./classes.js";
import { Teacher } from '../entities/users/teacher.entity.js';
import { fetchStudent } from './students.js';
import { ClassJoinRequest, ClassJoinRequestStatus } from '../entities/classes/class-join-request.entity.js';
import { mapToStudentRequestDTO, StudentRequestDTO } from '../interfaces/student-request.js';
import { TeacherRepository } from '../data/users/teacher-repository.js';
import { ClassRepository } from '../data/classes/class-repository.js';
import { Class } from '../entities/classes/class.entity.js';
import { StudentDTO } from '../interfaces/student.js';
import { LearningObjectRepository } from '../data/content/learning-object-repository.js';
import { LearningObject } from '../entities/content/learning-object.entity.js';
import { QuestionRepository } from '../data/questions/question-repository.js';
import { Question } from '../entities/questions/question.entity.js';
import { ClassJoinRequestRepository } from '../data/classes/class-join-request-repository.js';
import { Student } from '../entities/users/student.entity.js';
import { NotFoundException } from '../exceptions/not-found-exception.js';
import { getClassStudents } from './classes.js';
export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> {
const teacherRepository: TeacherRepository = getTeacherRepository();
@ -40,7 +40,7 @@ export async function fetchTeacher(username: string): Promise<Teacher> {
const user: Teacher | null = await teacherRepository.findByUsername(username);
if (!user) {
throw new NotFoundException("Teacher with username not found");
throw new NotFoundException('Teacher with username not found');
}
return user;
@ -86,7 +86,7 @@ export async function getClassesByTeacher(username: string, full: boolean): Prom
export async function getStudentsByTeacher(username: string, full: boolean) {
const classes: ClassDTO[] = await fetchClassesByTeacher(username);
if (!classes || classes.length === 0){
if (!classes || classes.length === 0) {
return [];
}
@ -109,7 +109,7 @@ export async function getTeacherQuestions(username: string, full: boolean): Prom
// Console.log(learningObjects)
// TODO returns empty
if (!learningObjects || learningObjects.length === 0){
if (!learningObjects || learningObjects.length === 0) {
return [];
}
@ -125,12 +125,12 @@ export async function getTeacherQuestions(username: string, full: boolean): Prom
return questionsDTO.map(mapToQuestionId);
}
export async function getJoinRequestsByClass( classId: string ): Promise<StudentRequestDTO[]> {
export async function getJoinRequestsByClass(classId: string): Promise<StudentRequestDTO[]> {
const classRepository: ClassRepository = getClassRepository();
const cls: Class | null = await classRepository.findById(classId);
if (!cls) {
throw new NotFoundException("Class with id not found");
throw new NotFoundException('Class with id not found');
}
const requestRepo: ClassJoinRequestRepository = getClassJoinRequestRepository();
@ -138,7 +138,7 @@ export async function getJoinRequestsByClass( classId: string ): Promise<Student
return requests.map(mapToStudentRequestDTO);
}
export async function updateClassJoinRequestStatus( studentUsername: string, classId: string, accepted: boolean = true): Promise<void> {
export async function updateClassJoinRequestStatus(studentUsername: string, classId: string, accepted: boolean = true): Promise<void> {
const requestRepo: ClassJoinRequestRepository = getClassJoinRequestRepository();
const classRepo: ClassRepository = getClassRepository();

View file

@ -12,14 +12,14 @@ import {
getStudentQuestionsHandler,
createStudentRequestHandler,
getStudentRequestHandler,
deleteClassJoinRequestHandler
deleteClassJoinRequestHandler,
} from '../../src/controllers/students.js';
import {TEST_STUDENTS} from "../test_assets/users/students.testdata.js";
import {NotFoundException} from "../../src/exceptions/not-found-exception.js";
import {BadRequestException} from "../../src/exceptions/bad-request-exception.js";
import {ConflictException} from "../../src/exceptions/conflict-exception.js";
import {EntityAlreadyExistsException} from "../../src/exceptions/entity-already-exists-exception.js";
import {StudentDTO} from "../../src/interfaces/student.js";
import { TEST_STUDENTS } from '../test_assets/users/students.testdata.js';
import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
import { BadRequestException } from '../../src/exceptions/bad-request-exception.js';
import { ConflictException } from '../../src/exceptions/conflict-exception.js';
import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js';
import { StudentDTO } from '../../src/interfaces/student.js';
describe('Student controllers', () => {
let req: Partial<Request>;
@ -45,7 +45,7 @@ describe('Student controllers', () => {
});
it('Get student', async () => {
req = { params: { username: 'DireStraits' }};
req = { params: { username: 'DireStraits' } };
await getStudentHandler(req as Request, res as Response);
@ -55,17 +55,13 @@ describe('Student controllers', () => {
it('Student not found', async () => {
req = { params: { username: 'doesnotexist' } };
await expect(() => getStudentHandler(req as Request, res as Response))
.rejects
.toThrow(NotFoundException);
await expect(() => getStudentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('No username', async () => {
req = { params: {} };
await expect(() => getStudentHandler(req as Request, res as Response))
.rejects
.toThrowError(BadRequestException);
await expect(() => getStudentHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
});
it('Create and delete student', async () => {
@ -73,8 +69,8 @@ describe('Student controllers', () => {
body: {
username: 'coolstudent',
firstName: 'New',
lastName: 'Student'
}
lastName: 'Student',
},
};
await createStudentHandler(req as Request, res as Response);
@ -88,27 +84,22 @@ describe('Student controllers', () => {
expect(sendStatusMock).toHaveBeenCalledWith(200);
});
it('Create duplicate student', async () => {
req = {
body: {
username: 'DireStraits',
firstName: 'dupe',
lastName: 'dupe'
}
lastName: 'dupe',
},
};
await expect(() => createStudentHandler(req as Request, res as Response))
.rejects
.toThrowError(EntityAlreadyExistsException);
await expect(() => createStudentHandler(req as Request, res as Response)).rejects.toThrowError(EntityAlreadyExistsException);
});
it('Create student no body', async () => {
req = { body: {} };
await expect(() => createStudentHandler(req as Request, res as Response))
.rejects
.toThrowError(BadRequestException);
await expect(() => createStudentHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
});
it('Student list', async () => {
@ -133,7 +124,6 @@ describe('Student controllers', () => {
await getStudentClassesHandler(req as Request, res as Response);
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ classes: expect.anything() }));
const result = jsonMock.mock.lastCall?.[0];
@ -176,9 +166,7 @@ describe('Student controllers', () => {
it('Deleting non-existent student', async () => {
req = { params: { username: 'doesnotexist' } };
await expect(() => deleteStudentHandler(req as Request, res as Response))
.rejects
.toThrow(NotFoundException);
await expect(() => deleteStudentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('Get join requests by student', async () => {
@ -203,7 +191,7 @@ describe('Student controllers', () => {
it('Create join request', async () => {
req = {
params: { username: 'Noordkaap' },
body: { classId: 'id02' }
body: { classId: 'id02' },
};
await createStudentRequestHandler(req as Request, res as Response);
@ -214,15 +202,12 @@ describe('Student controllers', () => {
it('Create join request duplicate', async () => {
req = {
params: { username: 'Tool' },
body: { classId: 'id02' }
body: { classId: 'id02' },
};
await expect(() => createStudentRequestHandler(req as Request, res as Response))
.rejects
.toThrow(ConflictException);
await expect(() => createStudentRequestHandler(req as Request, res as Response)).rejects.toThrow(ConflictException);
});
it('Delete join request', async () => {
req = {
params: { username: 'Noordkaap', classId: 'id02' },
@ -232,9 +217,6 @@ describe('Student controllers', () => {
expect(sendStatusMock).toHaveBeenCalledWith(204);
await expect(() => deleteClassJoinRequestHandler(req as Request, res as Response))
.rejects
.toThrow(NotFoundException);
await expect(() => deleteClassJoinRequestHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
});

View file

@ -1,17 +1,22 @@
import {beforeAll, beforeEach, describe, expect, it, Mock, vi} from "vitest";
import {Request, Response} from "express";
import {setupTestApp} from "../setup-tests.js";
import {NotFoundException} from "../../src/exceptions/not-found-exception.js";
import { beforeAll, beforeEach, describe, expect, it, Mock, vi } from 'vitest';
import { Request, Response } from 'express';
import { setupTestApp } from '../setup-tests.js';
import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
import {
createTeacherHandler,
deleteTeacherHandler,
getAllTeachersHandler, getStudentJoinRequestHandler, getTeacherClassHandler,
getTeacherHandler, getTeacherQuestionHandler, getTeacherStudentHandler, updateStudentJoinRequestHandler
} from "../../src/controllers/teachers.js";
import {BadRequestException} from "../../src/exceptions/bad-request-exception.js";
import {EntityAlreadyExistsException} from "../../src/exceptions/entity-already-exists-exception.js";
import {getStudentRequestHandler} from "../../src/controllers/students.js";
import {TeacherDTO} from "../../src/interfaces/teacher.js";
getAllTeachersHandler,
getStudentJoinRequestHandler,
getTeacherClassHandler,
getTeacherHandler,
getTeacherQuestionHandler,
getTeacherStudentHandler,
updateStudentJoinRequestHandler,
} from '../../src/controllers/teachers.js';
import { BadRequestException } from '../../src/exceptions/bad-request-exception.js';
import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js';
import { getStudentRequestHandler } from '../../src/controllers/students.js';
import { TeacherDTO } from '../../src/interfaces/teacher.js';
describe('Teacher controllers', () => {
let req: Partial<Request>;
@ -37,7 +42,7 @@ describe('Teacher controllers', () => {
});
it('Get teacher', async () => {
req = { params: { username: 'FooFighters' }};
req = { params: { username: 'FooFighters' } };
await getTeacherHandler(req as Request, res as Response);
@ -45,19 +50,15 @@ describe('Teacher controllers', () => {
});
it('Teacher not found', async () => {
req = {params: {username: 'doesnotexist'}};
req = { params: { username: 'doesnotexist' } };
await expect(() => getTeacherHandler(req as Request, res as Response))
.rejects
.toThrow(NotFoundException);
await expect(() => getTeacherHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('No username', async () => {
req = { params: {} };
await expect(() => getTeacherHandler(req as Request, res as Response))
.rejects
.toThrowError(BadRequestException);
await expect(() => getTeacherHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
});
it('Create and delete teacher', async () => {
@ -65,8 +66,8 @@ describe('Teacher controllers', () => {
body: {
username: 'coolteacher',
firstName: 'New',
lastName: 'Teacher'
}
lastName: 'Teacher',
},
};
await createTeacherHandler(req as Request, res as Response);
@ -86,20 +87,16 @@ describe('Teacher controllers', () => {
username: 'FooFighters',
firstName: 'Dave',
lastName: 'Grohl',
}
},
};
await expect(() => createTeacherHandler(req as Request, res as Response))
.rejects
.toThrowError(EntityAlreadyExistsException);
await expect(() => createTeacherHandler(req as Request, res as Response)).rejects.toThrowError(EntityAlreadyExistsException);
});
it('Create teacher no body', async () => {
req = { body: {} };
await expect(() => createTeacherHandler(req as Request, res as Response))
.rejects
.toThrowError(BadRequestException);
await expect(() => createTeacherHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
});
it('Teacher list', async () => {
@ -120,12 +117,9 @@ describe('Teacher controllers', () => {
it('Deleting non-existent student', async () => {
req = { params: { username: 'doesnotexist' } };
await expect(() => deleteTeacherHandler(req as Request, res as Response))
.rejects
.toThrow(NotFoundException);
await expect(() => deleteTeacherHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
});
it('Get teacher classes', async () => {
req = {
params: { username: 'FooFighters' },
@ -196,7 +190,7 @@ describe('Teacher controllers', () => {
req = {
query: { username: 'LimpBizkit', studentUsername: 'PinkFloyd' },
params: { classId: 'id02' },
body: { accepted: 'true' }
body: { accepted: 'true' },
};
await updateStudentJoinRequestHandler(req as Request, res as Response);
@ -209,11 +203,7 @@ describe('Teacher controllers', () => {
await getStudentRequestHandler(req as Request, res as Response);
const status: boolean = jsonMock.mock.lastCall?.[0].requests[0].status
const status: boolean = jsonMock.mock.lastCall?.[0].requests[0].status;
expect(status).toBeTruthy;
});
});

View file

@ -15,6 +15,5 @@ export const TEST_STUDENTS = [
// 🏗️ Functie die ORM entities maakt uit de data array
export function makeTestStudents(em: EntityManager<IDatabaseDriver<Connection>>): Student[] {
return TEST_STUDENTS.map(data => em.create(Student, data));
return TEST_STUDENTS.map((data) => em.create(Student, data));
}