style: fix linting issues met Prettier
This commit is contained in:
parent
a824cdff94
commit
783c91b2e3
11 changed files with 112 additions and 93 deletions
|
@ -1,7 +1,7 @@
|
|||
import { Request, Response } from 'express';
|
||||
import {requireFields} from "./error-helper";
|
||||
import {createInvitation, deleteInvitationFor, getAllInvitations} from "../services/teacher-invitations";
|
||||
import {TeacherInvitationData} from "@dwengo-1/common/interfaces/teacher-invitation";
|
||||
import { requireFields } from './error-helper';
|
||||
import { createInvitation, deleteInvitationFor, getAllInvitations } from '../services/teacher-invitations';
|
||||
import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation';
|
||||
|
||||
export async function getAllInvitationsHandler(req: Request, res: Response): Promise<void> {
|
||||
const username = req.params.username;
|
||||
|
|
|
@ -25,6 +25,6 @@ export class TeacherInvitationRepository extends DwengoEntityRepository<TeacherI
|
|||
sender: sender,
|
||||
receiver: receiver,
|
||||
class: clazz,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity.js';
|
||||
import { mapToUserDTO } from './user.js';
|
||||
import { TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation';
|
||||
import {getTeacherInvitationRepository} from "../data/repositories";
|
||||
import {Teacher} from "../entities/users/teacher.entity";
|
||||
import {Class} from "../entities/classes/class.entity";
|
||||
import { getTeacherInvitationRepository } from '../data/repositories';
|
||||
import { Teacher } from '../entities/users/teacher.entity';
|
||||
import { Class } from '../entities/classes/class.entity';
|
||||
|
||||
export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO {
|
||||
return {
|
||||
|
@ -23,6 +23,8 @@ export function mapToTeacherInvitationDTOIds(invitation: TeacherInvitation): Tea
|
|||
|
||||
export function mapToInvitation(sender: Teacher, receiver: Teacher, cls: Class): TeacherInvitation {
|
||||
return getTeacherInvitationRepository().create({
|
||||
sender, receiver, class: cls
|
||||
sender,
|
||||
receiver,
|
||||
class: cls,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
import express from "express";
|
||||
import {
|
||||
createInvitationHandler,
|
||||
deleteInvitationForHandler,
|
||||
getAllInvitationsHandler
|
||||
} from "../controllers/teacher-invitations";
|
||||
import express from 'express';
|
||||
import { createInvitationHandler, deleteInvitationForHandler, getAllInvitationsHandler } from '../controllers/teacher-invitations';
|
||||
|
||||
const router = express.Router({ mergeParams: true });
|
||||
|
||||
|
@ -13,5 +9,4 @@ router.post('/', createInvitationHandler);
|
|||
|
||||
router.delete('/:sender/:receiver/:classId', deleteInvitationForHandler);
|
||||
|
||||
|
||||
export default router;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import {fetchTeacher} from "./teachers";
|
||||
import {getTeacherInvitationRepository} from "../data/repositories";
|
||||
import {mapToInvitation, mapToTeacherInvitationDTO} from "../interfaces/teacher-invitation";
|
||||
import {addClassTeacher, fetchClass} from "./classes";
|
||||
import {TeacherInvitationData, TeacherInvitationDTO} from "@dwengo-1/common/interfaces/teacher-invitation";
|
||||
import {ConflictException} from "../exceptions/conflict-exception";
|
||||
import {Teacher} from "../entities/users/teacher.entity";
|
||||
import {Class} from "../entities/classes/class.entity";
|
||||
import {NotFoundException} from "../exceptions/not-found-exception";
|
||||
import {TeacherInvitation} from "../entities/classes/teacher-invitation.entity";
|
||||
import { fetchTeacher } from './teachers';
|
||||
import { getTeacherInvitationRepository } from '../data/repositories';
|
||||
import { mapToInvitation, mapToTeacherInvitationDTO } from '../interfaces/teacher-invitation';
|
||||
import { addClassTeacher, fetchClass } from './classes';
|
||||
import { TeacherInvitationData, TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation';
|
||||
import { ConflictException } from '../exceptions/conflict-exception';
|
||||
import { Teacher } from '../entities/users/teacher.entity';
|
||||
import { Class } from '../entities/classes/class.entity';
|
||||
import { NotFoundException } from '../exceptions/not-found-exception';
|
||||
import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity';
|
||||
|
||||
export async function getAllInvitations(username: string, by: boolean): Promise<TeacherInvitationDTO[]> {
|
||||
const teacher = await fetchTeacher(username);
|
||||
|
@ -29,12 +29,12 @@ export async function createInvitation(data: TeacherInvitationData): Promise<Tea
|
|||
|
||||
const cls = await fetchClass(data.class);
|
||||
|
||||
if (!cls.teachers.contains(sender)){
|
||||
throw new ConflictException("The teacher sending the invite is not part of the class");
|
||||
if (!cls.teachers.contains(sender)) {
|
||||
throw new ConflictException('The teacher sending the invite is not part of the class');
|
||||
}
|
||||
|
||||
const newInvitation = mapToInvitation(sender, receiver, cls);
|
||||
await teacherInvitationRepository.save(newInvitation, {preventOverwrite: true});
|
||||
await teacherInvitationRepository.save(newInvitation, { preventOverwrite: true });
|
||||
|
||||
return mapToTeacherInvitationDTO(newInvitation);
|
||||
}
|
||||
|
@ -43,14 +43,19 @@ async function fetchInvitation(sender: Teacher, receiver: Teacher, cls: Class):
|
|||
const teacherInvitationRepository = getTeacherInvitationRepository();
|
||||
const invite = await teacherInvitationRepository.findBy(cls, sender, receiver);
|
||||
|
||||
if (!invite){
|
||||
throw new NotFoundException("Teacher invite not found");
|
||||
if (!invite) {
|
||||
throw new NotFoundException('Teacher invite not found');
|
||||
}
|
||||
|
||||
return invite;
|
||||
}
|
||||
|
||||
export async function deleteInvitationFor(usernameSender: string, usernameReceiver: string, classId: string, accepted: boolean): Promise<TeacherInvitationDTO> {
|
||||
export async function deleteInvitationFor(
|
||||
usernameSender: string,
|
||||
usernameReceiver: string,
|
||||
classId: string,
|
||||
accepted: boolean
|
||||
): Promise<TeacherInvitationDTO> {
|
||||
const teacherInvitationRepository = getTeacherInvitationRepository();
|
||||
const sender = await fetchTeacher(usernameSender);
|
||||
const receiver = await fetchTeacher(usernameReceiver);
|
||||
|
@ -60,12 +65,9 @@ export async function deleteInvitationFor(usernameSender: string, usernameReceiv
|
|||
const invitation = await fetchInvitation(sender, receiver, cls);
|
||||
await teacherInvitationRepository.deleteBy(cls, sender, receiver);
|
||||
|
||||
if (accepted){
|
||||
if (accepted) {
|
||||
await addClassTeacher(classId, usernameReceiver);
|
||||
}
|
||||
|
||||
return mapToTeacherInvitationDTO(invitation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
import { beforeAll, beforeEach, describe, expect, it, Mock, vi } from 'vitest';
|
||||
import { Request, Response } from 'express';
|
||||
import { setupTestApp } from '../setup-tests.js';
|
||||
import {
|
||||
createInvitationHandler,
|
||||
deleteInvitationForHandler,
|
||||
getAllInvitationsHandler
|
||||
} from "../../src/controllers/teacher-invitations";
|
||||
import {TeacherInvitationData} from "@dwengo-1/common/interfaces/teacher-invitation";
|
||||
import {getClassHandler} from "../../src/controllers/classes";
|
||||
import { createInvitationHandler, deleteInvitationForHandler, getAllInvitationsHandler } from '../../src/controllers/teacher-invitations';
|
||||
import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation';
|
||||
import { getClassHandler } from '../../src/controllers/classes';
|
||||
|
||||
describe('Teacher controllers', () => {
|
||||
let req: Partial<Request>;
|
||||
|
@ -27,22 +23,22 @@ describe('Teacher controllers', () => {
|
|||
});
|
||||
|
||||
it('Get teacher invitations by', async () => {
|
||||
req = {params: {username: 'LimpBizkit'}, query: {by: 'true' }};
|
||||
req = { params: { username: 'LimpBizkit' }, query: { by: 'true' } };
|
||||
|
||||
await getAllInvitationsHandler(req as Request, res as Response);
|
||||
|
||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({invitations: expect.anything()}));
|
||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ invitations: expect.anything() }));
|
||||
|
||||
const result = jsonMock.mock.lastCall?.[0];
|
||||
expect(result.invitations).to.have.length.greaterThan(0);
|
||||
});
|
||||
|
||||
it('Get teacher invitations for', async () => {
|
||||
req = {params: {username: 'FooFighters'}, query: {by: 'false' }};
|
||||
req = { params: { username: 'FooFighters' }, query: { by: 'false' } };
|
||||
|
||||
await getAllInvitationsHandler(req as Request, res as Response);
|
||||
|
||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({invitations: expect.anything()}));
|
||||
expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ invitations: expect.anything() }));
|
||||
|
||||
const result = jsonMock.mock.lastCall?.[0];
|
||||
expect(result.invitations).to.have.length.greaterThan(0);
|
||||
|
@ -50,8 +46,9 @@ describe('Teacher controllers', () => {
|
|||
|
||||
it('Create and delete invitation', async () => {
|
||||
const body = {
|
||||
sender: 'LimpBizkit', receiver: 'testleerkracht1',
|
||||
class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89'
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'testleerkracht1',
|
||||
class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
} as TeacherInvitationData;
|
||||
req = { body };
|
||||
|
||||
|
@ -59,9 +56,11 @@ describe('Teacher controllers', () => {
|
|||
|
||||
req = {
|
||||
params: {
|
||||
sender: 'LimpBizkit', receiver: 'testleerkracht1',
|
||||
classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89'
|
||||
}, body: { accepted: 'false' }
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'testleerkracht1',
|
||||
classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
},
|
||||
body: { accepted: 'false' },
|
||||
};
|
||||
|
||||
await deleteInvitationForHandler(req as Request, res as Response);
|
||||
|
@ -69,8 +68,9 @@ describe('Teacher controllers', () => {
|
|||
|
||||
it('Create and accept invitation', async () => {
|
||||
const body = {
|
||||
sender: 'LimpBizkit', receiver: 'testleerkracht1',
|
||||
class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89'
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'testleerkracht1',
|
||||
class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
} as TeacherInvitationData;
|
||||
req = { body };
|
||||
|
||||
|
@ -78,16 +78,20 @@ describe('Teacher controllers', () => {
|
|||
|
||||
req = {
|
||||
params: {
|
||||
sender: 'LimpBizkit', receiver: 'testleerkracht1',
|
||||
classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89'
|
||||
}, body: { accepted: 'true' }
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'testleerkracht1',
|
||||
classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
},
|
||||
body: { accepted: 'true' },
|
||||
};
|
||||
|
||||
await deleteInvitationForHandler(req as Request, res as Response);
|
||||
|
||||
req = {params: {
|
||||
id: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89'
|
||||
}};
|
||||
req = {
|
||||
params: {
|
||||
id: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
},
|
||||
};
|
||||
|
||||
await getClassHandler(req as Request, res as Response);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import { makeTestAttachments } from './test_assets/content/attachments.testdata.
|
|||
import { makeTestQuestions } from './test_assets/questions/questions.testdata.js';
|
||||
import { makeTestAnswers } from './test_assets/questions/answers.testdata.js';
|
||||
import { makeTestSubmissions } from './test_assets/assignments/submission.testdata.js';
|
||||
import {Collection} from "@mikro-orm/core";
|
||||
import { Collection } from '@mikro-orm/core';
|
||||
|
||||
export async function setupTestApp(): Promise<void> {
|
||||
dotenv.config({ path: '.env.test' });
|
||||
|
|
|
@ -3,7 +3,7 @@ import type { ClassDTO } from "@dwengo-1/common/interfaces/class";
|
|||
import type { StudentsResponse } from "./students";
|
||||
import type { AssignmentsResponse } from "./assignments";
|
||||
import type { TeachersResponse } from "@/controllers/teachers.ts";
|
||||
import type {TeacherInvitationsResponse} from "@/controllers/teacher-invitations.ts";
|
||||
import type { TeacherInvitationsResponse } from "@/controllers/teacher-invitations.ts";
|
||||
|
||||
export interface ClassesResponse {
|
||||
classes: ClassDTO[] | string[];
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import {BaseController} from "@/controllers/base-controller.ts";
|
||||
import type {TeacherInvitationData, TeacherInvitationDTO} from "@dwengo-1/common/interfaces/teacher-invitation";
|
||||
import { BaseController } from "@/controllers/base-controller.ts";
|
||||
import type { TeacherInvitationData, TeacherInvitationDTO } from "@dwengo-1/common/interfaces/teacher-invitation";
|
||||
|
||||
export interface TeacherInvitationsResponse {
|
||||
invitations: TeacherInvitationDTO[]
|
||||
invitations: TeacherInvitationDTO[];
|
||||
}
|
||||
|
||||
export interface TeacherInvitationResponse {
|
||||
invitation: TeacherInvitationDTO
|
||||
invitation: TeacherInvitationDTO;
|
||||
}
|
||||
|
||||
export class TeacherInvitationController extends BaseController {
|
||||
|
|
|
@ -1,65 +1,80 @@
|
|||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
type UseMutationReturnType,
|
||||
type UseQueryReturnType,
|
||||
} from "@tanstack/vue-query";
|
||||
import { useMutation, useQuery, type UseMutationReturnType, type UseQueryReturnType } from "@tanstack/vue-query";
|
||||
import { computed, toValue } from "vue";
|
||||
import type { MaybeRefOrGetter } from "vue";
|
||||
import {
|
||||
TeacherInvitationController,
|
||||
type TeacherInvitationResponse,
|
||||
type TeacherInvitationsResponse
|
||||
type TeacherInvitationsResponse,
|
||||
} from "@/controllers/teacher-invitations.ts";
|
||||
import type {TeacherInvitationData} from "@dwengo-1/common/dist/interfaces/teacher-invitation.ts";
|
||||
import type {TeacherDTO} from "@dwengo-1/common/dist/interfaces/teacher.ts";
|
||||
import type { TeacherInvitationData } from "@dwengo-1/common/dist/interfaces/teacher-invitation.ts";
|
||||
import type { TeacherDTO } from "@dwengo-1/common/dist/interfaces/teacher.ts";
|
||||
|
||||
const controller = new TeacherInvitationController();
|
||||
|
||||
/**
|
||||
All the invitations the teacher send
|
||||
**/
|
||||
export function useTeacherInvitationsByQuery(username: MaybeRefOrGetter<string | undefined>
|
||||
export function useTeacherInvitationsByQuery(
|
||||
username: MaybeRefOrGetter<string | undefined>,
|
||||
): UseQueryReturnType<TeacherInvitationsResponse, Error> {
|
||||
return useQuery({
|
||||
queryFn: computed(async () => controller.getAll(toValue(username), true)),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
All the pending invitations send to this teacher
|
||||
*/
|
||||
export function useTeacherInvitationsForQuery(username: MaybeRefOrGetter<string | undefined>
|
||||
export function useTeacherInvitationsForQuery(
|
||||
username: MaybeRefOrGetter<string | undefined>,
|
||||
): UseQueryReturnType<TeacherInvitationsResponse, Error> {
|
||||
return useQuery({
|
||||
queryFn: computed(async () => controller.getAll(toValue(username), false)),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateTeacherInvitationMutation(): UseMutationReturnType<TeacherInvitationResponse, Error, TeacherDTO, unknown>{
|
||||
export function useCreateTeacherInvitationMutation(): UseMutationReturnType<
|
||||
TeacherInvitationResponse,
|
||||
Error,
|
||||
TeacherDTO,
|
||||
unknown
|
||||
> {
|
||||
return useMutation({
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.create(data)
|
||||
})
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.create(data),
|
||||
});
|
||||
}
|
||||
|
||||
export function useAcceptTeacherInvitationMutation(): UseMutationReturnType<TeacherInvitationResponse, Error, TeacherDTO, unknown> {
|
||||
export function useAcceptTeacherInvitationMutation(): UseMutationReturnType<
|
||||
TeacherInvitationResponse,
|
||||
Error,
|
||||
TeacherDTO,
|
||||
unknown
|
||||
> {
|
||||
return useMutation({
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.respond(data, true)
|
||||
})
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.respond(data, true),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeclineTeacherInvitationMutation(): UseMutationReturnType<TeacherInvitationResponse, Error, TeacherDTO, unknown> {
|
||||
export function useDeclineTeacherInvitationMutation(): UseMutationReturnType<
|
||||
TeacherInvitationResponse,
|
||||
Error,
|
||||
TeacherDTO,
|
||||
unknown
|
||||
> {
|
||||
return useMutation({
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.respond(data, false)
|
||||
})
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.respond(data, false),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteTeacherInvitationMutation(): UseMutationReturnType<TeacherInvitationResponse, Error, TeacherDTO, unknown> {
|
||||
export function useDeleteTeacherInvitationMutation(): UseMutationReturnType<
|
||||
TeacherInvitationResponse,
|
||||
Error,
|
||||
TeacherDTO,
|
||||
unknown
|
||||
> {
|
||||
return useMutation({
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.respond(data, false)
|
||||
})
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.respond(data, false),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -279,7 +279,8 @@
|
|||
:key="i.classId"
|
||||
>
|
||||
<td>
|
||||
{{ i.classId }} <!-- TODO fetch display name via classId because db only returns classId field -->
|
||||
{{ i.classId }}
|
||||
<!-- TODO fetch display name via classId because db only returns classId field -->
|
||||
</td>
|
||||
<td>{{ (i.sender as TeacherDTO).firstName + " " + (i.sender as TeacherDTO).lastName }}</td>
|
||||
<td class="text-right">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue