fix: put route frontend + veranderingen delete
This commit is contained in:
		
							parent
							
								
									f3d2b3313c
								
							
						
					
					
						commit
						ef04f6c7af
					
				
					 4 changed files with 40 additions and 42 deletions
				
			
		|  | @ -5,11 +5,12 @@ import { | ||||||
|     createInvitationHandler, |     createInvitationHandler, | ||||||
|     deleteInvitationHandler, |     deleteInvitationHandler, | ||||||
|     getAllInvitationsHandler, |     getAllInvitationsHandler, | ||||||
|     getInvitationHandler |     getInvitationHandler, updateInvitationHandler | ||||||
| } from '../../src/controllers/teacher-invitations'; | } from '../../src/controllers/teacher-invitations'; | ||||||
| import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation'; | import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation'; | ||||||
| import { getClassHandler } from '../../src/controllers/classes'; | import { getClassHandler } from '../../src/controllers/classes'; | ||||||
| import {BadRequestException} from "../../src/exceptions/bad-request-exception"; | import {BadRequestException} from "../../src/exceptions/bad-request-exception"; | ||||||
|  | import {ClassStatus} from "@dwengo-1/common/util/class-join-request"; | ||||||
| 
 | 
 | ||||||
| describe('Teacher controllers', () => { | describe('Teacher controllers', () => { | ||||||
|     let req: Partial<Request>; |     let req: Partial<Request>; | ||||||
|  | @ -95,28 +96,19 @@ describe('Teacher controllers', () => { | ||||||
|             .rejects.toThrowError(BadRequestException); |             .rejects.toThrowError(BadRequestException); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     /* |  | ||||||
| 
 | 
 | ||||||
|     it('Create and accept invitation', async () => { |     it('Accept invitation', async () => { | ||||||
|         const body = { |         const body = { | ||||||
|             sender: 'LimpBizkit', |             sender: 'LimpBizkit', | ||||||
|             receiver: 'testleerkracht1', |             receiver: 'FooFighters', | ||||||
|             class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', |             class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', | ||||||
|         } as TeacherInvitationData; |         } as TeacherInvitationData; | ||||||
|         req = { body }; |         req = { body }; | ||||||
| 
 | 
 | ||||||
|         await createInvitationHandler(req as Request, res as Response); |         await updateInvitationHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         req = { |         const result1 = jsonMock.mock.lastCall?.[0]; | ||||||
|             params: { |         expect(result1.invitation.status).toEqual(ClassStatus.Accepted); | ||||||
|                 sender: 'LimpBizkit', |  | ||||||
|                 receiver: 'testleerkracht1', |  | ||||||
|                 classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89', |  | ||||||
|             }, |  | ||||||
|             body: { accepted: 'true' }, |  | ||||||
|         }; |  | ||||||
| 
 |  | ||||||
|         await deleteInvitationHandler(req as Request, res as Response); |  | ||||||
| 
 | 
 | ||||||
|         req = { |         req = { | ||||||
|             params: { |             params: { | ||||||
|  | @ -127,8 +119,8 @@ describe('Teacher controllers', () => { | ||||||
|         await getClassHandler(req as Request, res as Response); |         await getClassHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         const result = jsonMock.mock.lastCall?.[0]; |         const result = jsonMock.mock.lastCall?.[0]; | ||||||
|         expect(result.class.teachers).toContain('testleerkracht1'); |         expect(result.class.teachers).toContain('FooFighters'); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|      */ | 
 | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -12,5 +12,5 @@ export interface TeacherInvitationData { | ||||||
|     sender: string; |     sender: string; | ||||||
|     receiver: string; |     receiver: string; | ||||||
|     class: string; |     class: string; | ||||||
|     accepted?: boolean; |     accepted?: boolean; // use for put requests, else skip
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -14,15 +14,23 @@ export class TeacherInvitationController extends BaseController { | ||||||
|         super("teachers/invitations"); |         super("teachers/invitations"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async getAll(username: string, by: boolean): Promise<TeacherInvitationsResponse> { |     async getAll(username: string, sent: boolean): Promise<TeacherInvitationsResponse> { | ||||||
|         return this.get<TeacherInvitationsResponse>(`/${username}`, { by }); |         return this.get<TeacherInvitationsResponse>(`/${username}`, { sent }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async getBy(data: TeacherInvitationData): Promise<TeacherInvitationResponse> { | ||||||
|  |         return this.get<TeacherInvitationResponse>(`/${data.sender}/${data.receiver}/${data.class}`) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async create(data: TeacherInvitationData): Promise<TeacherInvitationResponse> { |     async create(data: TeacherInvitationData): Promise<TeacherInvitationResponse> { | ||||||
|         return this.post<TeacherInvitationResponse>("/", data); |         return this.post<TeacherInvitationResponse>("/", data); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async respond(data: TeacherInvitationData, accepted: boolean): Promise<TeacherInvitationResponse> { |     async remove(data: TeacherInvitationData): Promise<TeacherInvitationResponse> { | ||||||
|         return this.delete<TeacherInvitationResponse>(`/${data.sender}/${data.receiver}/${data.class}`, { accepted }); |         return this.delete<TeacherInvitationResponse>(`/${data.sender}/${data.receiver}/${data.class}`); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async respond(data: TeacherInvitationData) { | ||||||
|  |         return this.put<TeacherInvitationResponse>("/", data); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,15 +6,15 @@ import { | ||||||
|     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/interfaces/teacher-invitation"; | ||||||
| import type { TeacherDTO } from "@dwengo-1/common/dist/interfaces/teacher.ts"; | import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; | ||||||
| 
 | 
 | ||||||
| const controller = new TeacherInvitationController(); | const controller = new TeacherInvitationController(); | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|     All the invitations the teacher send |     All the invitations the teacher sent | ||||||
| **/ | **/ | ||||||
| export function useTeacherInvitationsByQuery( | export function useTeacherInvitationsSentQuery( | ||||||
|     username: MaybeRefOrGetter<string | undefined>, |     username: MaybeRefOrGetter<string | undefined>, | ||||||
| ): UseQueryReturnType<TeacherInvitationsResponse, Error> { | ): UseQueryReturnType<TeacherInvitationsResponse, Error> { | ||||||
|     return useQuery({ |     return useQuery({ | ||||||
|  | @ -24,9 +24,9 @@ export function useTeacherInvitationsByQuery( | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|     All the pending invitations send to this teacher |     All the pending invitations sent to this teacher | ||||||
|  */ |  */ | ||||||
| export function useTeacherInvitationsForQuery( | export function useTeacherInvitationsReceivedQuery( | ||||||
|     username: MaybeRefOrGetter<string | undefined>, |     username: MaybeRefOrGetter<string | undefined>, | ||||||
| ): UseQueryReturnType<TeacherInvitationsResponse, Error> { | ): UseQueryReturnType<TeacherInvitationsResponse, Error> { | ||||||
|     return useQuery({ |     return useQuery({ | ||||||
|  | @ -35,6 +35,15 @@ export function useTeacherInvitationsForQuery( | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export function useTeacherInvitationQuery( | ||||||
|  |     data: MaybeRefOrGetter<TeacherInvitationData | undefined>, | ||||||
|  | ): UseQueryReturnType<TeacherInvitationResponse, Error> { | ||||||
|  |     return useQuery({ | ||||||
|  |         queryFn: computed(async () => controller.getBy(toValue(data))), | ||||||
|  |         enabled: () => Boolean(toValue(data)), | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export function useCreateTeacherInvitationMutation(): UseMutationReturnType< | export function useCreateTeacherInvitationMutation(): UseMutationReturnType< | ||||||
|     TeacherInvitationResponse, |     TeacherInvitationResponse, | ||||||
|     Error, |     Error, | ||||||
|  | @ -46,25 +55,14 @@ export function useCreateTeacherInvitationMutation(): UseMutationReturnType< | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function useAcceptTeacherInvitationMutation(): UseMutationReturnType< | export function useRespondTeacherInvitationMutation(): UseMutationReturnType< | ||||||
|     TeacherInvitationResponse, |     TeacherInvitationResponse, | ||||||
|     Error, |     Error, | ||||||
|     TeacherDTO, |     TeacherDTO, | ||||||
|     unknown |     unknown | ||||||
| > { | > { | ||||||
|     return useMutation({ |     return useMutation({ | ||||||
|         mutationFn: async (data: TeacherInvitationData) => controller.respond(data, true), |         mutationFn: async (data: TeacherInvitationData) => controller.respond(data), | ||||||
|     }); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export function useDeclineTeacherInvitationMutation(): UseMutationReturnType< |  | ||||||
|     TeacherInvitationResponse, |  | ||||||
|     Error, |  | ||||||
|     TeacherDTO, |  | ||||||
|     unknown |  | ||||||
| > { |  | ||||||
|     return useMutation({ |  | ||||||
|         mutationFn: async (data: TeacherInvitationData) => controller.respond(data, false), |  | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -75,6 +73,6 @@ export function useDeleteTeacherInvitationMutation(): UseMutationReturnType< | ||||||
|     unknown |     unknown | ||||||
| > { | > { | ||||||
|     return useMutation({ |     return useMutation({ | ||||||
|         mutationFn: async (data: TeacherInvitationData) => controller.respond(data, false), |         mutationFn: async (data: TeacherInvitationData) => controller.remove(data), | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl