Refactor getMonitorByUserID to getMonitorByTeamID

This commit is contained in:
Alex Holliday committed 2024-08-26 19:38:24 -07:00
1 parent e658b4759a
commit 465c1f9f9e
7 files changed
+26 -26

No files matched your search

@@ -33,9 +33,9 @@ export const getUptimeMonitorsByUserId = createAsyncThunk(
async (token, thunkApi) => { async (token, thunkApi) => {
const user = jwtDecode(token); const user = jwtDecode(token);
try { try {
const res = await networkService.getMonitorsByUserId( const res = await networkService.getMonitorsByTeamId(
token, token,
user._id, user.teamId,
25, 25,
["http", "ping"], ["http", "ping"],
null, null,
+3 -3
View File
@@ -52,9 +52,9 @@ class NetworkService {
* @param {boolean} [normalize] - Whether to normalize the retrieved monitors. * @param {boolean} [normalize] - Whether to normalize the retrieved monitors.
* @returns {Promise<AxiosResponse>} The response from the axios GET request. * @returns {Promise<AxiosResponse>} The response from the axios GET request.
*/ */
async getMonitorsByUserId( async getMonitorsByTeamId(
authToken, authToken,
userId, teamId,
limit, limit,
types, types,
status, status,
@@ -74,7 +74,7 @@ class NetworkService {
if (normalize) params.append("normalize", normalize); if (normalize) params.append("normalize", normalize);
return this.axiosInstance.get( return this.axiosInstance.get(
`/monitors/user/${userId}?${params.toString()}`, `/monitors/team/${teamId}?${params.toString()}`,
{ {
headers: { headers: {
Authorization: `Bearer ${authToken}`, Authorization: `Bearer ${authToken}`,
+9 -9
View File
@@ -1,10 +1,10 @@
const { const {
getMonitorByIdParamValidation, getMonitorByIdParamValidation,
getMonitorByIdQueryValidation, getMonitorByIdQueryValidation,
getMonitorsByUserIdValidation, getMonitorsByTeamIdValidation,
createMonitorBodyValidation, createMonitorBodyValidation,
editMonitorBodyValidation, editMonitorBodyValidation,
getMonitorsByUserIdQueryValidation, getMonitorsByTeamIdQueryValidation,
} = require("../validation/joi"); } = require("../validation/joi");
const sslChecker = require("ssl-checker"); const sslChecker = require("ssl-checker");
@@ -149,10 +149,10 @@ const getMonitorById = async (req, res, next) => {
* @returns {Promise<Express.Response>} * @returns {Promise<Express.Response>}
* @throws {Error} * @throws {Error}
*/ */
const getMonitorsByUserId = async (req, res, next) => { const getMonitorsByTeamId = async (req, res, next) => {
try { try {
await getMonitorsByUserIdValidation.validateAsync(req.params); await getMonitorsByTeamIdValidation.validateAsync(req.params);
await getMonitorsByUserIdQueryValidation.validateAsync(req.query); await getMonitorsByTeamIdQueryValidation.validateAsync(req.query);
} catch (error) { } catch (error) {
error.status = 422; error.status = 422;
error.service = SERVICE_NAME; error.service = SERVICE_NAME;
@@ -163,12 +163,12 @@ const getMonitorsByUserId = async (req, res, next) => {
} }
try { try {
const userId = req.params.userId; const teamId = req.params.teamId;
const monitors = await req.db.getMonitorsByUserId(req, res); const monitors = await req.db.getMonitorsByTeamId(req, res);
return res.json({ return res.json({
success: true, success: true,
msg: successMessages.MONITOR_GET_BY_USER_ID(userId), msg: successMessages.MONITOR_GET_BY_USER_ID(teamId),
data: monitors, data: monitors,
}); });
} catch (error) { } catch (error) {
@@ -342,7 +342,7 @@ module.exports = {
getMonitorStatsById, getMonitorStatsById,
getMonitorCertificate, getMonitorCertificate,
getMonitorById, getMonitorById,
getMonitorsByUserId, getMonitorsByTeamId,
createMonitor, createMonitor,
deleteMonitor, deleteMonitor,
deleteAllMonitors, deleteAllMonitors,
+2 -2
View File
@@ -66,7 +66,7 @@ const {
getAllMonitors, getAllMonitors,
getMonitorStatsById, getMonitorStatsById,
getMonitorById, getMonitorById,
getMonitorsByUserId, getMonitorsByTeamId,
createMonitor, createMonitor,
deleteMonitor, deleteMonitor,
deleteAllMonitors, deleteAllMonitors,
@@ -145,7 +145,7 @@ module.exports = {
getAllMonitors, getAllMonitors,
getMonitorStatsById, getMonitorStatsById,
getMonitorById, getMonitorById,
getMonitorsByUserId, getMonitorsByTeamId,
createMonitor, createMonitor,
deleteMonitor, deleteMonitor,
deleteAllMonitors, deleteAllMonitors,
+4 -4
View File
@@ -287,17 +287,17 @@ const getMonitorById = async (monitorId) => {
}; };
/** /**
* Get monitors by UserID * Get monitors by TeamID
* @async * @async
* @param {Express.Request} req * @param {Express.Request} req
* @param {Express.Response} res * @param {Express.Response} res
* @returns {Promise<Array<Monitor>>} * @returns {Promise<Array<Monitor>>}
* @throws {Error} * @throws {Error}
*/ */
const getMonitorsByUserId = async (req, res) => { const getMonitorsByTeamId = async (req, res) => {
try { try {
let { limit, type, status, sortOrder, normalize } = req.query || {}; let { limit, type, status, sortOrder, normalize } = req.query || {};
const monitorQuery = { userId: req.params.userId }; const monitorQuery = { teamId: req.params.teamId };
if (type !== undefined) { if (type !== undefined) {
const types = Array.isArray(type) ? type : [type]; const types = Array.isArray(type) ? type : [type];
@@ -453,7 +453,7 @@ module.exports = {
getAllMonitors, getAllMonitors,
getMonitorStatsById, getMonitorStatsById,
getMonitorById, getMonitorById,
getMonitorsByUserId, getMonitorsByTeamId,
createMonitor, createMonitor,
deleteMonitor, deleteMonitor,
deleteAllMonitors, deleteAllMonitors,
+1 -1
View File
@@ -7,7 +7,7 @@ router.get("/", monitorController.getAllMonitors);
router.get("/stats/:monitorId", monitorController.getMonitorStatsById); router.get("/stats/:monitorId", monitorController.getMonitorStatsById);
router.get("/certificate/:monitorId", monitorController.getMonitorCertificate); router.get("/certificate/:monitorId", monitorController.getMonitorCertificate);
router.get("/:monitorId", monitorController.getMonitorById); router.get("/:monitorId", monitorController.getMonitorById);
router.get("/user/:userId", monitorController.getMonitorsByUserId); router.get("/team/:teamId", monitorController.getMonitorsByTeamId);
router.post("/", monitorController.createMonitor); router.post("/", monitorController.createMonitor);
router.delete( router.delete(
+5 -5
View File
@@ -160,11 +160,11 @@ const getMonitorByIdQueryValidation = joi.object({
normalize: joi.boolean(), normalize: joi.boolean(),
}); });
const getMonitorsByUserIdValidation = joi.object({ const getMonitorsByTeamIdValidation = joi.object({
userId: joi.string().required(), teamId: joi.string().required(),
}); });
const getMonitorsByUserIdQueryValidation = joi.object({ const getMonitorsByTeamIdQueryValidation = joi.object({
status: joi.boolean(), status: joi.boolean(),
sortOrder: joi.string().valid("asc", "desc"), sortOrder: joi.string().valid("asc", "desc"),
limit: joi.number(), limit: joi.number(),
@@ -347,8 +347,8 @@ module.exports = {
createMonitorBodyValidation, createMonitorBodyValidation,
getMonitorByIdParamValidation, getMonitorByIdParamValidation,
getMonitorByIdQueryValidation, getMonitorByIdQueryValidation,
getMonitorsByUserIdValidation, getMonitorsByTeamIdValidation,
getMonitorsByUserIdQueryValidation, getMonitorsByTeamIdQueryValidation,
editMonitorBodyValidation, editMonitorBodyValidation,
editUserParamValidation, editUserParamValidation,
editUserBodyValidation, editUserBodyValidation,