feat: teacher invitation middelware + extra error catchings

This commit is contained in:
Gabriellvl 2025-04-18 22:33:22 +02:00
parent ac399153b6
commit f671341bad
4 changed files with 43 additions and 5 deletions

View file

@ -0,0 +1,23 @@
import {authorize} from "./auth-checks";
import {AuthenticationInfo} from "../authentication-info";
import {AuthenticatedRequest} from "../authenticated-request";
export const onlyAllowSenderOrReceiver = authorize(
(auth: AuthenticationInfo, req: AuthenticatedRequest) =>
req.params.sender === auth.username || req.params.receiver === auth.username
);
export const onlyAllowSender = authorize(
(auth: AuthenticationInfo, req: AuthenticatedRequest) =>
req.params.sender === auth.username
);
export const onlyAllowSenderBody = authorize(
(auth: AuthenticationInfo, req: AuthenticatedRequest) =>
req.body.sender === auth.username
);
export const onlyAllowReceiverBody = authorize(
(auth: AuthenticationInfo, req: AuthenticatedRequest) =>
req.body.receiver === auth.username
);