fix: lint proberen fixen

This commit is contained in:
Joyelle Ndagijimana 2025-05-18 13:06:25 +02:00
parent 844dce839f
commit 9af2f136eb
3 changed files with 20 additions and 21 deletions

View file

@ -1,6 +1,5 @@
import { EntityRepository, FilterQuery } from '@mikro-orm/core'; import { EntityRepository, FilterQuery } from '@mikro-orm/core';
import { EntityAlreadyExistsException } from '../exceptions/entity-already-exists-exception.js'; import { EntityAlreadyExistsException } from '../exceptions/entity-already-exists-exception.js';
import { getLogger } from '../logging/initalize.js';
export abstract class DwengoEntityRepository<T extends object> extends EntityRepository<T> { export abstract class DwengoEntityRepository<T extends object> extends EntityRepository<T> {
public async save(entity: T, options?: { preventOverwrite?: boolean }): Promise<void> { public async save(entity: T, options?: { preventOverwrite?: boolean }): Promise<void> {

View file

@ -1,4 +1,4 @@
import { AssignmentDTO, AssignmentDTOId } from '@dwengo-1/common/interfaces/assignment'; import {AssignmentDTO, AssignmentDTOId} from '@dwengo-1/common/interfaces/assignment';
import { import {
getAssignmentRepository, getAssignmentRepository,
getClassRepository, getClassRepository,
@ -6,20 +6,19 @@ import {
getQuestionRepository, getQuestionRepository,
getSubmissionRepository, getSubmissionRepository,
} from '../data/repositories.js'; } from '../data/repositories.js';
import { Assignment } from '../entities/assignments/assignment.entity.js'; import {Assignment} from '../entities/assignments/assignment.entity.js';
import { NotFoundException } from '../exceptions/not-found-exception.js'; import {NotFoundException} from '../exceptions/not-found-exception.js';
import { mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js'; import {mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId} from '../interfaces/assignment.js';
import { mapToQuestionDTO } from '../interfaces/question.js'; import {mapToQuestionDTO} from '../interfaces/question.js';
import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submission.js'; import {mapToSubmissionDTO, mapToSubmissionDTOId} from '../interfaces/submission.js';
import { fetchClass } from './classes.js'; import {fetchClass} from './classes.js';
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; import {QuestionDTO, QuestionId} from '@dwengo-1/common/interfaces/question';
import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; import {SubmissionDTO, SubmissionDTOId} from '@dwengo-1/common/interfaces/submission';
import { EntityDTO } from '@mikro-orm/core'; import {EntityDTO} from '@mikro-orm/core';
import { putObject } from './service-helper.js'; import {putObject} from './service-helper.js';
import { fetchStudents } from './students.js'; import {fetchStudents} from './students.js';
import { ServerErrorException } from '../exceptions/server-error-exception.js'; import {ServerErrorException} from '../exceptions/server-error-exception.js';
import { createGroup, deleteGroup, fetchAllGroups } from './groups.js'; import {BadRequestException} from '../exceptions/bad-request-exception.js';
import { BadRequestException } from '../exceptions/bad-request-exception.js';
export async function fetchAssignment(classid: string, assignmentNumber: number): Promise<Assignment> { export async function fetchAssignment(classid: string, assignmentNumber: number): Promise<Assignment> {
const classRepository = getClassRepository(); const classRepository = getClassRepository();
@ -45,8 +44,6 @@ export async function getAllAssignments(classid: string, full: boolean): Promise
const assignmentRepository = getAssignmentRepository(); const assignmentRepository = getAssignmentRepository();
const assignments = await assignmentRepository.findAllAssignmentsInClass(cls); const assignments = await assignmentRepository.findAllAssignmentsInClass(cls);
console.log(assignments);
if (full) { if (full) {
return assignments.map(mapToAssignmentDTO); return assignments.map(mapToAssignmentDTO);
} }
@ -63,7 +60,7 @@ export async function createAssignment(classid: string, assignmentData: Assignme
if (assignmentData.groups) { if (assignmentData.groups) {
/* /*
For some reason when trying to add groups, it does not work when using the original assignment variable. For some reason when trying to add groups, it does not work when using the original assignment variable.
The assignment needs to be refetched in order for it to work. The assignment needs to be refetched in order for it to work.
*/ */
@ -97,11 +94,14 @@ export async function getAssignment(classid: string, id: number): Promise<Assign
return mapToAssignmentDTO(assignment); return mapToAssignmentDTO(assignment);
} }
function hasDuplicates(arr: string[]): boolean {
return new Set(arr).size !== arr.length;
}
export async function putAssignment(classid: string, id: number, assignmentData: Partial<AssignmentDTO>): Promise<AssignmentDTO> { export async function putAssignment(classid: string, id: number, assignmentData: Partial<AssignmentDTO>): Promise<AssignmentDTO> {
const assignment = await fetchAssignment(classid, id); const assignment = await fetchAssignment(classid, id);
if (assignmentData.groups) { if (assignmentData.groups) {
const hasDuplicates = (arr: string[]) => new Set(arr).size !== arr.length;
if (hasDuplicates(assignmentData.groups.flat() as string[])) { if (hasDuplicates(assignmentData.groups.flat() as string[])) {
throw new BadRequestException('Student can only be in one group'); throw new BadRequestException('Student can only be in one group');
} }

View file

@ -12,7 +12,7 @@ import type { ClassesResponse } from "@/controllers/classes.ts";
import type { JoinRequestResponse, JoinRequestsResponse, StudentsResponse } from "@/controllers/students.ts"; import type { JoinRequestResponse, JoinRequestsResponse, StudentsResponse } from "@/controllers/students.ts";
import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher";
import { studentJoinRequestQueryKey, studentJoinRequestsQueryKey } from "@/queries/students.ts"; import { studentJoinRequestQueryKey, studentJoinRequestsQueryKey } from "@/queries/students.ts";
import type { AssignmentResponse, AssignmentsResponse } from "@/controllers/assignments"; import type { AssignmentsResponse } from "@/controllers/assignments";
const teacherController = new TeacherController(); const teacherController = new TeacherController();