Merge pull request #3019 from bluewave-labs/feature/monitor-grouping-backend

feat: Add monitor grouping functionality (Backend)
This commit is contained in:
Alexander Holliday
2025-10-14 09:05:34 -07:00
committed by GitHub
6 changed files with 50 additions and 0 deletions
@@ -452,6 +452,24 @@ class MonitorController extends BaseController {
SERVICE_NAME,
"getAllGames"
);
getGroupsByTeamId = this.asyncHandler(
async (req, res) => {
const teamId = req?.user?.teamId;
if (!teamId) {
throw this.errorService.createBadRequestError("Team ID is required");
}
const groups = await this.monitorService.getGroupsByTeamId({ teamId });
return res.success({
msg: "OK",
data: groups,
});
},
SERVICE_NAME,
"getGroupsByTeamId"
);
}
export default MonitorController;
+9
View File
@@ -128,6 +128,15 @@ const MonitorSchema = mongoose.Schema(
gameId: {
type: String,
},
group: {
type: String,
trim: true,
maxLength: 50,
default: null,
set: function (value) {
return value && value.trim() ? value.trim() : null;
},
},
},
{
timestamps: true,
+15
View File
@@ -573,6 +573,21 @@ class MonitorModule {
throw error;
}
};
getGroupsByTeamId = async ({ teamId }) => {
try {
const groups = await this.Monitor.distinct("group", {
teamId: new this.ObjectId(teamId),
group: { $ne: null, $ne: "" },
});
return groups.filter(Boolean).sort();
} catch (error) {
error.service = SERVICE_NAME;
error.method = "getGroupsByTeamId";
throw error;
}
};
}
export default MonitorModule;
+1
View File
@@ -18,6 +18,7 @@ class MonitorRoutes {
this.router.get("/team", this.monitorController.getMonitorsByTeamId);
this.router.get("/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId);
this.router.get("/team/summary", this.monitorController.getMonitorsAndSummaryByTeamId);
this.router.get("/team/groups", this.monitorController.getGroupsByTeamId);
// Uptime routes
this.router.get("/uptime/details/:monitorId", this.monitorController.getUptimeDetailsById);
@@ -267,6 +267,11 @@ class MonitorService {
getAllGames = () => {
return this.games;
};
getGroupsByTeamId = async ({ teamId }) => {
const groups = await this.db.monitorModule.getGroupsByTeamId({ teamId });
return groups;
};
}
export default MonitorService;
+2
View File
@@ -174,6 +174,7 @@ const createMonitorBodyValidation = joi.object({
expectedValue: joi.string().allow(""),
matchMethod: joi.string(),
gameId: joi.string().allow(""),
group: joi.string().max(50).trim().allow(null, "").optional(),
});
const createMonitorsBodyValidation = joi.array().items(
@@ -203,6 +204,7 @@ const editMonitorBodyValidation = joi.object({
usage_temperature: joi.number(),
}),
gameId: joi.string(),
group: joi.string().max(50).trim().allow(null, "").optional(),
});
const pauseMonitorParamValidation = joi.object({