Merge pull request #3019 from bluewave-labs/feature/monitor-grouping-backend
feat: Add monitor grouping functionality (Backend)
This commit is contained in:
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;
|
||||||
@@ -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,
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -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;
|
||||||
@@ -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({
|
||||||
|
|||||||
Reference in new issue
Block a user