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); | ||||
|  | @ -30,7 +30,7 @@ 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"); | ||||
|         throw new ConflictException('The teacher sending the invite is not part of the class'); | ||||
|     } | ||||
| 
 | ||||
|     const newInvitation = mapToInvitation(sender, receiver, cls); | ||||
|  | @ -44,13 +44,18 @@ async function fetchInvitation(sender: Teacher, receiver: Teacher, cls: Class): | |||
|     const invite = await teacherInvitationRepository.findBy(cls, sender, receiver); | ||||
| 
 | ||||
|     if (!invite) { | ||||
|         throw new NotFoundException("Teacher invite not found"); | ||||
|         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); | ||||
|  | @ -66,6 +71,3 @@ export async function deleteInvitationFor(usernameSender: string, usernameReceiv | |||
| 
 | ||||
|     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>; | ||||
|  | @ -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' }); | ||||
|  |  | |||
|  | @ -2,11 +2,11 @@ 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,15 +1,10 @@ | |||
| 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"; | ||||
|  | @ -19,47 +14,67 @@ 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"> | ||||
|  |  | |||
		Reference in a new issue
	
	 Lint Action
						Lint Action