Skip to content

Commit

Permalink
feat: add saving notifications for test
Browse files Browse the repository at this point in the history
  • Loading branch information
serezhaolshan committed Oct 8, 2024
1 parent 61e823c commit 5f0ce93
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/router/watcher.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DependencyContainer } from "tsyringe";
import { Application } from "express";
import { WatcherNetwork } from "../watcher";
import { NotificationService } from "../notification-sender";
import { HistoricalNotificationsService } from "../historical-notifications";

const routes = (app: Application, container: DependencyContainer) => {

Expand Down Expand Up @@ -48,17 +49,24 @@ const routes = (app: Application, container: DependencyContainer) => {
);

app.post("/api/v1/send-notification", async (req, res) => {
const { title, body, pushToken, data } = req.body;
container.resolve(NotificationService).sendNotification({
title,
body,
pushToken,
data
}).then((result) => {
const { title, body, pushToken, data, watcherId } = req.body;
try {
const result = await container.resolve(NotificationService).sendNotification({
title,
body,
pushToken,
data
});
await container.resolve(HistoricalNotificationsService).addHistoricalNotification(watcherId, {
title,
body,
sent: true,
timestamp: Date.now()
});
res.send(result);
}).catch((error) => {
res.status(500).send(error);
});
} catch (e) {
res.status(500).send(e);
}
});
};

Expand Down

0 comments on commit 5f0ce93

Please sign in to comment.