remove teamId from checks

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

No files matched your search

+25 -6
View File
@@ -54,7 +54,18 @@ class CheckController {
} }
try { 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({ return res.success({
msg: this.stringService.checkGet, msg: this.stringService.checkGet,
@@ -74,8 +85,17 @@ class CheckController {
return; return;
} }
try { 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({ return res.success({
msg: this.stringService.checkGet, msg: this.stringService.checkGet,
data: checkData, data: checkData,
@@ -114,7 +134,8 @@ class CheckController {
} }
try { try {
const deletedCount = await this.db.deleteChecksByTeamId(req.params.teamId); const { teamId } = req.user;
const deletedCount = await this.db.deleteChecksByTeamId(teamId);
return res.success({ return res.success({
msg: this.stringService.checkDelete, msg: this.stringService.checkDelete,
@@ -137,9 +158,7 @@ class CheckController {
try { try {
// Get user's teamId // Get user's teamId
const token = getTokenFromHeaders(req.headers); const { teamId } = req.user;
const { jwtSecret } = this.settingsService.getSettings();
const { teamId } = jwt.verify(token, jwtSecret);
const ttl = parseInt(req.body.ttl, 10) * SECONDS_PER_DAY; const ttl = parseInt(req.body.ttl, 10) * SECONDS_PER_DAY;
await this.db.updateChecksTTL(teamId, ttl); await this.db.updateChecksTTL(teamId, ttl);
+18 -6
View File
@@ -57,10 +57,17 @@ const createChecks = async (checks) => {
* @returns {Promise<Array<Check>>} * @returns {Promise<Array<Check>>}
* @throws {Error} * @throws {Error}
*/ */
const getChecksByMonitor = async (req) => { const getChecksByMonitor = async ({
monitorId,
type,
sortOrder,
dateRange,
filter,
page,
rowsPerPage,
status,
}) => {
try { try {
const { monitorId } = req.params;
let { type, sortOrder, dateRange, filter, page, rowsPerPage, status } = req.query;
status = typeof status !== "undefined" ? false : undefined; status = typeof status !== "undefined" ? false : undefined;
page = parseInt(page); page = parseInt(page);
rowsPerPage = parseInt(rowsPerPage); 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 { try {
let { sortOrder, dateRange, filter, page, rowsPerPage } = req.query;
page = parseInt(page); page = parseInt(page);
rowsPerPage = parseInt(rowsPerPage); rowsPerPage = parseInt(rowsPerPage);
const { teamId } = req.params;
const matchStage = { const matchStage = {
teamId: ObjectId.createFromHexString(teamId), teamId: ObjectId.createFromHexString(teamId),
status: false, status: false,
+8 -8
View File
@@ -11,7 +11,15 @@ class CheckRoutes {
} }
initRoutes() { 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.get("/:monitorId", this.checkController.getChecksByMonitor);
this.router.post( this.router.post(
"/:monitorId", "/:monitorId",
verifyOwnership(Monitor, "monitorId"), verifyOwnership(Monitor, "monitorId"),
@@ -23,14 +31,6 @@ class CheckRoutes {
this.checkController.deleteChecks 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( this.router.put(
"/team/ttl", "/team/ttl",
isAllowed(["admin", "superadmin"]), isAllowed(["admin", "superadmin"]),
+2 -6
View File
@@ -301,9 +301,7 @@ const getChecksQueryValidation = joi.object({
status: joi.boolean(), status: joi.boolean(),
}); });
const getTeamChecksParamValidation = joi.object({ const getTeamChecksParamValidation = joi.object({});
teamId: joi.string().required(),
});
const getTeamChecksQueryValidation = joi.object({ const getTeamChecksQueryValidation = joi.object({
sortOrder: joi.string().valid("asc", "desc"), sortOrder: joi.string().valid("asc", "desc"),
@@ -319,9 +317,7 @@ const deleteChecksParamValidation = joi.object({
monitorId: joi.string().required(), monitorId: joi.string().required(),
}); });
const deleteChecksByTeamIdParamValidation = joi.object({ const deleteChecksByTeamIdParamValidation = joi.object({});
teamId: joi.string().required(),
});
const updateChecksTTLBodyValidation = joi.object({ const updateChecksTTLBodyValidation = joi.object({
ttl: joi.number().required(), ttl: joi.number().required(),