Skip to content

Commit

Permalink
feat: add delay for sending notification for test
Browse files Browse the repository at this point in the history
  • Loading branch information
serezhaolshan committed Oct 8, 2024
1 parent cc45624 commit 966fb82
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/router/watcher.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,26 @@ const routes = (app: Application, container: DependencyContainer) => {
watcherNetwork.updateWatcherPushToken.bind(watcherNetwork)
);

app.post("/api/v1/send-notification", (req, res) => {
app.post("/api/v1/send-notification", async (req, res) => {
const { title, body, pushToken, data } = req.body;
setTimeout(() => {
container.resolve(NotificationService).sendNotification({
title,
body,
pushToken,
data
}).then((result) => {
res.send(result);
}).catch((error) => {
res.status(500).send(error);
});
}, 5000);
await sleep(5000);
container.resolve(NotificationService).sendNotification({
title,
body,
pushToken,
data
}).then((result) => {
res.send(result);
}).catch((error) => {
res.status(500).send(error);
});
});
};

function sleep(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

export default routes;

0 comments on commit 966fb82

Please sign in to comment.