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,
|
||||
deleteInvitationHandler,
|
||||
getAllInvitationsHandler,
|
||||
getInvitationHandler
|
||||
getInvitationHandler, updateInvitationHandler
|
||||
} from '../../src/controllers/teacher-invitations';
|
||||
import { TeacherInvitationData } from '@dwengo-1/common/interfaces/teacher-invitation';
|
||||
import { getClassHandler } from '../../src/controllers/classes';
|
||||
import {BadRequestException} from "../../src/exceptions/bad-request-exception";
|
||||
import {ClassStatus} from "@dwengo-1/common/util/class-join-request";
|
||||
|
||||
describe('Teacher controllers', () => {
|
||||
let req: Partial<Request>;
|
||||
|
@ -95,28 +96,19 @@ describe('Teacher controllers', () => {
|
|||
.rejects.toThrowError(BadRequestException);
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
it('Create and accept invitation', async () => {
|
||||
it('Accept invitation', async () => {
|
||||
const body = {
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'testleerkracht1',
|
||||
receiver: 'FooFighters',
|
||||
class: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
} as TeacherInvitationData;
|
||||
req = { body };
|
||||
|
||||
await createInvitationHandler(req as Request, res as Response);
|
||||
await updateInvitationHandler(req as Request, res as Response);
|
||||
|
||||
req = {
|
||||
params: {
|
||||
sender: 'LimpBizkit',
|
||||
receiver: 'testleerkracht1',
|
||||
classId: '34d484a1-295f-4e9f-bfdc-3e7a23d86a89',
|
||||
},
|
||||
body: { accepted: 'true' },
|
||||
};
|
||||
|
||||
await deleteInvitationHandler(req as Request, res as Response);
|
||||
const result1 = jsonMock.mock.lastCall?.[0];
|
||||
expect(result1.invitation.status).toEqual(ClassStatus.Accepted);
|
||||
|
||||
req = {
|
||||
params: {
|
||||
|
@ -127,8 +119,8 @@ describe('Teacher controllers', () => {
|
|||
await getClassHandler(req as Request, res as Response);
|
||||
|
||||
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;
|
||||
receiver: 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");
|
||||
}
|
||||
|
||||
async getAll(username: string, by: boolean): Promise<TeacherInvitationsResponse> {
|
||||
return this.get<TeacherInvitationsResponse>(`/${username}`, { by });
|
||||
async getAll(username: string, sent: boolean): Promise<TeacherInvitationsResponse> {
|
||||
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> {
|
||||
return this.post<TeacherInvitationResponse>("/", data);
|
||||
}
|
||||
|
||||
async respond(data: TeacherInvitationData, accepted: boolean): Promise<TeacherInvitationResponse> {
|
||||
return this.delete<TeacherInvitationResponse>(`/${data.sender}/${data.receiver}/${data.class}`, { accepted });
|
||||
async remove(data: TeacherInvitationData): Promise<TeacherInvitationResponse> {
|
||||
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 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/interfaces/teacher-invitation";
|
||||
import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher";
|
||||
|
||||
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>,
|
||||
): UseQueryReturnType<TeacherInvitationsResponse, Error> {
|
||||
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>,
|
||||
): UseQueryReturnType<TeacherInvitationsResponse, Error> {
|
||||
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<
|
||||
TeacherInvitationResponse,
|
||||
Error,
|
||||
|
@ -46,25 +55,14 @@ export function useCreateTeacherInvitationMutation(): UseMutationReturnType<
|
|||
});
|
||||
}
|
||||
|
||||
export function useAcceptTeacherInvitationMutation(): UseMutationReturnType<
|
||||
export function useRespondTeacherInvitationMutation(): UseMutationReturnType<
|
||||
TeacherInvitationResponse,
|
||||
Error,
|
||||
TeacherDTO,
|
||||
unknown
|
||||
> {
|
||||
return useMutation({
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.respond(data, true),
|
||||
});
|
||||
}
|
||||
|
||||
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),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -75,6 +73,6 @@ export function useDeleteTeacherInvitationMutation(): UseMutationReturnType<
|
|||
unknown
|
||||
> {
|
||||
return useMutation({
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.respond(data, false),
|
||||
mutationFn: async (data: TeacherInvitationData) => controller.remove(data),
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue