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 { Request, Response } from 'express'; | ||||||
| import {requireFields} from "./error-helper"; | import { requireFields } from './error-helper'; | ||||||
| import {createInvitation, deleteInvitationFor, getAllInvitations} from "../services/teacher-invitations"; | import { createInvitation, deleteInvitationFor, getAllInvitations } from '../services/teacher-invitations'; | ||||||
| import {TeacherInvitationData} from "@dwengo-1/common/interfaces/teacher-invitation"; | import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation'; | ||||||
| 
 | 
 | ||||||
| export async function getAllInvitationsHandler(req: Request, res: Response): Promise<void> { | export async function getAllInvitationsHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const username = req.params.username; |     const username = req.params.username; | ||||||
|  |  | ||||||
|  | @ -25,6 +25,6 @@ export class TeacherInvitationRepository extends DwengoEntityRepository<TeacherI | ||||||
|             sender: sender, |             sender: sender, | ||||||
|             receiver: receiver, |             receiver: receiver, | ||||||
|             class: clazz, |             class: clazz, | ||||||
|         }) |         }); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,9 +1,9 @@ | ||||||
| import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity.js'; | import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity.js'; | ||||||
| import { mapToUserDTO } from './user.js'; | import { mapToUserDTO } from './user.js'; | ||||||
| import { TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation'; | import { TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation'; | ||||||
| import {getTeacherInvitationRepository} from "../data/repositories"; | import { getTeacherInvitationRepository } from '../data/repositories'; | ||||||
| import {Teacher} from "../entities/users/teacher.entity"; | import { Teacher } from '../entities/users/teacher.entity'; | ||||||
| import {Class} from "../entities/classes/class.entity"; | import { Class } from '../entities/classes/class.entity'; | ||||||
| 
 | 
 | ||||||
| export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO { | export function mapToTeacherInvitationDTO(invitation: TeacherInvitation): TeacherInvitationDTO { | ||||||
|     return { |     return { | ||||||
|  | @ -23,6 +23,8 @@ export function mapToTeacherInvitationDTOIds(invitation: TeacherInvitation): Tea | ||||||
| 
 | 
 | ||||||
| export function mapToInvitation(sender: Teacher, receiver: Teacher, cls: Class): TeacherInvitation { | export function mapToInvitation(sender: Teacher, receiver: Teacher, cls: Class): TeacherInvitation { | ||||||
|     return getTeacherInvitationRepository().create({ |     return getTeacherInvitationRepository().create({ | ||||||
|         sender, receiver, class: cls |         sender, | ||||||
|  |         receiver, | ||||||
|  |         class: cls, | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,9 +1,5 @@ | ||||||
| import express from "express"; | import express from 'express'; | ||||||
| import { | import { createInvitationHandler, deleteInvitationForHandler, getAllInvitationsHandler } from '../controllers/teacher-invitations'; | ||||||
|     createInvitationHandler, |  | ||||||
|     deleteInvitationForHandler, |  | ||||||
|     getAllInvitationsHandler |  | ||||||
| } from "../controllers/teacher-invitations"; |  | ||||||
| 
 | 
 | ||||||
| const router = express.Router({ mergeParams: true }); | const router = express.Router({ mergeParams: true }); | ||||||
| 
 | 
 | ||||||
|  | @ -13,5 +9,4 @@ router.post('/', createInvitationHandler); | ||||||
| 
 | 
 | ||||||
| router.delete('/:sender/:receiver/:classId', deleteInvitationForHandler); | router.delete('/:sender/:receiver/:classId', deleteInvitationForHandler); | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| export default router; | export default router; | ||||||
|  |  | ||||||
|  | @ -1,13 +1,13 @@ | ||||||
| import {fetchTeacher} from "./teachers"; | import { fetchTeacher } from './teachers'; | ||||||
| import {getTeacherInvitationRepository} from "../data/repositories"; | import { getTeacherInvitationRepository } from '../data/repositories'; | ||||||
| import {mapToInvitation, mapToTeacherInvitationDTO} from "../interfaces/teacher-invitation"; | import { mapToInvitation, mapToTeacherInvitationDTO } from '../interfaces/teacher-invitation'; | ||||||
| import {addClassTeacher, fetchClass} from "./classes"; | import { addClassTeacher, fetchClass } from './classes'; | ||||||
| import {TeacherInvitationData, TeacherInvitationDTO} from "@dwengo-1/common/interfaces/teacher-invitation"; | import { TeacherInvitationData, TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation'; | ||||||
| import {ConflictException} from "../exceptions/conflict-exception"; | import { ConflictException } from '../exceptions/conflict-exception'; | ||||||
| import {Teacher} from "../entities/users/teacher.entity"; | import { Teacher } from '../entities/users/teacher.entity'; | ||||||
| import {Class} from "../entities/classes/class.entity"; | import { Class } from '../entities/classes/class.entity'; | ||||||
| import {NotFoundException} from "../exceptions/not-found-exception"; | import { NotFoundException } from '../exceptions/not-found-exception'; | ||||||
| import {TeacherInvitation} from "../entities/classes/teacher-invitation.entity"; | import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity'; | ||||||
| 
 | 
 | ||||||
| export async function getAllInvitations(username: string, by: boolean): Promise<TeacherInvitationDTO[]> { | export async function getAllInvitations(username: string, by: boolean): Promise<TeacherInvitationDTO[]> { | ||||||
|     const teacher = await fetchTeacher(username); |     const teacher = await fetchTeacher(username); | ||||||
|  | @ -30,7 +30,7 @@ export async function createInvitation(data: TeacherInvitationData): Promise<Tea | ||||||
|     const cls = await fetchClass(data.class); |     const cls = await fetchClass(data.class); | ||||||
| 
 | 
 | ||||||
|     if (!cls.teachers.contains(sender)) { |     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); |     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); |     const invite = await teacherInvitationRepository.findBy(cls, sender, receiver); | ||||||
| 
 | 
 | ||||||
|     if (!invite) { |     if (!invite) { | ||||||
|         throw new NotFoundException("Teacher invite not found"); |         throw new NotFoundException('Teacher invite not found'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return invite; |     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 teacherInvitationRepository = getTeacherInvitationRepository(); | ||||||
|     const sender = await fetchTeacher(usernameSender); |     const sender = await fetchTeacher(usernameSender); | ||||||
|     const receiver = await fetchTeacher(usernameReceiver); |     const receiver = await fetchTeacher(usernameReceiver); | ||||||
|  | @ -66,6 +71,3 @@ export async function deleteInvitationFor(usernameSender: string, usernameReceiv | ||||||
| 
 | 
 | ||||||
|     return mapToTeacherInvitationDTO(invitation); |     return mapToTeacherInvitationDTO(invitation); | ||||||
| } | } | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|  |  | ||||||
|  | @ -1,13 +1,9 @@ | ||||||
| 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 { | import { createInvitationHandler, deleteInvitationForHandler, getAllInvitationsHandler } from '../../src/controllers/teacher-invitations'; | ||||||
|     createInvitationHandler, | import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation'; | ||||||
|     deleteInvitationForHandler, | import { getClassHandler } from '../../src/controllers/classes'; | ||||||
|     getAllInvitationsHandler |  | ||||||
| } from "../../src/controllers/teacher-invitations"; |  | ||||||
| import {TeacherInvitationData} from "@dwengo-1/common/interfaces/teacher-invitation"; |  | ||||||
| import {getClassHandler} from "../../src/controllers/classes"; |  | ||||||
| 
 | 
 | ||||||
| describe('Teacher controllers', () => { | describe('Teacher controllers', () => { | ||||||
|     let req: Partial<Request>; |     let req: Partial<Request>; | ||||||
|  | @ -50,8 +46,9 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|     it('Create and delete invitation', async () => { |     it('Create and delete invitation', async () => { | ||||||
|         const body = { |         const body = { | ||||||
|             sender: 'LimpBizkit', receiver: 'testleerkracht1', |             sender: 'LimpBizkit', | ||||||
|             class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' |             receiver: 'testleerkracht1', | ||||||
|  |             class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||||
|         } as TeacherInvitationData; |         } as TeacherInvitationData; | ||||||
|         req = { body }; |         req = { body }; | ||||||
| 
 | 
 | ||||||
|  | @ -59,9 +56,11 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|         req = { |         req = { | ||||||
|             params: { |             params: { | ||||||
|             sender: 'LimpBizkit', receiver: 'testleerkracht1', |                 sender: 'LimpBizkit', | ||||||
|                 classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' |                 receiver: 'testleerkracht1', | ||||||
|             }, body: { accepted: 'false' } |                 classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||||
|  |             }, | ||||||
|  |             body: { accepted: 'false' }, | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         await deleteInvitationForHandler(req as Request, res as Response); |         await deleteInvitationForHandler(req as Request, res as Response); | ||||||
|  | @ -69,8 +68,9 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|     it('Create and accept invitation', async () => { |     it('Create and accept invitation', async () => { | ||||||
|         const body = { |         const body = { | ||||||
|             sender: 'LimpBizkit', receiver: 'testleerkracht1', |             sender: 'LimpBizkit', | ||||||
|             class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' |             receiver: 'testleerkracht1', | ||||||
|  |             class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||||
|         } as TeacherInvitationData; |         } as TeacherInvitationData; | ||||||
|         req = { body }; |         req = { body }; | ||||||
| 
 | 
 | ||||||
|  | @ -78,16 +78,20 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|         req = { |         req = { | ||||||
|             params: { |             params: { | ||||||
|                 sender: 'LimpBizkit', receiver: 'testleerkracht1', |                 sender: 'LimpBizkit', | ||||||
|                 classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' |                 receiver: 'testleerkracht1', | ||||||
|             }, body: { accepted: 'true' } |                 classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||||
|  |             }, | ||||||
|  |             body: { accepted: 'true' }, | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         await deleteInvitationForHandler(req as Request, res as Response); |         await deleteInvitationForHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         req = {params: { |         req = { | ||||||
|             id: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89' |             params: { | ||||||
|         }}; |                 id: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||||
|  |             }, | ||||||
|  |         }; | ||||||
| 
 | 
 | ||||||
|         await getClassHandler(req as Request, res as Response); |         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 { makeTestQuestions } from './test_assets/questions/questions.testdata.js'; | ||||||
| import { makeTestAnswers } from './test_assets/questions/answers.testdata.js'; | import { makeTestAnswers } from './test_assets/questions/answers.testdata.js'; | ||||||
| import { makeTestSubmissions } from './test_assets/assignments/submission.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> { | export async function setupTestApp(): Promise<void> { | ||||||
|     dotenv.config({ path: '.env.test' }); |     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"; | import type { TeacherInvitationData, TeacherInvitationDTO } from "@dwengo-1/common/interfaces/teacher-invitation"; | ||||||
| 
 | 
 | ||||||
| export interface TeacherInvitationsResponse { | export interface TeacherInvitationsResponse { | ||||||
|     invitations: TeacherInvitationDTO[] |     invitations: TeacherInvitationDTO[]; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface TeacherInvitationResponse { | export interface TeacherInvitationResponse { | ||||||
|     invitation: TeacherInvitationDTO |     invitation: TeacherInvitationDTO; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class TeacherInvitationController extends BaseController { | export class TeacherInvitationController extends BaseController { | ||||||
|  |  | ||||||
|  | @ -1,15 +1,10 @@ | ||||||
| import { | import { useMutation, useQuery, type UseMutationReturnType, type UseQueryReturnType } from "@tanstack/vue-query"; | ||||||
|     useMutation, |  | ||||||
|     useQuery, |  | ||||||
|     type UseMutationReturnType, |  | ||||||
|     type UseQueryReturnType, |  | ||||||
| } from "@tanstack/vue-query"; |  | ||||||
| import { computed, toValue } from "vue"; | import { computed, toValue } from "vue"; | ||||||
| import type { MaybeRefOrGetter } from "vue"; | import type { MaybeRefOrGetter } from "vue"; | ||||||
| import { | import { | ||||||
|     TeacherInvitationController, |     TeacherInvitationController, | ||||||
|     type TeacherInvitationResponse, |     type TeacherInvitationResponse, | ||||||
|     type TeacherInvitationsResponse |     type TeacherInvitationsResponse, | ||||||
| } from "@/controllers/teacher-invitations.ts"; | } from "@/controllers/teacher-invitations.ts"; | ||||||
| import type { TeacherInvitationData } from "@dwengo-1/common/dist/interfaces/teacher-invitation.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 { TeacherDTO } from "@dwengo-1/common/dist/interfaces/teacher.ts"; | ||||||
|  | @ -19,47 +14,67 @@ const controller = new TeacherInvitationController(); | ||||||
| /** | /** | ||||||
|     All the invitations the teacher send |     All the invitations the teacher send | ||||||
| **/ | **/ | ||||||
| export function useTeacherInvitationsByQuery(username: MaybeRefOrGetter<string | undefined> | export function useTeacherInvitationsByQuery( | ||||||
|  |     username: MaybeRefOrGetter<string | undefined>, | ||||||
| ): UseQueryReturnType<TeacherInvitationsResponse, Error> { | ): UseQueryReturnType<TeacherInvitationsResponse, Error> { | ||||||
|     return useQuery({ |     return useQuery({ | ||||||
|         queryFn: computed(async () => controller.getAll(toValue(username), true)), |         queryFn: computed(async () => controller.getAll(toValue(username), true)), | ||||||
|         enabled: () => Boolean(toValue(username)), |         enabled: () => Boolean(toValue(username)), | ||||||
|     }) |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|     All the pending invitations send to this teacher |     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> { | ): UseQueryReturnType<TeacherInvitationsResponse, Error> { | ||||||
|     return useQuery({ |     return useQuery({ | ||||||
|         queryFn: computed(async () => controller.getAll(toValue(username), false)), |         queryFn: computed(async () => controller.getAll(toValue(username), false)), | ||||||
|         enabled: () => Boolean(toValue(username)), |         enabled: () => Boolean(toValue(username)), | ||||||
|     }) |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function useCreateTeacherInvitationMutation(): UseMutationReturnType<TeacherInvitationResponse, Error, TeacherDTO, unknown>{ | export function useCreateTeacherInvitationMutation(): UseMutationReturnType< | ||||||
|  |     TeacherInvitationResponse, | ||||||
|  |     Error, | ||||||
|  |     TeacherDTO, | ||||||
|  |     unknown | ||||||
|  | > { | ||||||
|     return useMutation({ |     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({ |     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({ |     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({ |     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" |                         :key="i.classId" | ||||||
|                     > |                     > | ||||||
|                         <td> |                         <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> | ||||||
|                         <td>{{ (i.sender as TeacherDTO).firstName + " " + (i.sender as TeacherDTO).lastName }}</td> |                         <td>{{ (i.sender as TeacherDTO).firstName + " " + (i.sender as TeacherDTO).lastName }}</td> | ||||||
|                         <td class="text-right"> |                         <td class="text-right"> | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Lint Action
						Lint Action