From 8ccd667627bdd40aee16e21d47df24b6eba83882 Mon Sep 17 00:00:00 2001 From: Josh Everett <44347292+MrJoshE@users.noreply.github.com> Date: Thu, 20 Apr 2023 15:54:53 +0100 Subject: [PATCH] Added logging for fetching notification --- src/index.js | 12 ++++++------ src/routes/notification.js | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 85fef6b..d4c7f4b 100644 --- a/src/index.js +++ b/src/index.js @@ -8,18 +8,18 @@ const app = express(); const port = process.env.PORT; app.use(express.json()); -app.get("/",(req,res) =>{ +app.get("/", (req, res) => { console.log("testing"); res.send("Hello"); - + }) const notificationRouter = require("./routes/notification"); -app.use("/notification",notificationRouter); +app.use("/notification", notificationRouter); - app.listen(port, function(){ - console.log("Notifcation Microservice is running ..."); - }) +app.listen(port, function () { + console.log("Notifcation Microservice is running at http://localhost:${port}"); +}) diff --git a/src/routes/notification.js b/src/routes/notification.js index b2ef76d..f53ce6e 100644 --- a/src/routes/notification.js +++ b/src/routes/notification.js @@ -18,6 +18,7 @@ const jwtAlgorithm = "HS512"; // retrieve all the notifications for a user that are stored in the database. router.get("/info", async (req, res) => { + console.log("fetching notifications called") try { // Get the JWT secret from the environment variables @@ -39,10 +40,13 @@ router.get("/info", async (req, res) => { // Get the user id from the decoded token payload. const userId = payload.id; + console.log("fetching the notifications for user: " + userId) + // Find all the notifications for the user and return them without the user_id and __v fields. // as this should not be exposed to the user. const notifications = await Notification.find({ user_id: userId }, { user_id: 0, __v: 0 }); + console.log("found notifications for user: " + userId + " " + notifications.length + " notifications found.") res.status(200).send(notifications); -- GitLab