mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-12 04:39:48 -06:00
feat: Add monitor grouping functionality to backend
- Add optional 'group' field to Monitor schema with trimming and validation - Add group validation to Joi schemas for create and edit monitor endpoints - Add GET /api/v1/monitors/team/groups endpoint to fetch unique groups - Implement case-insensitive group filtering in database layer - Support for organizing monitors into collapsible groups 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user