Skip to content
Snippets Groups Projects
Commit 8ccd6676 authored by Josh Everett's avatar Josh Everett
Browse files

Added logging for fetching notification

parent fd7f7c20
No related branches found
No related tags found
Loading
......@@ -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}");
})
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment