style: fix linting issues met Prettier
This commit is contained in:
parent
9895d22521
commit
ee5f69cbc8
20 changed files with 188 additions and 192 deletions
|
@ -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
|
* Checks for the presence of required fields and throws a BadRequestException
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import {
|
import {
|
||||||
createClassJoinRequest,
|
createClassJoinRequest,
|
||||||
createStudent, deleteClassJoinRequest,
|
createStudent,
|
||||||
|
deleteClassJoinRequest,
|
||||||
deleteStudent,
|
deleteStudent,
|
||||||
getAllStudents, getJoinRequestsByStudent,
|
getAllStudents,
|
||||||
|
getJoinRequestsByStudent,
|
||||||
getStudent,
|
getStudent,
|
||||||
getStudentAssignments,
|
getStudentAssignments,
|
||||||
getStudentClasses,
|
getStudentClasses,
|
||||||
getStudentGroups, getStudentQuestions,
|
getStudentGroups,
|
||||||
|
getStudentQuestions,
|
||||||
getStudentSubmissions,
|
getStudentSubmissions,
|
||||||
} from '../services/students.js';
|
} from '../services/students.js';
|
||||||
import { StudentDTO } from '../interfaces/student.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> {
|
export async function getAllStudentsHandler(req: Request, res: Response): Promise<void> {
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
@ -128,7 +131,7 @@ export async function getStudentRequestHandler(req: Request, res: Response): Pro
|
||||||
requireFields({ username });
|
requireFields({ username });
|
||||||
|
|
||||||
const requests = await getJoinRequestsByStudent(username);
|
const requests = await getJoinRequestsByStudent(username);
|
||||||
res.status(201).json({ requests })
|
res.status(201).json({ requests });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteClassJoinRequestHandler(req: Request, res: Response) {
|
export async function deleteClassJoinRequestHandler(req: Request, res: Response) {
|
||||||
|
@ -139,5 +142,3 @@ export async function deleteClassJoinRequestHandler(req: Request, res: Response)
|
||||||
await deleteClassJoinRequest(username, classId);
|
await deleteClassJoinRequest(username, classId);
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,16 +3,18 @@ import {
|
||||||
createTeacher,
|
createTeacher,
|
||||||
deleteTeacher,
|
deleteTeacher,
|
||||||
getAllTeachers,
|
getAllTeachers,
|
||||||
getClassesByTeacher, getJoinRequestsByClass,
|
getClassesByTeacher,
|
||||||
|
getJoinRequestsByClass,
|
||||||
getStudentsByTeacher,
|
getStudentsByTeacher,
|
||||||
getTeacher,
|
getTeacher,
|
||||||
getTeacherQuestions, updateClassJoinRequestStatus
|
getTeacherQuestions,
|
||||||
|
updateClassJoinRequestStatus,
|
||||||
} from '../services/teachers.js';
|
} from '../services/teachers.js';
|
||||||
import { ClassDTO } from '../interfaces/class.js';
|
import { ClassDTO } from '../interfaces/class.js';
|
||||||
import { StudentDTO } from '../interfaces/student.js';
|
import { StudentDTO } from '../interfaces/student.js';
|
||||||
import { QuestionDTO, QuestionId } from '../interfaces/question.js';
|
import { QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||||
import { TeacherDTO } from '../interfaces/teacher.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> {
|
export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> {
|
||||||
const full = req.query.full === 'true';
|
const full = req.query.full === 'true';
|
||||||
|
|
|
@ -8,7 +8,7 @@ export class ClassJoinRequestRepository extends DwengoEntityRepository<ClassJoin
|
||||||
return this.findAll({ where: { requester: requester } });
|
return this.findAll({ where: { requester: requester } });
|
||||||
}
|
}
|
||||||
public findAllOpenRequestsTo(clazz: Class): Promise<ClassJoinRequest[]> {
|
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> {
|
public findByStudentAndClass(requester: Student, clazz: Class): Promise<ClassJoinRequest | null> {
|
||||||
return this.findOne({ requester, class: clazz });
|
return this.findOne({ requester, class: clazz });
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import {mapToStudentDTO, StudentDTO} from "./student";
|
import { mapToStudentDTO, StudentDTO } from './student';
|
||||||
import {ClassJoinRequest, ClassJoinRequestStatus} from "../entities/classes/class-join-request.entity";
|
import { ClassJoinRequest, ClassJoinRequestStatus } from '../entities/classes/class-join-request.entity';
|
||||||
import {getClassJoinRequestRepository} from "../data/repositories";
|
import { getClassJoinRequestRepository } from '../data/repositories';
|
||||||
import {Student} from "../entities/users/student.entity";
|
import { Student } from '../entities/users/student.entity';
|
||||||
import {Class} from "../entities/classes/class.entity";
|
import { Class } from '../entities/classes/class.entity';
|
||||||
|
|
||||||
export interface StudentRequestDTO {
|
export interface StudentRequestDTO {
|
||||||
requester: StudentDTO;
|
requester: StudentDTO;
|
||||||
class: string;
|
class: string;
|
||||||
status: ClassJoinRequestStatus
|
status: ClassJoinRequestStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapToStudentRequestDTO(request: ClassJoinRequest): StudentRequestDTO {
|
export function mapToStudentRequestDTO(request: ClassJoinRequest): StudentRequestDTO {
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
import express from "express";
|
import express from 'express';
|
||||||
import {
|
import { createStudentRequestHandler, deleteClassJoinRequestHandler, getStudentRequestHandler } from '../controllers/students';
|
||||||
createStudentRequestHandler, deleteClassJoinRequestHandler,
|
|
||||||
getStudentRequestHandler,
|
|
||||||
} from "../controllers/students";
|
|
||||||
|
|
||||||
const router = express.Router({ mergeParams: true });
|
const router = express.Router({ mergeParams: true });
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
getStudentQuestionsHandler,
|
getStudentQuestionsHandler,
|
||||||
getStudentSubmissionsHandler,
|
getStudentSubmissionsHandler,
|
||||||
} from '../controllers/students.js';
|
} from '../controllers/students.js';
|
||||||
import joinRequestRouter from './student-join-requests.js'
|
import joinRequestRouter from './student-join-requests.js';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
@ -39,6 +39,6 @@ router.get('/:username/groups', getStudentGroupsHandler);
|
||||||
// A list of questions a user has created
|
// A list of questions a user has created
|
||||||
router.get('/:username/questions', getStudentQuestionsHandler);
|
router.get('/:username/questions', getStudentQuestionsHandler);
|
||||||
|
|
||||||
router.use('/:username/joinRequests', joinRequestRouter)
|
router.use('/:username/joinRequests', joinRequestRouter);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
@ -2,11 +2,13 @@ import express from 'express';
|
||||||
import {
|
import {
|
||||||
createTeacherHandler,
|
createTeacherHandler,
|
||||||
deleteTeacherHandler,
|
deleteTeacherHandler,
|
||||||
getAllTeachersHandler, getStudentJoinRequestHandler,
|
getAllTeachersHandler,
|
||||||
|
getStudentJoinRequestHandler,
|
||||||
getTeacherClassHandler,
|
getTeacherClassHandler,
|
||||||
getTeacherHandler,
|
getTeacherHandler,
|
||||||
getTeacherQuestionHandler,
|
getTeacherQuestionHandler,
|
||||||
getTeacherStudentHandler, updateStudentJoinRequestHandler,
|
getTeacherStudentHandler,
|
||||||
|
updateStudentJoinRequestHandler,
|
||||||
} from '../controllers/teachers.js';
|
} from '../controllers/teachers.js';
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
||||||
import { mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
import { mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
||||||
import { mapToTeacherInvitationDTO, mapToTeacherInvitationDTOIds, TeacherInvitationDTO } from '../interfaces/teacher-invitation.js';
|
import { mapToTeacherInvitationDTO, mapToTeacherInvitationDTOIds, TeacherInvitationDTO } from '../interfaces/teacher-invitation.js';
|
||||||
import { getLogger } from '../logging/initalize.js';
|
import { getLogger } from '../logging/initalize.js';
|
||||||
import {NotFoundException} from "../exceptions/not-found-exception";
|
import { NotFoundException } from '../exceptions/not-found-exception';
|
||||||
import {Class} from "../entities/classes/class.entity";
|
import { Class } from '../entities/classes/class.entity';
|
||||||
|
|
||||||
const logger = getLogger();
|
const logger = getLogger();
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ export async function fetchClass(classId: string): Promise<Class> {
|
||||||
const cls = await classRepository.findById(classId);
|
const cls = await classRepository.findById(classId);
|
||||||
|
|
||||||
if (!cls) {
|
if (!cls) {
|
||||||
throw new NotFoundException("Class with id not found");
|
throw new NotFoundException('Class with id not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return cls;
|
return cls;
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
getGroupRepository,
|
getGroupRepository,
|
||||||
getQuestionRepository,
|
getQuestionRepository,
|
||||||
getStudentRepository,
|
getStudentRepository,
|
||||||
getSubmissionRepository
|
getSubmissionRepository,
|
||||||
} from '../data/repositories.js';
|
} from '../data/repositories.js';
|
||||||
import { AssignmentDTO } from '../interfaces/assignment.js';
|
import { AssignmentDTO } from '../interfaces/assignment.js';
|
||||||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.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 { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js';
|
||||||
import { getAllAssignments } from './assignments.js';
|
import { getAllAssignments } from './assignments.js';
|
||||||
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||||
import {mapToStudentRequest, mapToStudentRequestDTO} from "../interfaces/student-request.js";
|
import { mapToStudentRequest, mapToStudentRequestDTO } 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';
|
||||||
|
|
||||||
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
|
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
|
||||||
const studentRepository = getStudentRepository();
|
const studentRepository = getStudentRepository();
|
||||||
const users = await studentRepository.findAll();
|
const users = await studentRepository.findAll();
|
||||||
|
|
||||||
if (full)
|
if (full) {
|
||||||
{return users.map(mapToStudentDTO);}
|
return users.map(mapToStudentDTO);
|
||||||
|
}
|
||||||
|
|
||||||
return users.map((user) => user.username);
|
return users.map((user) => user.username);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +34,7 @@ export async function fetchStudent(username: string): Promise<Student> {
|
||||||
const user = await studentRepository.findByUsername(username);
|
const user = await studentRepository.findByUsername(username);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new NotFoundException("Student with username not found");
|
throw new NotFoundException('Student with username not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
@ -115,8 +116,9 @@ export async function getStudentQuestions(username: string, full: boolean): Prom
|
||||||
|
|
||||||
const questionsDTO = questions.map(mapToQuestionDTO);
|
const questionsDTO = questions.map(mapToQuestionDTO);
|
||||||
|
|
||||||
if (full)
|
if (full) {
|
||||||
{return questionsDTO;}
|
return questionsDTO;
|
||||||
|
}
|
||||||
|
|
||||||
return questionsDTO.map(mapToQuestionId);
|
return questionsDTO.map(mapToQuestionId);
|
||||||
}
|
}
|
||||||
|
@ -146,7 +148,6 @@ export async function deleteClassJoinRequest(studentUsername: string, classId: s
|
||||||
const student = await fetchStudent(studentUsername);
|
const student = await fetchStudent(studentUsername);
|
||||||
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) {
|
||||||
|
|
|
@ -8,22 +8,22 @@ import {
|
||||||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.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 { 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';
|
||||||
import {ClassJoinRequest, ClassJoinRequestStatus} from "../entities/classes/class-join-request.entity.js";
|
import { ClassJoinRequest, ClassJoinRequestStatus } from '../entities/classes/class-join-request.entity.js';
|
||||||
import {mapToStudentRequestDTO, StudentRequestDTO} from "../interfaces/student-request.js";
|
import { mapToStudentRequestDTO, StudentRequestDTO } from '../interfaces/student-request.js';
|
||||||
import {TeacherRepository} from "../data/users/teacher-repository.js";
|
import { TeacherRepository } from '../data/users/teacher-repository.js';
|
||||||
import {ClassRepository} from "../data/classes/class-repository.js";
|
import { ClassRepository } from '../data/classes/class-repository.js';
|
||||||
import {Class} from "../entities/classes/class.entity.js";
|
import { Class } from '../entities/classes/class.entity.js';
|
||||||
import {StudentDTO} from "../interfaces/student.js";
|
import { StudentDTO } from '../interfaces/student.js';
|
||||||
import {LearningObjectRepository} from "../data/content/learning-object-repository.js";
|
import { LearningObjectRepository } from '../data/content/learning-object-repository.js';
|
||||||
import {LearningObject} from "../entities/content/learning-object.entity.js";
|
import { LearningObject } from '../entities/content/learning-object.entity.js';
|
||||||
import {QuestionRepository} from "../data/questions/question-repository.js";
|
import { QuestionRepository } from '../data/questions/question-repository.js';
|
||||||
import {Question} from "../entities/questions/question.entity.js";
|
import { Question } from '../entities/questions/question.entity.js';
|
||||||
import {ClassJoinRequestRepository} from "../data/classes/class-join-request-repository.js";
|
import { ClassJoinRequestRepository } from '../data/classes/class-join-request-repository.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 {getClassStudents} from "./classes.js";
|
import { getClassStudents } from './classes.js';
|
||||||
|
|
||||||
export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> {
|
export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> {
|
||||||
const teacherRepository: TeacherRepository = getTeacherRepository();
|
const teacherRepository: TeacherRepository = getTeacherRepository();
|
||||||
|
@ -40,7 +40,7 @@ export async function fetchTeacher(username: string): Promise<Teacher> {
|
||||||
const user: Teacher | null = await teacherRepository.findByUsername(username);
|
const user: Teacher | null = await teacherRepository.findByUsername(username);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new NotFoundException("Teacher with username not found");
|
throw new NotFoundException('Teacher with username not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
@ -130,7 +130,7 @@ export async function getJoinRequestsByClass( classId: string ): Promise<Student
|
||||||
const cls: Class | null = await classRepository.findById(classId);
|
const cls: Class | null = await classRepository.findById(classId);
|
||||||
|
|
||||||
if (!cls) {
|
if (!cls) {
|
||||||
throw new NotFoundException("Class with id not found");
|
throw new NotFoundException('Class with id not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestRepo: ClassJoinRequestRepository = getClassJoinRequestRepository();
|
const requestRepo: ClassJoinRequestRepository = getClassJoinRequestRepository();
|
||||||
|
|
|
@ -12,14 +12,14 @@ import {
|
||||||
getStudentQuestionsHandler,
|
getStudentQuestionsHandler,
|
||||||
createStudentRequestHandler,
|
createStudentRequestHandler,
|
||||||
getStudentRequestHandler,
|
getStudentRequestHandler,
|
||||||
deleteClassJoinRequestHandler
|
deleteClassJoinRequestHandler,
|
||||||
} 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';
|
||||||
import {BadRequestException} from "../../src/exceptions/bad-request-exception.js";
|
import { BadRequestException } from '../../src/exceptions/bad-request-exception.js';
|
||||||
import {ConflictException} from "../../src/exceptions/conflict-exception.js";
|
import { ConflictException } from '../../src/exceptions/conflict-exception.js';
|
||||||
import {EntityAlreadyExistsException} from "../../src/exceptions/entity-already-exists-exception.js";
|
import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js';
|
||||||
import {StudentDTO} from "../../src/interfaces/student.js";
|
import { StudentDTO } from '../../src/interfaces/student.js';
|
||||||
|
|
||||||
describe('Student controllers', () => {
|
describe('Student controllers', () => {
|
||||||
let req: Partial<Request>;
|
let req: Partial<Request>;
|
||||||
|
@ -55,17 +55,13 @@ describe('Student controllers', () => {
|
||||||
it('Student not found', async () => {
|
it('Student not found', async () => {
|
||||||
req = { params: { username: 'doesnotexist' } };
|
req = { params: { username: 'doesnotexist' } };
|
||||||
|
|
||||||
await expect(() => getStudentHandler(req as Request, res as Response))
|
await expect(() => 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(() => getStudentHandler(req as Request, res as Response))
|
await expect(() => 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 () => {
|
||||||
|
@ -73,8 +69,8 @@ describe('Student controllers', () => {
|
||||||
body: {
|
body: {
|
||||||
username: 'coolstudent',
|
username: 'coolstudent',
|
||||||
firstName: 'New',
|
firstName: 'New',
|
||||||
lastName: 'Student'
|
lastName: 'Student',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await createStudentHandler(req as Request, res as Response);
|
await createStudentHandler(req as Request, res as Response);
|
||||||
|
@ -88,27 +84,22 @@ describe('Student controllers', () => {
|
||||||
expect(sendStatusMock).toHaveBeenCalledWith(200);
|
expect(sendStatusMock).toHaveBeenCalledWith(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Create duplicate student', async () => {
|
it('Create duplicate student', async () => {
|
||||||
req = {
|
req = {
|
||||||
body: {
|
body: {
|
||||||
username: 'DireStraits',
|
username: 'DireStraits',
|
||||||
firstName: 'dupe',
|
firstName: 'dupe',
|
||||||
lastName: 'dupe'
|
lastName: 'dupe',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(() => createStudentHandler(req as Request, res as Response))
|
await expect(() => 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(() => createStudentHandler(req as Request, res as Response))
|
await expect(() => createStudentHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
|
||||||
.rejects
|
|
||||||
.toThrowError(BadRequestException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Student list', async () => {
|
it('Student list', async () => {
|
||||||
|
@ -133,7 +124,6 @@ describe('Student controllers', () => {
|
||||||
|
|
||||||
await getStudentClassesHandler(req as Request, res as Response);
|
await getStudentClassesHandler(req as Request, res as Response);
|
||||||
|
|
||||||
|
|
||||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ classes: expect.anything() }));
|
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ classes: expect.anything() }));
|
||||||
|
|
||||||
const result = jsonMock.mock.lastCall?.[0];
|
const result = jsonMock.mock.lastCall?.[0];
|
||||||
|
@ -176,9 +166,7 @@ describe('Student controllers', () => {
|
||||||
it('Deleting non-existent student', async () => {
|
it('Deleting non-existent student', async () => {
|
||||||
req = { params: { username: 'doesnotexist' } };
|
req = { params: { username: 'doesnotexist' } };
|
||||||
|
|
||||||
await expect(() => deleteStudentHandler(req as Request, res as Response))
|
await expect(() => deleteStudentHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
|
||||||
.rejects
|
|
||||||
.toThrow(NotFoundException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Get join requests by student', async () => {
|
it('Get join requests by student', async () => {
|
||||||
|
@ -203,7 +191,7 @@ describe('Student controllers', () => {
|
||||||
it('Create join request', async () => {
|
it('Create join request', async () => {
|
||||||
req = {
|
req = {
|
||||||
params: { username: 'Noordkaap' },
|
params: { username: 'Noordkaap' },
|
||||||
body: { classId: 'id02' }
|
body: { classId: 'id02' },
|
||||||
};
|
};
|
||||||
|
|
||||||
await createStudentRequestHandler(req as Request, res as Response);
|
await createStudentRequestHandler(req as Request, res as Response);
|
||||||
|
@ -214,15 +202,12 @@ describe('Student controllers', () => {
|
||||||
it('Create join request duplicate', async () => {
|
it('Create join request duplicate', async () => {
|
||||||
req = {
|
req = {
|
||||||
params: { username: 'Tool' },
|
params: { username: 'Tool' },
|
||||||
body: { classId: 'id02' }
|
body: { classId: 'id02' },
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(() => createStudentRequestHandler(req as Request, res as Response))
|
await expect(() => createStudentRequestHandler(req as Request, res as Response)).rejects.toThrow(ConflictException);
|
||||||
.rejects
|
|
||||||
.toThrow(ConflictException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Delete join request', async () => {
|
it('Delete join request', async () => {
|
||||||
req = {
|
req = {
|
||||||
params: { username: 'Noordkaap', classId: 'id02' },
|
params: { username: 'Noordkaap', classId: 'id02' },
|
||||||
|
@ -232,9 +217,6 @@ describe('Student controllers', () => {
|
||||||
|
|
||||||
expect(sendStatusMock).toHaveBeenCalledWith(204);
|
expect(sendStatusMock).toHaveBeenCalledWith(204);
|
||||||
|
|
||||||
await expect(() => deleteClassJoinRequestHandler(req as Request, res as Response))
|
await expect(() => deleteClassJoinRequestHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
|
||||||
.rejects
|
|
||||||
.toThrow(NotFoundException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
import {beforeAll, beforeEach, describe, expect, it, Mock, vi} from "vitest";
|
import { beforeAll, beforeEach, describe, expect, it, Mock, vi } from 'vitest';
|
||||||
import {Request, Response} from "express";
|
import { Request, Response } from 'express';
|
||||||
import {setupTestApp} from "../setup-tests.js";
|
import { setupTestApp } from '../setup-tests.js';
|
||||||
import {NotFoundException} from "../../src/exceptions/not-found-exception.js";
|
import { NotFoundException } from '../../src/exceptions/not-found-exception.js';
|
||||||
import {
|
import {
|
||||||
createTeacherHandler,
|
createTeacherHandler,
|
||||||
deleteTeacherHandler,
|
deleteTeacherHandler,
|
||||||
getAllTeachersHandler, getStudentJoinRequestHandler, getTeacherClassHandler,
|
getAllTeachersHandler,
|
||||||
getTeacherHandler, getTeacherQuestionHandler, getTeacherStudentHandler, updateStudentJoinRequestHandler
|
getStudentJoinRequestHandler,
|
||||||
} from "../../src/controllers/teachers.js";
|
getTeacherClassHandler,
|
||||||
import {BadRequestException} from "../../src/exceptions/bad-request-exception.js";
|
getTeacherHandler,
|
||||||
import {EntityAlreadyExistsException} from "../../src/exceptions/entity-already-exists-exception.js";
|
getTeacherQuestionHandler,
|
||||||
import {getStudentRequestHandler} from "../../src/controllers/students.js";
|
getTeacherStudentHandler,
|
||||||
import {TeacherDTO} from "../../src/interfaces/teacher.js";
|
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', () => {
|
describe('Teacher controllers', () => {
|
||||||
let req: Partial<Request>;
|
let req: Partial<Request>;
|
||||||
|
@ -47,17 +52,13 @@ describe('Teacher controllers', () => {
|
||||||
it('Teacher not found', async () => {
|
it('Teacher not found', async () => {
|
||||||
req = { params: { username: 'doesnotexist' } };
|
req = { params: { username: 'doesnotexist' } };
|
||||||
|
|
||||||
await expect(() => getTeacherHandler(req as Request, res as Response))
|
await expect(() => 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(() => getTeacherHandler(req as Request, res as Response))
|
await expect(() => 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 () => {
|
||||||
|
@ -65,8 +66,8 @@ describe('Teacher controllers', () => {
|
||||||
body: {
|
body: {
|
||||||
username: 'coolteacher',
|
username: 'coolteacher',
|
||||||
firstName: 'New',
|
firstName: 'New',
|
||||||
lastName: 'Teacher'
|
lastName: 'Teacher',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await createTeacherHandler(req as Request, res as Response);
|
await createTeacherHandler(req as Request, res as Response);
|
||||||
|
@ -86,20 +87,16 @@ describe('Teacher controllers', () => {
|
||||||
username: 'FooFighters',
|
username: 'FooFighters',
|
||||||
firstName: 'Dave',
|
firstName: 'Dave',
|
||||||
lastName: 'Grohl',
|
lastName: 'Grohl',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(() => createTeacherHandler(req as Request, res as Response))
|
await expect(() => 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(() => createTeacherHandler(req as Request, res as Response))
|
await expect(() => createTeacherHandler(req as Request, res as Response)).rejects.toThrowError(BadRequestException);
|
||||||
.rejects
|
|
||||||
.toThrowError(BadRequestException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Teacher list', async () => {
|
it('Teacher list', async () => {
|
||||||
|
@ -120,12 +117,9 @@ describe('Teacher controllers', () => {
|
||||||
it('Deleting non-existent student', async () => {
|
it('Deleting non-existent student', async () => {
|
||||||
req = { params: { username: 'doesnotexist' } };
|
req = { params: { username: 'doesnotexist' } };
|
||||||
|
|
||||||
await expect(() => deleteTeacherHandler(req as Request, res as Response))
|
await expect(() => deleteTeacherHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException);
|
||||||
.rejects
|
|
||||||
.toThrow(NotFoundException);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Get teacher classes', async () => {
|
it('Get teacher classes', async () => {
|
||||||
req = {
|
req = {
|
||||||
params: { username: 'FooFighters' },
|
params: { username: 'FooFighters' },
|
||||||
|
@ -196,7 +190,7 @@ describe('Teacher controllers', () => {
|
||||||
req = {
|
req = {
|
||||||
query: { username: 'LimpBizkit', studentUsername: 'PinkFloyd' },
|
query: { username: 'LimpBizkit', studentUsername: 'PinkFloyd' },
|
||||||
params: { classId: 'id02' },
|
params: { classId: 'id02' },
|
||||||
body: { accepted: 'true' }
|
body: { accepted: 'true' },
|
||||||
};
|
};
|
||||||
|
|
||||||
await updateStudentJoinRequestHandler(req as Request, res as Response);
|
await updateStudentJoinRequestHandler(req as Request, res as Response);
|
||||||
|
@ -209,11 +203,7 @@ describe('Teacher controllers', () => {
|
||||||
|
|
||||||
await getStudentRequestHandler(req as Request, res as Response);
|
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;
|
expect(status).toBeTruthy;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,6 +15,5 @@ export const TEST_STUDENTS = [
|
||||||
|
|
||||||
// 🏗️ Functie die ORM entities maakt uit de data array
|
// 🏗️ Functie die ORM entities maakt uit de data array
|
||||||
export function makeTestStudents(em: EntityManager<IDatabaseDriver<Connection>>): Student[] {
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ export class TeacherController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateStudentJoinRequest(teacherUsername: string, classId: string, studentUsername: string, accepted: boolean) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInvitations(id: string) {return this.get<{ invitations: string[] }>(`/${id}/invitations`);}
|
// GetInvitations(id: string) {return this.get<{ invitations: string[] }>(`/${id}/invitations`);}
|
||||||
|
|
|
@ -6,16 +6,15 @@ import {StudentController} from "@/controllers/students.ts";
|
||||||
const studentController = new StudentController();
|
const studentController = new StudentController();
|
||||||
|
|
||||||
/** 🔑 Query keys */
|
/** 🔑 Query keys */
|
||||||
const STUDENTS_QUERY_KEY = (full: boolean) => ['students', full];
|
const STUDENTS_QUERY_KEY = (full: boolean) => ["students", full];
|
||||||
const STUDENT_QUERY_KEY = (username: string) => ['student', username];
|
const STUDENT_QUERY_KEY = (username: string) => ["student", username];
|
||||||
const STUDENT_CLASSES_QUERY_KEY = (username: string, full: boolean) => ['student-classes', username, full];
|
const STUDENT_CLASSES_QUERY_KEY = (username: string, full: boolean) => ["student-classes", username, full];
|
||||||
const STUDENT_ASSIGNMENTS_QUERY_KEY = (username: string, full: boolean) => ['student-assignments', username, full];
|
const STUDENT_ASSIGNMENTS_QUERY_KEY = (username: string, full: boolean) => ["student-assignments", username, full];
|
||||||
const STUDENT_GROUPS_QUERY_KEY = (username: string, full: boolean) => ['student-groups', username, full];
|
const STUDENT_GROUPS_QUERY_KEY = (username: string, full: boolean) => ["student-groups", username, full];
|
||||||
const STUDENT_SUBMISSIONS_QUERY_KEY = (username: string) => ['student-submissions', username];
|
const STUDENT_SUBMISSIONS_QUERY_KEY = (username: string) => ["student-submissions", username];
|
||||||
const STUDENT_QUESTIONS_QUERY_KEY = (username: string, full: boolean) => ['student-questions', username, full];
|
const STUDENT_QUESTIONS_QUERY_KEY = (username: string, full: boolean) => ["student-questions", username, full];
|
||||||
const STUDENT_JOIN_REQUESTS_QUERY_KEY = (username: string) => ["student-join-requests", username];
|
const STUDENT_JOIN_REQUESTS_QUERY_KEY = (username: string) => ["student-join-requests", username];
|
||||||
|
|
||||||
|
|
||||||
export function useStudentsQuery(full: MaybeRefOrGetter<boolean> = true) {
|
export function useStudentsQuery(full: MaybeRefOrGetter<boolean> = true) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: computed(() => STUDENTS_QUERY_KEY(toValue(full))),
|
queryKey: computed(() => STUDENTS_QUERY_KEY(toValue(full))),
|
||||||
|
@ -31,7 +30,10 @@ export function useStudentQuery(username: MaybeRefOrGetter<string | undefined>)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useStudentClassesQuery(username: MaybeRefOrGetter<string | undefined>, full: MaybeRefOrGetter<boolean> = true) {
|
export function useStudentClassesQuery(
|
||||||
|
username: MaybeRefOrGetter<string | undefined>,
|
||||||
|
full: MaybeRefOrGetter<boolean> = true,
|
||||||
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: computed(() => STUDENT_CLASSES_QUERY_KEY(toValue(username)!, toValue(full))),
|
queryKey: computed(() => STUDENT_CLASSES_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||||
queryFn: () => studentController.getClasses(toValue(username)!, toValue(full)),
|
queryFn: () => studentController.getClasses(toValue(username)!, toValue(full)),
|
||||||
|
@ -39,7 +41,10 @@ export function useStudentClassesQuery(username: MaybeRefOrGetter<string | undef
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useStudentAssignmentsQuery(username: MaybeRefOrGetter<string | undefined>, full: MaybeRefOrGetter<boolean> = true) {
|
export function useStudentAssignmentsQuery(
|
||||||
|
username: MaybeRefOrGetter<string | undefined>,
|
||||||
|
full: MaybeRefOrGetter<boolean> = true,
|
||||||
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: computed(() => STUDENT_ASSIGNMENTS_QUERY_KEY(toValue(username)!, toValue(full))),
|
queryKey: computed(() => STUDENT_ASSIGNMENTS_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||||
queryFn: () => studentController.getAssignments(toValue(username)!, toValue(full)),
|
queryFn: () => studentController.getAssignments(toValue(username)!, toValue(full)),
|
||||||
|
@ -47,7 +52,10 @@ export function useStudentAssignmentsQuery(username: MaybeRefOrGetter<string | u
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useStudentGroupsQuery(username: MaybeRefOrGetter<string | undefined>, full: MaybeRefOrGetter<boolean> = true) {
|
export function useStudentGroupsQuery(
|
||||||
|
username: MaybeRefOrGetter<string | undefined>,
|
||||||
|
full: MaybeRefOrGetter<boolean> = true,
|
||||||
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: computed(() => STUDENT_GROUPS_QUERY_KEY(toValue(username)!, toValue(full))),
|
queryKey: computed(() => STUDENT_GROUPS_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||||
queryFn: () => studentController.getGroups(toValue(username)!, toValue(full)),
|
queryFn: () => studentController.getGroups(toValue(username)!, toValue(full)),
|
||||||
|
@ -63,7 +71,10 @@ export function useStudentSubmissionsQuery(username: MaybeRefOrGetter<string | u
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useStudentQuestionsQuery(username: MaybeRefOrGetter<string | undefined>, full: MaybeRefOrGetter<boolean> = true) {
|
export function useStudentQuestionsQuery(
|
||||||
|
username: MaybeRefOrGetter<string | undefined>,
|
||||||
|
full: MaybeRefOrGetter<boolean> = true,
|
||||||
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: computed(() => STUDENT_QUESTIONS_QUERY_KEY(toValue(username)!, toValue(full))),
|
queryKey: computed(() => STUDENT_QUESTIONS_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||||
queryFn: () => studentController.getQuestions(toValue(username)!, toValue(full)),
|
queryFn: () => studentController.getQuestions(toValue(username)!, toValue(full)),
|
||||||
|
@ -77,7 +88,7 @@ export function useCreateStudentMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (data: any) => studentController.createStudent(data),
|
mutationFn: (data: any) => studentController.createStudent(data),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
await queryClient.invalidateQueries({ queryKey: ['students'] });
|
await queryClient.invalidateQueries({ queryKey: ["students"] });
|
||||||
},
|
},
|
||||||
onError: (err) => {
|
onError: (err) => {
|
||||||
alert("Create student failed:", err);
|
alert("Create student failed:", err);
|
||||||
|
@ -94,7 +105,7 @@ export function useDeleteStudentMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (username: string) => studentController.deleteStudent(username),
|
mutationFn: (username: string) => studentController.deleteStudent(username),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
await queryClient.invalidateQueries({ queryKey: ['students'] });
|
await queryClient.invalidateQueries({ queryKey: ["students"] });
|
||||||
},
|
},
|
||||||
onError: (err) => {
|
onError: (err) => {
|
||||||
alert("Delete student failed:", err);
|
alert("Delete student failed:", err);
|
||||||
|
@ -145,7 +156,3 @@ export function useDeleteJoinRequestMutation() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,10 @@ export function useTeacherQuery(username: MaybeRefOrGetter<string | undefined>)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTeacherClassesQuery(username: MaybeRefOrGetter<string | undefined>, full: MaybeRefOrGetter<boolean> = false) {
|
export function useTeacherClassesQuery(
|
||||||
|
username: MaybeRefOrGetter<string | undefined>,
|
||||||
|
full: MaybeRefOrGetter<boolean> = false,
|
||||||
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: computed(() => TEACHER_CLASSES_QUERY_KEY(toValue(username)!, toValue(full))),
|
queryKey: computed(() => TEACHER_CLASSES_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||||
queryFn: () => teacherController.getClasses(toValue(username)!, toValue(full)),
|
queryFn: () => teacherController.getClasses(toValue(username)!, toValue(full)),
|
||||||
|
@ -36,7 +39,10 @@ export function useTeacherClassesQuery(username: MaybeRefOrGetter<string | undef
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTeacherStudentsQuery(username: MaybeRefOrGetter<string | undefined>, full: MaybeRefOrGetter<boolean> = false) {
|
export function useTeacherStudentsQuery(
|
||||||
|
username: MaybeRefOrGetter<string | undefined>,
|
||||||
|
full: MaybeRefOrGetter<boolean> = false,
|
||||||
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: computed(() => TEACHER_STUDENTS_QUERY_KEY(toValue(username)!, toValue(full))),
|
queryKey: computed(() => TEACHER_STUDENTS_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||||
queryFn: () => teacherController.getStudents(toValue(username)!, toValue(full)),
|
queryFn: () => teacherController.getStudents(toValue(username)!, toValue(full)),
|
||||||
|
@ -44,7 +50,10 @@ export function useTeacherStudentsQuery(username: MaybeRefOrGetter<string | unde
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTeacherQuestionsQuery(username: MaybeRefOrGetter<string | undefined>, full: MaybeRefOrGetter<boolean> = false) {
|
export function useTeacherQuestionsQuery(
|
||||||
|
username: MaybeRefOrGetter<string | undefined>,
|
||||||
|
full: MaybeRefOrGetter<boolean> = false,
|
||||||
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: computed(() => TEACHER_QUESTIONS_QUERY_KEY(toValue(username)!, toValue(full))),
|
queryKey: computed(() => TEACHER_QUESTIONS_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||||
queryFn: () => teacherController.getQuestions(toValue(username)!, toValue(full)),
|
queryFn: () => teacherController.getQuestions(toValue(username)!, toValue(full)),
|
||||||
|
@ -52,7 +61,10 @@ export function useTeacherQuestionsQuery(username: MaybeRefOrGetter<string | und
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTeacherJoinRequestsQuery(username: MaybeRefOrGetter<string | undefined>, classId: MaybeRefOrGetter<string | undefined>) {
|
export function useTeacherJoinRequestsQuery(
|
||||||
|
username: MaybeRefOrGetter<string | undefined>,
|
||||||
|
classId: MaybeRefOrGetter<string | undefined>,
|
||||||
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: computed(() => JOIN_REQUESTS_QUERY_KEY(toValue(username)!, toValue(classId)!)),
|
queryKey: computed(() => JOIN_REQUESTS_QUERY_KEY(toValue(username)!, toValue(classId)!)),
|
||||||
queryFn: () => teacherController.getStudentJoinRequests(toValue(username)!, toValue(classId)!),
|
queryFn: () => teacherController.getStudentJoinRequests(toValue(username)!, toValue(classId)!),
|
||||||
|
@ -66,7 +78,7 @@ export function useCreateTeacherMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (data: any) => teacherController.createTeacher(data),
|
mutationFn: (data: any) => teacherController.createTeacher(data),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
await queryClient.invalidateQueries({ queryKey: ['teachers'] });
|
await queryClient.invalidateQueries({ queryKey: ["teachers"] });
|
||||||
},
|
},
|
||||||
onError: (err) => {
|
onError: (err) => {
|
||||||
alert("Create teacher failed:", err);
|
alert("Create teacher failed:", err);
|
||||||
|
@ -80,7 +92,7 @@ export function useDeleteTeacherMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (username: string) => teacherController.deleteTeacher(username),
|
mutationFn: (username: string) => teacherController.deleteTeacher(username),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
await queryClient.invalidateQueries({ queryKey: ['teachers'] });
|
await queryClient.invalidateQueries({ queryKey: ["teachers"] });
|
||||||
},
|
},
|
||||||
onError: (err) => {
|
onError: (err) => {
|
||||||
alert("Delete teacher failed:", err);
|
alert("Delete teacher failed:", err);
|
||||||
|
@ -92,7 +104,12 @@ export function useUpdateJoinRequestMutation() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: ({ teacherUsername, classId, studentUsername, accepted }: {
|
mutationFn: ({
|
||||||
|
teacherUsername,
|
||||||
|
classId,
|
||||||
|
studentUsername,
|
||||||
|
accepted,
|
||||||
|
}: {
|
||||||
teacherUsername: string;
|
teacherUsername: string;
|
||||||
classId: string;
|
classId: string;
|
||||||
studentUsername: string;
|
studentUsername: string;
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
import { describe, it, expect, beforeAll } from 'vitest';
|
import { describe, it, expect, beforeAll } from "vitest";
|
||||||
import { StudentController } from "../../src/controllers/students";
|
import { StudentController } from "../../src/controllers/students";
|
||||||
|
|
||||||
const controller = new StudentController();
|
const controller = new StudentController();
|
||||||
|
|
||||||
describe('StudentController', () => {
|
describe("StudentController", () => {
|
||||||
const newStudent = {
|
const newStudent = {
|
||||||
username: 'teststudent1',
|
username: "teststudent1",
|
||||||
firstName: 'Testy',
|
firstName: "Testy",
|
||||||
lastName: 'McTestface',
|
lastName: "McTestface",
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
// Start backend
|
// Start backend
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates a student and fetches it by username', async () => {
|
it("creates a student and fetches it by username", async () => {
|
||||||
// Create student
|
// Create student
|
||||||
await controller.createStudent(newStudent);
|
await controller.createStudent(newStudent);
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ describe('StudentController', () => {
|
||||||
expect(student.firstName).toBe(newStudent.firstName);
|
expect(student.firstName).toBe(newStudent.firstName);
|
||||||
expect(student.lastName).toBe(newStudent.lastName);
|
expect(student.lastName).toBe(newStudent.lastName);
|
||||||
|
|
||||||
|
|
||||||
await controller.deleteStudent(newStudent.username);
|
await controller.deleteStudent(newStudent.username);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
import { describe, it, expect, beforeAll } from 'vitest';
|
import { describe, it, expect, beforeAll } from "vitest";
|
||||||
import { TeacherController } from "../../src/controllers/teachers";
|
import { TeacherController } from "../../src/controllers/teachers";
|
||||||
|
|
||||||
const controller = new TeacherController();
|
const controller = new TeacherController();
|
||||||
|
|
||||||
describe('TeacherController', () => {
|
describe("TeacherController", () => {
|
||||||
const newTeacher = {
|
const newTeacher = {
|
||||||
username: 'testteacher3',
|
username: "testteacher3",
|
||||||
firstName: 'Testy',
|
firstName: "Testy",
|
||||||
lastName: 'McTestface',
|
lastName: "McTestface",
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
// Start backend
|
// Start backend
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates a student and fetches it by username', async () => {
|
it("creates a student and fetches it by username", async () => {
|
||||||
// Create student
|
// Create student
|
||||||
await controller.createTeacher(newTeacher);
|
await controller.createTeacher(newTeacher);
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ describe('TeacherController', () => {
|
||||||
expect(teacher.firstName).toBe(newTeacher.firstName);
|
expect(teacher.firstName).toBe(newTeacher.firstName);
|
||||||
expect(teacher.lastName).toBe(newTeacher.lastName);
|
expect(teacher.lastName).toBe(newTeacher.lastName);
|
||||||
|
|
||||||
|
|
||||||
await controller.deleteTeacher(newTeacher.username);
|
await controller.deleteTeacher(newTeacher.username);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue