Refactor getChecksByUserId to getChecksByTeamId
This commit is contained in:
1 parent
c8c2dfe9ec
commit
eedc6bbed6
8 files changed
+27
-31
No files matched your search
@@ -46,9 +46,9 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
try {
|
try {
|
||||||
let res;
|
let res;
|
||||||
if (selectedMonitor === "0") {
|
if (selectedMonitor === "0") {
|
||||||
res = await networkService.getChecksByUser(
|
res = await networkService.getChecksByTeam(
|
||||||
authToken,
|
authToken,
|
||||||
user._id,
|
user.teamId,
|
||||||
"desc",
|
"desc",
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
|||||||
@@ -50,14 +50,14 @@ const Incidents = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
const res = await networkService.getMonitorsByTeamId(
|
const res = await networkService.getMonitorsByTeamId(
|
||||||
authState.authToken,
|
authState.authToken,
|
||||||
authState.user._id,
|
authState.user.teamId,
|
||||||
1,
|
1,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
console.log(res);
|
||||||
// Reduce to a lookup object for 0(1) lookup
|
// Reduce to a lookup object for 0(1) lookup
|
||||||
if (res.data && res.data.data.length > 0) {
|
if (res.data && res.data.data.length > 0) {
|
||||||
const monitorLookup = res.data.data.reduce((acc, monitor) => {
|
const monitorLookup = res.data.data.reduce((acc, monitor) => {
|
||||||
|
|||||||
@@ -409,9 +409,9 @@ class NetworkService {
|
|||||||
* @returns {Promise<AxiosResponse>} The response from the axios GET request.
|
* @returns {Promise<AxiosResponse>} The response from the axios GET request.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
async getChecksByUser(
|
async getChecksByTeam(
|
||||||
authToken,
|
authToken,
|
||||||
userId,
|
teamId,
|
||||||
sortOrder,
|
sortOrder,
|
||||||
limit,
|
limit,
|
||||||
dateRange,
|
dateRange,
|
||||||
@@ -427,7 +427,7 @@ class NetworkService {
|
|||||||
if (page) params.append("page", page);
|
if (page) params.append("page", page);
|
||||||
if (rowsPerPage) params.append("rowsPerPage", rowsPerPage);
|
if (rowsPerPage) params.append("rowsPerPage", rowsPerPage);
|
||||||
return this.axiosInstance.get(
|
return this.axiosInstance.get(
|
||||||
`/checks/user/${userId}?${params.toString()}`,
|
`/checks/team/${teamId}?${params.toString()}`,
|
||||||
{
|
{
|
||||||
headers: { Authorization: `Bearer ${authToken}` },
|
headers: { Authorization: `Bearer ${authToken}` },
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ const {
|
|||||||
createCheckBodyValidation,
|
createCheckBodyValidation,
|
||||||
getChecksParamValidation,
|
getChecksParamValidation,
|
||||||
getChecksQueryValidation,
|
getChecksQueryValidation,
|
||||||
getUserChecksParamValidation,
|
getTeamChecksParamValidation,
|
||||||
getUserChecksQueryValidation,
|
getTeamChecksQueryValidation,
|
||||||
deleteChecksParamValidation,
|
deleteChecksParamValidation,
|
||||||
} = require("../validation/joi");
|
} = require("../validation/joi");
|
||||||
const { successMessages } = require("../utils/messages");
|
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 {
|
try {
|
||||||
await getUserChecksParamValidation.validateAsync(req.params);
|
await getTeamChecksParamValidation.validateAsync(req.params);
|
||||||
await getUserChecksQueryValidation.validateAsync(req.query);
|
await getTeamChecksQueryValidation.validateAsync(req.query);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.status = 422;
|
error.status = 422;
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
@@ -75,7 +75,7 @@ const getUserChecks = async (req, res, next) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const checkData = await req.db.getUserChecks(req);
|
const checkData = await req.db.getTeamChecks(req);
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: successMessages.CHECK_GET,
|
msg: successMessages.CHECK_GET,
|
||||||
@@ -115,6 +115,6 @@ const deleteChecks = async (req, res, next) => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
createCheck,
|
createCheck,
|
||||||
getChecks,
|
getChecks,
|
||||||
getUserChecks,
|
getTeamChecks,
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
};
|
};
|
||||||
@@ -92,7 +92,7 @@ const {
|
|||||||
createCheck,
|
createCheck,
|
||||||
getChecksCount,
|
getChecksCount,
|
||||||
getChecks,
|
getChecks,
|
||||||
getUserChecks,
|
getTeamChecks,
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
} = require("./modules/checkModule");
|
} = require("./modules/checkModule");
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ module.exports = {
|
|||||||
createCheck,
|
createCheck,
|
||||||
getChecksCount,
|
getChecksCount,
|
||||||
getChecks,
|
getChecks,
|
||||||
getUserChecks,
|
getTeamChecks,
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
createAlert,
|
createAlert,
|
||||||
getAlertsByUserId,
|
getAlertsByUserId,
|
||||||
|
|||||||
@@ -116,12 +116,12 @@ const getChecks = async (req) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUserChecks = async (req) => {
|
const getTeamChecks = async (req) => {
|
||||||
const { userId } = req.params;
|
const { teamId } = req.params;
|
||||||
let { sortOrder, limit, dateRange, filter, page, rowsPerPage } = req.query;
|
let { sortOrder, limit, dateRange, filter, page, rowsPerPage } = req.query;
|
||||||
|
|
||||||
// Get monitorIDs
|
// Get monitorIDs
|
||||||
const userMonitors = await Monitor.find({ userId: userId });
|
const userMonitors = await Monitor.find({ teamId: teamId });
|
||||||
const monitorIds = userMonitors.map((monitor) => monitor._id);
|
const monitorIds = userMonitors.map((monitor) => monitor._id);
|
||||||
|
|
||||||
//Build check query
|
//Build check query
|
||||||
@@ -189,6 +189,6 @@ module.exports = {
|
|||||||
createCheck,
|
createCheck,
|
||||||
getChecksCount,
|
getChecksCount,
|
||||||
getChecks,
|
getChecks,
|
||||||
getUserChecks,
|
getTeamChecks,
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
};
|
};
|
||||||
@@ -9,13 +9,9 @@ router.post(
|
|||||||
checkController.createCheck
|
checkController.createCheck
|
||||||
);
|
);
|
||||||
|
|
||||||
router.get(
|
router.get("/:monitorId", checkController.getChecks);
|
||||||
"/:monitorId",
|
|
||||||
verifyOwnership(Monitor, "monitorId"),
|
|
||||||
checkController.getChecks
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get("/user/:userId", checkController.getUserChecks);
|
router.get("/team/:teamId", checkController.getTeamChecks);
|
||||||
|
|
||||||
router.delete(
|
router.delete(
|
||||||
"/:monitorId",
|
"/:monitorId",
|
||||||
|
|||||||
@@ -271,11 +271,11 @@ const getChecksQueryValidation = joi.object({
|
|||||||
rowsPerPage: joi.number(),
|
rowsPerPage: joi.number(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getUserChecksParamValidation = joi.object({
|
const getTeamChecksParamValidation = joi.object({
|
||||||
userId: joi.string().required(),
|
teamId: joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getUserChecksQueryValidation = joi.object({
|
const getTeamChecksQueryValidation = joi.object({
|
||||||
sortOrder: joi.string().valid("asc", "desc"),
|
sortOrder: joi.string().valid("asc", "desc"),
|
||||||
limit: joi.number(),
|
limit: joi.number(),
|
||||||
dateRange: joi.string().valid("day", "week", "month"),
|
dateRange: joi.string().valid("day", "week", "month"),
|
||||||
@@ -364,8 +364,8 @@ module.exports = {
|
|||||||
createCheckBodyValidation,
|
createCheckBodyValidation,
|
||||||
getChecksParamValidation,
|
getChecksParamValidation,
|
||||||
getChecksQueryValidation,
|
getChecksQueryValidation,
|
||||||
getUserChecksParamValidation,
|
getTeamChecksParamValidation,
|
||||||
getUserChecksQueryValidation,
|
getTeamChecksQueryValidation,
|
||||||
deleteChecksParamValidation,
|
deleteChecksParamValidation,
|
||||||
deleteUserParamValidation,
|
deleteUserParamValidation,
|
||||||
getPageSpeedCheckParamValidation,
|
getPageSpeedCheckParamValidation,
|
||||||
|
|||||||
Reference in new issue
Block a user