remove teamId from checks

This commit is contained in:
Alex Holliday
2025-06-13 12:04:39 +08:00
parent 9da3d3ef55
commit d2233d2e3e
4 changed files with 53 additions and 26 deletions

View File

@@ -54,7 +54,18 @@ class CheckController {
}
try {
const result = await this.db.getChecksByMonitor(req);
const { monitorId } = req.params;
let { type, sortOrder, dateRange, filter, page, rowsPerPage, status } = req.query;
const result = await this.db.getChecksByMonitor({
monitorId,
type,
sortOrder,
dateRange,
filter,
page,
rowsPerPage,
status,
});
return res.success({
msg: this.stringService.checkGet,
@@ -74,8 +85,17 @@ class CheckController {
return;
}
try {
const checkData = await this.db.getChecksByTeam(req);
let { sortOrder, dateRange, filter, page, rowsPerPage } = req.query;
const { teamId } = req.user;
const checkData = await this.db.getChecksByTeam({
sortOrder,
dateRange,
filter,
page,
rowsPerPage,
teamId,
});
return res.success({
msg: this.stringService.checkGet,
data: checkData,
@@ -114,7 +134,8 @@ class CheckController {
}
try {
const deletedCount = await this.db.deleteChecksByTeamId(req.params.teamId);
const { teamId } = req.user;
const deletedCount = await this.db.deleteChecksByTeamId(teamId);
return res.success({
msg: this.stringService.checkDelete,
@@ -137,9 +158,7 @@ class CheckController {
try {
// Get user's teamId
const token = getTokenFromHeaders(req.headers);
const { jwtSecret } = this.settingsService.getSettings();
const { teamId } = jwt.verify(token, jwtSecret);
const { teamId } = req.user;
const ttl = parseInt(req.body.ttl, 10) * SECONDS_PER_DAY;
await this.db.updateChecksTTL(teamId, ttl);

View File

@@ -57,10 +57,17 @@ const createChecks = async (checks) => {
* @returns {Promise<Array<Check>>}
* @throws {Error}
*/
const getChecksByMonitor = async (req) => {
const getChecksByMonitor = async ({
monitorId,
type,
sortOrder,
dateRange,
filter,
page,
rowsPerPage,
status,
}) => {
try {
const { monitorId } = req.params;
let { type, sortOrder, dateRange, filter, page, rowsPerPage, status } = req.query;
status = typeof status !== "undefined" ? false : undefined;
page = parseInt(page);
rowsPerPage = parseInt(rowsPerPage);
@@ -142,12 +149,17 @@ const getChecksByMonitor = async (req) => {
}
};
const getChecksByTeam = async (req) => {
const getChecksByTeam = async ({
sortOrder,
dateRange,
filter,
page,
rowsPerPage,
teamId,
}) => {
try {
let { sortOrder, dateRange, filter, page, rowsPerPage } = req.query;
page = parseInt(page);
rowsPerPage = parseInt(rowsPerPage);
const { teamId } = req.params;
const matchStage = {
teamId: ObjectId.createFromHexString(teamId),
status: false,

View File

@@ -11,7 +11,15 @@ class CheckRoutes {
}
initRoutes() {
this.router.get("/team", this.checkController.getChecksByTeam);
this.router.delete(
"/team",
isAllowed(["admin", "superadmin"]),
this.checkController.deleteChecksByTeamId
);
this.router.get("/:monitorId", this.checkController.getChecksByMonitor);
this.router.post(
"/:monitorId",
verifyOwnership(Monitor, "monitorId"),
@@ -23,14 +31,6 @@ class CheckRoutes {
this.checkController.deleteChecks
);
this.router.get("/team/:teamId", this.checkController.getChecksByTeam);
this.router.delete(
"/team/:teamId",
isAllowed(["admin", "superadmin"]),
this.checkController.deleteChecksByTeamId
);
this.router.put(
"/team/ttl",
isAllowed(["admin", "superadmin"]),

View File

@@ -301,9 +301,7 @@ const getChecksQueryValidation = joi.object({
status: joi.boolean(),
});
const getTeamChecksParamValidation = joi.object({
teamId: joi.string().required(),
});
const getTeamChecksParamValidation = joi.object({});
const getTeamChecksQueryValidation = joi.object({
sortOrder: joi.string().valid("asc", "desc"),
@@ -319,9 +317,7 @@ const deleteChecksParamValidation = joi.object({
monitorId: joi.string().required(),
});
const deleteChecksByTeamIdParamValidation = joi.object({
teamId: joi.string().required(),
});
const deleteChecksByTeamIdParamValidation = joi.object({});
const updateChecksTTLBodyValidation = joi.object({
ttl: joi.number().required(),