Refactor getChecksByUserId to getChecksByTeamId
This commit is contained in:
1 parent
c8c2dfe9ec
commit
eedc6bbed6
8 files changed
+27
-31
No files matched your search
@@ -3,8 +3,8 @@ const {
|
||||
createCheckBodyValidation,
|
||||
getChecksParamValidation,
|
||||
getChecksQueryValidation,
|
||||
getUserChecksParamValidation,
|
||||
getUserChecksQueryValidation,
|
||||
getTeamChecksParamValidation,
|
||||
getTeamChecksQueryValidation,
|
||||
deleteChecksParamValidation,
|
||||
} = require("../validation/joi");
|
||||
const { successMessages } = require("../utils/messages");
|
||||
@@ -62,10 +62,10 @@ const getChecks = async (req, res, next) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getUserChecks = async (req, res, next) => {
|
||||
const getTeamChecks = async (req, res, next) => {
|
||||
try {
|
||||
await getUserChecksParamValidation.validateAsync(req.params);
|
||||
await getUserChecksQueryValidation.validateAsync(req.query);
|
||||
await getTeamChecksParamValidation.validateAsync(req.params);
|
||||
await getTeamChecksQueryValidation.validateAsync(req.query);
|
||||
} catch (error) {
|
||||
error.status = 422;
|
||||
error.service = SERVICE_NAME;
|
||||
@@ -75,7 +75,7 @@ const getUserChecks = async (req, res, next) => {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const checkData = await req.db.getUserChecks(req);
|
||||
const checkData = await req.db.getTeamChecks(req);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: successMessages.CHECK_GET,
|
||||
@@ -115,6 +115,6 @@ const deleteChecks = async (req, res, next) => {
|
||||
module.exports = {
|
||||
createCheck,
|
||||
getChecks,
|
||||
getUserChecks,
|
||||
getTeamChecks,
|
||||
deleteChecks,
|
||||
};
|
||||
@@ -92,7 +92,7 @@ const {
|
||||
createCheck,
|
||||
getChecksCount,
|
||||
getChecks,
|
||||
getUserChecks,
|
||||
getTeamChecks,
|
||||
deleteChecks,
|
||||
} = require("./modules/checkModule");
|
||||
|
||||
@@ -153,7 +153,7 @@ module.exports = {
|
||||
createCheck,
|
||||
getChecksCount,
|
||||
getChecks,
|
||||
getUserChecks,
|
||||
getTeamChecks,
|
||||
deleteChecks,
|
||||
createAlert,
|
||||
getAlertsByUserId,
|
||||
|
||||
@@ -116,12 +116,12 @@ const getChecks = async (req) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getUserChecks = async (req) => {
|
||||
const { userId } = req.params;
|
||||
const getTeamChecks = async (req) => {
|
||||
const { teamId } = req.params;
|
||||
let { sortOrder, limit, dateRange, filter, page, rowsPerPage } = req.query;
|
||||
|
||||
// Get monitorIDs
|
||||
const userMonitors = await Monitor.find({ userId: userId });
|
||||
const userMonitors = await Monitor.find({ teamId: teamId });
|
||||
const monitorIds = userMonitors.map((monitor) => monitor._id);
|
||||
|
||||
//Build check query
|
||||
@@ -189,6 +189,6 @@ module.exports = {
|
||||
createCheck,
|
||||
getChecksCount,
|
||||
getChecks,
|
||||
getUserChecks,
|
||||
getTeamChecks,
|
||||
deleteChecks,
|
||||
};
|
||||
@@ -9,13 +9,9 @@ router.post(
|
||||
checkController.createCheck
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/:monitorId",
|
||||
verifyOwnership(Monitor, "monitorId"),
|
||||
checkController.getChecks
|
||||
);
|
||||
router.get("/:monitorId", checkController.getChecks);
|
||||
|
||||
router.get("/user/:userId", checkController.getUserChecks);
|
||||
router.get("/team/:teamId", checkController.getTeamChecks);
|
||||
|
||||
router.delete(
|
||||
"/:monitorId",
|
||||
|
||||
@@ -271,11 +271,11 @@ const getChecksQueryValidation = joi.object({
|
||||
rowsPerPage: joi.number(),
|
||||
});
|
||||
|
||||
const getUserChecksParamValidation = joi.object({
|
||||
userId: joi.string().required(),
|
||||
const getTeamChecksParamValidation = joi.object({
|
||||
teamId: joi.string().required(),
|
||||
});
|
||||
|
||||
const getUserChecksQueryValidation = joi.object({
|
||||
const getTeamChecksQueryValidation = joi.object({
|
||||
sortOrder: joi.string().valid("asc", "desc"),
|
||||
limit: joi.number(),
|
||||
dateRange: joi.string().valid("day", "week", "month"),
|
||||
@@ -364,8 +364,8 @@ module.exports = {
|
||||
createCheckBodyValidation,
|
||||
getChecksParamValidation,
|
||||
getChecksQueryValidation,
|
||||
getUserChecksParamValidation,
|
||||
getUserChecksQueryValidation,
|
||||
getTeamChecksParamValidation,
|
||||
getTeamChecksQueryValidation,
|
||||
deleteChecksParamValidation,
|
||||
deleteUserParamValidation,
|
||||
getPageSpeedCheckParamValidation,
|
||||
|
||||
Reference in new issue
Block a user