Skip to content

Commit

Permalink
feat: add /admin/notification endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Kan-A-Pesh committed Nov 5, 2024
1 parent 58d9e60 commit 2e60ccd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions routes/admin/notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Logger from "@/log/logger";
import Status from "@/models/status";
import SocketIO from "@/socket/socket";
import { NextFunction, Request, Response } from "express";
import { z } from "zod";

const body = z.object({
title: z.string(),
message: z.string(),
iconUrl: z.string().optional()
});

export default async function Route_Admin_Notification(req: Request, res: Response, next: NextFunction) {
const bodyPayload = body.safeParse(req.body);

if (!bodyPayload.success) {
return Status.send(req, next, {
status: 400,
error: "errors.validation"
});
}

Logger.info(
`Route_Admin_Notification | Dispatching notification: ${bodyPayload.data.title} - ${bodyPayload.data.message}`
);
SocketIO.sendRawNotification(bodyPayload.data.title, bodyPayload.data.message, bodyPayload.data.iconUrl);

return Status.send(req, next, {
status: 204
});
}
3 changes: 3 additions & 0 deletions routes/admin/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Router } from "express";
import adminChallengesRouter from "./challenges/router";
import adminClubsRouter from "./clubs/router";
import adminGrantersRouter from "./granters/router";
import Route_Admin_Notification from "./notification";

const adminRouter = Router();

Expand All @@ -13,4 +14,6 @@ adminRouter.use("/clubs", adminClubsRouter);
adminRouter.use("/challenges", adminChallengesRouter);
adminRouter.use("/granters", adminGrantersRouter);

adminRouter.post("/notification", Route_Admin_Notification);

export default adminRouter;

0 comments on commit 2e60ccd

Please sign in to comment.