update on joi schema, added logger docs, and updated user model

This commit is contained in:
veyselboybay committed 2024-05-14 23:15:29 -04:00
1 parent 6d9e74b33a
commit ca33fcae91
5 files changed
+34 -11

No files matched your search

+5
View File
@@ -2,6 +2,7 @@ const {
getMonitorsByIdValidation,
getMonitorsByUserIdValidation,
} = require("../validation/joi");
const logger = require('../utils/logger')
// Gets all monitors
const getAllMonitors = async (req, res) => {
@@ -9,6 +10,7 @@ const getAllMonitors = async (req, res) => {
const monitors = await req.db.getAllMonitors();
return res.json({ success: true, msg: "Monitors found", data: monitors });
} catch (error) {
logger.error(error.message, { "service": "monitor" });
return res.status(500).json({ success: false, msg: error.message });
}
};
@@ -27,6 +29,7 @@ const getMonitorById = async (req, res) => {
const monitor = await req.db.getMonitorById(monitorId);
return res.json({ success: true, msg: "Monitor found", data: monitor });
} catch (error) {
logger.error(error.message, { "service": "monitor" });
return res.status(500).json({ success: false, msg: error.message });
}
};
@@ -43,12 +46,14 @@ const getMonitorsByUserId = async (req, res) => {
try {
const userId = req.params.userId;
const monitors = await req.db.getMonitorsByUserId(userId);
logger.info(`Monitors for user ${userId} found`, { "service": "monitor", "userId":userId });
return res.json({
success: true,
msg: `Monitors for user ${userId} found`,
data: monitors,
});
} catch (error) {
logger.error(error.message, { "service": "monitor" });
return res.status(500).json({ success: false, msg: error.message });
}
};