generated from Kan-A-Pesh/express-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add /admin/notification endpoint
- Loading branch information
1 parent
58d9e60
commit 2e60ccd
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters