style: fix linting issues met Prettier
This commit is contained in:
parent
df8f4043a8
commit
b9681926f8
10 changed files with 31 additions and 44 deletions
|
@ -4,7 +4,8 @@ import {
|
||||||
createStudent,
|
createStudent,
|
||||||
deleteClassJoinRequest,
|
deleteClassJoinRequest,
|
||||||
deleteStudent,
|
deleteStudent,
|
||||||
getAllStudents, getJoinRequestByStudentClass,
|
getAllStudents,
|
||||||
|
getJoinRequestByStudentClass,
|
||||||
getJoinRequestsByStudent,
|
getJoinRequestsByStudent,
|
||||||
getStudent,
|
getStudent,
|
||||||
getStudentAssignments,
|
getStudentAssignments,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { mapToUserDTO, UserDTO } from './user.js';
|
import { mapToUserDTO, UserDTO } from './user.js';
|
||||||
import {mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId} from './question.js';
|
import { mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId } from './question.js';
|
||||||
import { Answer } from '../entities/questions/answer.entity.js';
|
import { Answer } from '../entities/questions/answer.entity.js';
|
||||||
|
|
||||||
export interface AnswerDTO {
|
export interface AnswerDTO {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {
|
||||||
createStudentRequestHandler,
|
createStudentRequestHandler,
|
||||||
deleteClassJoinRequestHandler,
|
deleteClassJoinRequestHandler,
|
||||||
getStudentRequestHandler,
|
getStudentRequestHandler,
|
||||||
getStudentRequestsHandler
|
getStudentRequestsHandler,
|
||||||
} from '../controllers/students.js';
|
} from '../controllers/students.js';
|
||||||
|
|
||||||
const router = express.Router({ mergeParams: true });
|
const router = express.Router({ mergeParams: true });
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js';
|
import { getAnswerRepository, getQuestionRepository } from '../data/repositories.js';
|
||||||
import {mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId} from '../interfaces/question.js';
|
import { mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||||
import { Question } from '../entities/questions/question.entity.js';
|
import { Question } from '../entities/questions/question.entity.js';
|
||||||
import { Answer } from '../entities/questions/answer.entity.js';
|
import { Answer } from '../entities/questions/answer.entity.js';
|
||||||
import { AnswerDTO, AnswerId, mapToAnswerDTO, mapToAnswerDTOId } from '../interfaces/answer.js';
|
import { AnswerDTO, AnswerId, mapToAnswerDTO, mapToAnswerDTOId } from '../interfaces/answer.js';
|
||||||
|
|
|
@ -12,13 +12,8 @@ import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js
|
||||||
import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
||||||
import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js';
|
import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js';
|
||||||
import { getAllAssignments } from './assignments.js';
|
import { getAllAssignments } from './assignments.js';
|
||||||
import {
|
import { mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||||
mapToQuestionDTO,
|
import { mapToStudentRequest, mapToStudentRequestDTO, StudentRequestDTO } from '../interfaces/student-request.js';
|
||||||
mapToQuestionDTOId,
|
|
||||||
QuestionDTO,
|
|
||||||
QuestionId
|
|
||||||
} from '../interfaces/question.js';
|
|
||||||
import {mapToStudentRequest, mapToStudentRequestDTO, StudentRequestDTO} from '../interfaces/student-request.js';
|
|
||||||
import { Student } from '../entities/users/student.entity.js';
|
import { Student } from '../entities/users/student.entity.js';
|
||||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||||
import { fetchClass } from './classes.js';
|
import { fetchClass } from './classes.js';
|
||||||
|
@ -148,14 +143,14 @@ export async function getJoinRequestsByStudent(username: string): Promise<Studen
|
||||||
return requests.map(mapToStudentRequestDTO);
|
return requests.map(mapToStudentRequestDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getJoinRequestByStudentClass(username: string, classId: string): Promise<StudentRequestDTO>{
|
export async function getJoinRequestByStudentClass(username: string, classId: string): Promise<StudentRequestDTO> {
|
||||||
const requestRepo = getClassJoinRequestRepository();
|
const requestRepo = getClassJoinRequestRepository();
|
||||||
|
|
||||||
const student = await fetchStudent(username);
|
const student = await fetchStudent(username);
|
||||||
const cls = await fetchClass(classId);
|
const cls = await fetchClass(classId);
|
||||||
|
|
||||||
const request = await requestRepo.findByStudentAndClass(student, cls);
|
const request = await requestRepo.findByStudentAndClass(student, cls);
|
||||||
if (!request){
|
if (!request) {
|
||||||
throw new NotFoundException('Join request not found');
|
throw new NotFoundException('Join request not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,7 @@ import {
|
||||||
getTeacherRepository,
|
getTeacherRepository,
|
||||||
} from '../data/repositories.js';
|
} from '../data/repositories.js';
|
||||||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
||||||
import {
|
import { mapToQuestionDTO, mapToQuestionDTOId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||||
mapToQuestionDTO,
|
|
||||||
mapToQuestionDTOId,
|
|
||||||
QuestionDTO,
|
|
||||||
QuestionId
|
|
||||||
} from '../interfaces/question.js';
|
|
||||||
import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
|
import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
|
||||||
import { Teacher } from '../entities/users/teacher.entity.js';
|
import { Teacher } from '../entities/users/teacher.entity.js';
|
||||||
import { fetchStudent } from './students.js';
|
import { fetchStudent } from './students.js';
|
||||||
|
|
|
@ -12,7 +12,8 @@ import {
|
||||||
getStudentQuestionsHandler,
|
getStudentQuestionsHandler,
|
||||||
createStudentRequestHandler,
|
createStudentRequestHandler,
|
||||||
getStudentRequestsHandler,
|
getStudentRequestsHandler,
|
||||||
deleteClassJoinRequestHandler, getStudentRequestHandler,
|
deleteClassJoinRequestHandler,
|
||||||
|
getStudentRequestHandler,
|
||||||
} from '../../src/controllers/students.js';
|
} from '../../src/controllers/students.js';
|
||||||
import { TEST_STUDENTS } from '../test_assets/users/students.testdata.js';
|
import { TEST_STUDENTS } from '../test_assets/users/students.testdata.js';
|
||||||
import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
|
import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
|
||||||
|
@ -49,15 +50,13 @@ describe('Student controllers', () => {
|
||||||
it('Student not found', async () => {
|
it('Student not found', async () => {
|
||||||
req = { params: { username: 'doesnotexist' } };
|
req = { params: { username: 'doesnotexist' } };
|
||||||
|
|
||||||
await expect(async () => getStudentHandler(req as Request, res as Response))
|
await expect(async () => getStudentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
|
||||||
.rejects.toThrow(NotFoundException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('No username', async () => {
|
it('No username', async () => {
|
||||||
req = { params: {} };
|
req = { params: {} };
|
||||||
|
|
||||||
await expect(async () => getStudentHandler(req as Request, res as Response))
|
await expect(async () => getStudentHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
|
||||||
.rejects.toThrowError(BadRequestException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Create and delete student', async () => {
|
it('Create and delete student', async () => {
|
||||||
|
@ -68,7 +67,7 @@ describe('Student controllers', () => {
|
||||||
lastName: 'Student',
|
lastName: 'Student',
|
||||||
} as StudentDTO;
|
} as StudentDTO;
|
||||||
req = {
|
req = {
|
||||||
body: student
|
body: student,
|
||||||
};
|
};
|
||||||
|
|
||||||
await createStudentHandler(req as Request, res as Response);
|
await createStudentHandler(req as Request, res as Response);
|
||||||
|
@ -91,15 +90,13 @@ describe('Student controllers', () => {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(async () => createStudentHandler(req as Request, res as Response))
|
await expect(async () => createStudentHandler(req as Request, res as Response)).rejects.toThrowError(EntityAlreadyExistsException);
|
||||||
.rejects.toThrowError(EntityAlreadyExistsException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Create student no body', async () => {
|
it('Create student no body', async () => {
|
||||||
req = { body: {} };
|
req = { body: {} };
|
||||||
|
|
||||||
await expect(async () => createStudentHandler(req as Request, res as Response))
|
await expect(async () => createStudentHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
|
||||||
.rejects.toThrowError(BadRequestException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Student list', async () => {
|
it('Student list', async () => {
|
||||||
|
@ -218,8 +215,7 @@ describe('Student controllers', () => {
|
||||||
body: { classId: 'id02' },
|
body: { classId: 'id02' },
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(async () => createStudentRequestHandler(req as Request, res as Response))
|
await expect(async () => createStudentRequestHandler(req as Request, res as Response)).rejects.toThrow(ConflictException);
|
||||||
.rejects.toThrow(ConflictException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Delete join request', async () => {
|
it('Delete join request', async () => {
|
||||||
|
@ -231,7 +227,6 @@ describe('Student controllers', () => {
|
||||||
|
|
||||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ request: expect.anything() }));
|
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ request: expect.anything() }));
|
||||||
|
|
||||||
await expect(async () => deleteClassJoinRequestHandler(req as Request, res as Response))
|
await expect(async () => deleteClassJoinRequestHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
|
||||||
.rejects.toThrow(NotFoundException);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -45,15 +45,13 @@ describe('Teacher controllers', () => {
|
||||||
it('Teacher not found', async () => {
|
it('Teacher not found', async () => {
|
||||||
req = { params: { username: 'doesnotexist' } };
|
req = { params: { username: 'doesnotexist' } };
|
||||||
|
|
||||||
await expect(async () => getTeacherHandler(req as Request, res as Response))
|
await expect(async () => getTeacherHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
|
||||||
.rejects.toThrow(NotFoundException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('No username', async () => {
|
it('No username', async () => {
|
||||||
req = { params: {} };
|
req = { params: {} };
|
||||||
|
|
||||||
await expect(async () => getTeacherHandler(req as Request, res as Response))
|
await expect(async () => getTeacherHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
|
||||||
.rejects.toThrowError(BadRequestException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Create and delete teacher', async () => {
|
it('Create and delete teacher', async () => {
|
||||||
|
@ -62,7 +60,7 @@ describe('Teacher controllers', () => {
|
||||||
username: 'coolteacher',
|
username: 'coolteacher',
|
||||||
firstName: 'New',
|
firstName: 'New',
|
||||||
lastName: 'Teacher',
|
lastName: 'Teacher',
|
||||||
}
|
};
|
||||||
req = {
|
req = {
|
||||||
body: teacher,
|
body: teacher,
|
||||||
};
|
};
|
||||||
|
@ -87,15 +85,13 @@ describe('Teacher controllers', () => {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(async () => createTeacherHandler(req as Request, res as Response))
|
await expect(async () => createTeacherHandler(req as Request, res as Response)).rejects.toThrowError(EntityAlreadyExistsException);
|
||||||
.rejects.toThrowError(EntityAlreadyExistsException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Create teacher no body', async () => {
|
it('Create teacher no body', async () => {
|
||||||
req = { body: {} };
|
req = { body: {} };
|
||||||
|
|
||||||
await expect(async () => createTeacherHandler(req as Request, res as Response))
|
await expect(async () => createTeacherHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
|
||||||
.rejects.toThrowError(BadRequestException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Teacher list', async () => {
|
it('Teacher list', async () => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { EntityManager} from '@mikro-orm/core';
|
import { EntityManager } from '@mikro-orm/core';
|
||||||
import { Student } from '../../../src/entities/users/student.entity';
|
import { Student } from '../../../src/entities/users/student.entity';
|
||||||
|
|
||||||
// 🔓 Ruwe testdata array — herbruikbaar in assertions
|
// 🔓 Ruwe testdata array — herbruikbaar in assertions
|
||||||
|
|
|
@ -37,7 +37,12 @@ export class TeacherController extends BaseController {
|
||||||
return this.get<{ joinRequests: any[] }>(`/${username}/joinRequests/${classId}`);
|
return this.get<{ joinRequests: any[] }>(`/${username}/joinRequests/${classId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateStudentJoinRequest(teacherUsername: string, classId: string, studentUsername: string, accepted: boolean) {
|
async updateStudentJoinRequest(
|
||||||
|
teacherUsername: string,
|
||||||
|
classId: string,
|
||||||
|
studentUsername: string,
|
||||||
|
accepted: boolean,
|
||||||
|
) {
|
||||||
return this.put(`/${teacherUsername}/joinRequests/${classId}/${studentUsername}`, accepted);
|
return this.put(`/${teacherUsername}/joinRequests/${classId}/${studentUsername}`, accepted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue