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:
gorkem-bwlandClaude committed 2025-10-12 21:11:20 -04:00
1 parent 97a14ed926
commit 27d37ece7d
6 files changed
+50

No files matched your search

@@ -452,6 +452,24 @@ class MonitorController extends BaseController {
SERVICE_NAME, SERVICE_NAME,
"getAllGames" "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; export default MonitorController;
+9
View File
@@ -128,6 +128,15 @@ const MonitorSchema = mongoose.Schema(
gameId: { gameId: {
type: String, type: String,
}, },
group: {
type: String,
trim: true,
maxLength: 50,
default: null,
set: function(value) {
return value && value.trim() ? value.trim() : null;
}
},
}, },
{ {
timestamps: true, timestamps: true,
+15
View File
@@ -573,6 +573,21 @@ class MonitorModule {
throw error; 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; export default MonitorModule;
+1
View File
@@ -18,6 +18,7 @@ class MonitorRoutes {
this.router.get("/team", this.monitorController.getMonitorsByTeamId); this.router.get("/team", this.monitorController.getMonitorsByTeamId);
this.router.get("/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId); this.router.get("/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId);
this.router.get("/team/summary", this.monitorController.getMonitorsAndSummaryByTeamId); this.router.get("/team/summary", this.monitorController.getMonitorsAndSummaryByTeamId);
this.router.get("/team/groups", this.monitorController.getGroupsByTeamId);
// Uptime routes // Uptime routes
this.router.get("/uptime/details/:monitorId", this.monitorController.getUptimeDetailsById); this.router.get("/uptime/details/:monitorId", this.monitorController.getUptimeDetailsById);
@@ -267,6 +267,11 @@ class MonitorService {
getAllGames = () => { getAllGames = () => {
return this.games; return this.games;
}; };
getGroupsByTeamId = async ({ teamId }) => {
const groups = await this.db.monitorModule.getGroupsByTeamId({ teamId });
return groups;
};
} }
export default MonitorService; export default MonitorService;
+2
View File
@@ -174,6 +174,7 @@ const createMonitorBodyValidation = joi.object({
expectedValue: joi.string().allow(""), expectedValue: joi.string().allow(""),
matchMethod: joi.string(), matchMethod: joi.string(),
gameId: joi.string().allow(""), gameId: joi.string().allow(""),
group: joi.string().max(50).trim().allow(null, "").optional(),
}); });
const createMonitorsBodyValidation = joi.array().items( const createMonitorsBodyValidation = joi.array().items(
@@ -203,6 +204,7 @@ const editMonitorBodyValidation = joi.object({
usage_temperature: joi.number(), usage_temperature: joi.number(),
}), }),
gameId: joi.string(), gameId: joi.string(),
group: joi.string().max(50).trim().allow(null, "").optional(),
}); });
const pauseMonitorParamValidation = joi.object({ const pauseMonitorParamValidation = joi.object({