From 966fb825108e6ebf0cf7ab2f8b07c8501eef0315 Mon Sep 17 00:00:00 2001 From: serezhaolshan Date: Tue, 8 Oct 2024 16:32:06 +0300 Subject: [PATCH] feat: add delay for sending notification for test --- src/router/watcher.router.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/router/watcher.router.ts b/src/router/watcher.router.ts index 0237aeb..091c9ae 100644 --- a/src/router/watcher.router.ts +++ b/src/router/watcher.router.ts @@ -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; \ No newline at end of file