Skip to content

Commit

Permalink
Merge pull request #108 from dvishal485/main
Browse files Browse the repository at this point in the history
notification delivery impl
  • Loading branch information
dvishal485 authored Aug 26, 2024
2 parents f927f7c + e94ef57 commit 1ed64ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 13 additions & 11 deletions src/api/controllers/notificationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ export const push_notification = async (notification: ClientNotification) => {
});
};

export const test_notif = asyncErrorHandler(async (req, res, _next) => {
await push_notification({
title: "Test notification",
description: "This is a test notification",
actions: [],
});
res.json({
done: true,
});
});

export const save_notif = asyncErrorHandler(async (req, res, _next) => {
if (req.body.secret != process.env.NOTIF_SECRET) {
throw new CustomError("Invalid secret", StatusCode.BAD_REQUEST);
Expand Down Expand Up @@ -209,6 +198,19 @@ export const save_notif = asyncErrorHandler(async (req, res, _next) => {
status: "success",
message: "Notification saved successfully",
});
res.end();

if (notifications.length === 0) return;

if (notifications.length > 5) {
push_notification({
title: "DTU Website Update",
description: "Multiple updates were made to the website",
actions: [],
}).then(console.log);
} else {
notifications.forEach((n) => push_notification(n).then(console.log));
}
});

export const subscribe = asyncErrorHandler(async (req, res, _next) => {
Expand Down
2 changes: 0 additions & 2 deletions src/api/routes/notificationRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import {
get_notif,
save_notif,
subscribe,
test_notif,
} from "../controllers/notificationController";

const router = express.Router();

router.route("/").get(get_notif);
router.route("/subscribe").post(subscribe);
router.route("/save").post(save_notif);
router.route("/test_notif").get(test_notif);

export default router;

0 comments on commit 1ed64ec

Please sign in to comment.