Skip to content

Commit

Permalink
pushed notif revoke
Browse files Browse the repository at this point in the history
  • Loading branch information
AydanPirani committed Feb 24, 2024
1 parent d78b50a commit e36346b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/services/notification/notification-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RouterError } from "../../middleware/error-handler.js";
import { StatusCode } from "status-code-enum";
import Models from "../../database/models.js";
import { JwtPayload } from "../auth/auth-models.js";
import { hasStaffPerms } from "../auth/auth-lib.js";
import { hasAdminPerms, hasStaffPerms } from "../auth/auth-lib.js";
import { NotificationSendFormat, isValidNotificationSendFormat } from "./notification-formats.js";
import { StaffShift } from "database/staff-db.js";
import { NotificationsMiddleware } from "../../middleware/fcm.js";
Expand Down Expand Up @@ -50,6 +50,11 @@ notificationsRouter.post(
const payload: JwtPayload = res.locals.payload as JwtPayload;
const admin = res.locals.fcm;
const sendRequest = req.body as { title: string; body: string; userIds: string[] };

if (!hasAdminPerms(payload)) {
return next(new RouterError(StatusCode.ClientErrorForbidden, "Forbidden"));
}

const targetUserIds = sendRequest.userIds;
if (!targetUserIds || !sendRequest.body || !sendRequest.title) {
return next(new RouterError(StatusCode.ClientErrorBadRequest, "InvalidFormat"));
Expand Down Expand Up @@ -96,7 +101,7 @@ notificationsRouter.post("/send/", strongJwtVerification, async (req: Request, r
const startTime = new Date();
const payload: JwtPayload = res.locals.payload as JwtPayload;

if (!hasStaffPerms(payload)) {
if (!hasAdminPerms(payload)) {
return next(new RouterError(StatusCode.ClientErrorForbidden, "Forbidden"));
}

Expand Down

0 comments on commit e36346b

Please sign in to comment.