mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix lint
This commit is contained in:
@@ -17,7 +17,6 @@ process.on('uncaughtException', err => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
const app = express();
|
||||
|
||||
@@ -27,24 +27,20 @@ let checksFailed = false;
|
||||
child.on('message', function(score) {
|
||||
const scores = [
|
||||
sites[sitesIndex - 1],
|
||||
|
||||
|
||||
score.performance,
|
||||
|
||||
|
||||
score.accessibility,
|
||||
|
||||
|
||||
score.bestPractices,
|
||||
|
||||
|
||||
score.seo,
|
||||
];
|
||||
table.push(scores);
|
||||
if (
|
||||
|
||||
score.performance < 50 ||
|
||||
|
||||
score.accessibility < 70 ||
|
||||
|
||||
score.bestPractices < 70 ||
|
||||
|
||||
score.seo < 80
|
||||
) {
|
||||
checksFailed = true;
|
||||
@@ -65,9 +61,7 @@ child.on('message', function(score) {
|
||||
});
|
||||
|
||||
function pages() {
|
||||
|
||||
if (program.mobile) {
|
||||
|
||||
child.send({ url: sites[sitesIndex], mobile: program.mobile });
|
||||
} else {
|
||||
child.send({ url: sites[sitesIndex], mobile: false });
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import lighthouse from 'lighthouse';
|
||||
import chromeLauncher from 'chrome-launcher';
|
||||
import ora from 'ora';
|
||||
@@ -41,7 +40,6 @@ function launchChromeAndRunLighthouse(
|
||||
config = null
|
||||
) {
|
||||
return chromeLauncher.launch(flags).then(chrome => {
|
||||
|
||||
flags.port = chrome.port;
|
||||
return lighthouse(url, flags, config).then((results: $TSFixMe) => {
|
||||
return chrome.kill().then(() => results);
|
||||
@@ -59,7 +57,7 @@ process.on('message', function(data) {
|
||||
const scores = {};
|
||||
const spinner = ora(`Running lighthouse on ${data.url}`).start();
|
||||
spinner.color = 'green';
|
||||
|
||||
|
||||
launchChromeAndRunLighthouse(data.url, flags, config)
|
||||
.then(results => {
|
||||
results.artifacts = 'ignore';
|
||||
@@ -78,35 +76,30 @@ process.on('message', function(data) {
|
||||
results.lhr.audits = 'ignore';
|
||||
results.lhr.categoryGroups = 'ignore';
|
||||
|
||||
|
||||
scores.performance = Math.ceil(
|
||||
results.lhr.categories.performance.score * 100
|
||||
);
|
||||
|
||||
|
||||
scores.accessibility = Math.ceil(
|
||||
results.lhr.categories.accessibility.score * 100
|
||||
);
|
||||
|
||||
|
||||
scores.bestPractices = Math.ceil(
|
||||
results.lhr.categories['best-practices'].score * 100
|
||||
);
|
||||
|
||||
|
||||
scores.seo = Math.ceil(results.lhr.categories.seo.score * 100);
|
||||
if (
|
||||
|
||||
scores.performance < 50 ||
|
||||
|
||||
scores.accessibility < 70 ||
|
||||
|
||||
scores.bestPractices < 70 ||
|
||||
|
||||
scores.seo < 80
|
||||
) {
|
||||
spinner.fail();
|
||||
} else {
|
||||
spinner.succeed();
|
||||
}
|
||||
|
||||
|
||||
process.send(scores);
|
||||
return scores;
|
||||
})
|
||||
|
||||
@@ -37,7 +37,6 @@ export function changePassword(values: $TSFixMe) {
|
||||
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
dispatch(changePasswordSuccess(response.data));
|
||||
},
|
||||
function(error) {
|
||||
|
||||
@@ -37,7 +37,7 @@ export function loginSuccess(user: $TSFixMe) {
|
||||
const { statusPageLogin, statusPageURL } = state.login;
|
||||
if (statusPageLogin) {
|
||||
const newURL = `${statusPageURL}?userId=${user.id}&accessToken=${user.tokens.jwtAccessToken}`;
|
||||
|
||||
|
||||
return (window.location = newURL);
|
||||
}
|
||||
|
||||
@@ -62,15 +62,12 @@ export function loginSuccess(user: $TSFixMe) {
|
||||
}
|
||||
|
||||
if (user.redirect && user?.tokens?.jwtAccessToken) {
|
||||
|
||||
return (window.location = `${user.redirect}?accessToken=${user.tokens.jwtAccessToken}`);
|
||||
} else if (user.redirect) {
|
||||
return (window.location = user.redirect);
|
||||
} else if (user.role === 'master-admin') {
|
||||
|
||||
window.location = ADMIN_DASHBOARD_URL;
|
||||
} else {
|
||||
|
||||
window.location = DASHBOARD_URL;
|
||||
}
|
||||
|
||||
@@ -111,7 +108,6 @@ export function loginUser(values: $TSFixMe) {
|
||||
|
||||
promise.then(
|
||||
function(user) {
|
||||
|
||||
dispatch(loginSuccess(user.data));
|
||||
},
|
||||
function(error) {
|
||||
@@ -144,7 +140,7 @@ export const loginUserSso = (values: $TSFixMe) => async (
|
||||
) => {
|
||||
try {
|
||||
const response = await getApi(`user/sso/login?email=${values.email}`);
|
||||
|
||||
|
||||
const { url } = response.data;
|
||||
window.location = url;
|
||||
} catch (error) {
|
||||
@@ -176,7 +172,6 @@ export function verifyAuthToken(values: $TSFixMe) {
|
||||
|
||||
promise.then(
|
||||
function(user) {
|
||||
|
||||
dispatch(loginSuccess(user.data));
|
||||
},
|
||||
function(error) {
|
||||
@@ -231,7 +226,6 @@ export function verifyBackupCode(values: $TSFixMe) {
|
||||
|
||||
promise.then(
|
||||
function(user) {
|
||||
|
||||
dispatch(loginSuccess(user.data));
|
||||
},
|
||||
function(error) {
|
||||
@@ -289,12 +283,10 @@ export const resetMasterAdminExists = () => {
|
||||
// Calls the API to register a user.
|
||||
export function checkIfMasterAdminExists(values: $TSFixMe) {
|
||||
return function(dispatch: $TSFixMe) {
|
||||
|
||||
const promise = getApi('user/masterAdminExists', values);
|
||||
dispatch(masterAdminExistsRequest(promise));
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
dispatch(masterAdminExistsSuccess(response.data));
|
||||
},
|
||||
function(error) {
|
||||
|
||||
@@ -83,21 +83,17 @@ export function signupUser(values: $TSFixMe) {
|
||||
dispatch(signUpRequest(promise));
|
||||
promise.then(
|
||||
function(user) {
|
||||
|
||||
dispatch(signupSuccess(user.data));
|
||||
|
||||
|
||||
if (user.data.role === 'master-admin' && !IS_SAAS_SERVICE) {
|
||||
|
||||
dispatch(loginSuccess(user.data));
|
||||
dispatch(masterAdminExistsSuccess({ result: true }));
|
||||
}
|
||||
if (values.token) {
|
||||
|
||||
dispatch(loginSuccess(user.data));
|
||||
}
|
||||
|
||||
|
||||
if (user.data.cardRegistered) {
|
||||
|
||||
dispatch(loginSuccess(user.data));
|
||||
}
|
||||
},
|
||||
@@ -182,7 +178,6 @@ export function isUserInvited(values: $TSFixMe) {
|
||||
dispatch(isUserInvitedRequest(promise));
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
dispatch(isUserInvitedSuccess(response.data));
|
||||
},
|
||||
function(error) {
|
||||
@@ -233,7 +228,6 @@ export function addCard(data: $TSFixMe) {
|
||||
|
||||
promise.then(
|
||||
function(card) {
|
||||
|
||||
dispatch(addCardSuccess(card.data));
|
||||
},
|
||||
function(error) {
|
||||
@@ -266,7 +260,6 @@ export function getEmailFromToken(token: $TSFixMe) {
|
||||
const promise = getApi(`user/${token}/email`);
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
dispatch(getEmailSuccess(response.data));
|
||||
},
|
||||
function(error) {
|
||||
|
||||
@@ -14,7 +14,6 @@ const headers = {
|
||||
|
||||
export function postApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
|
||||
@@ -44,7 +43,6 @@ export function postApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
|
||||
export function getApi(url: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
axios({
|
||||
@@ -73,7 +71,6 @@ export function getApi(url: $TSFixMe) {
|
||||
|
||||
export function putApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
axios({
|
||||
@@ -103,7 +100,6 @@ export function putApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
|
||||
export function deleteApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
axios({
|
||||
|
||||
@@ -15,7 +15,6 @@ export default (state = initialState, action: $TSFixMe) => {
|
||||
case CLOSE_MODAL:
|
||||
return Object.assign({}, state, {
|
||||
modals: state.modals.filter(
|
||||
|
||||
item => item.id !== action.payload.id
|
||||
),
|
||||
});
|
||||
|
||||
@@ -54,7 +54,6 @@ export default function register(state = initialState, action: $TSFixMe) {
|
||||
error: null,
|
||||
});
|
||||
case SIGNUP_SUCCESS:
|
||||
|
||||
state.user.cardRegistered = action.payload.cardRegistered;
|
||||
return Object.assign({}, state, {
|
||||
requesting: false,
|
||||
|
||||
@@ -130,19 +130,19 @@ export const allRoutes = groups
|
||||
const newSubRoutes = [];
|
||||
for (const subRoute of route.subRoutes) {
|
||||
newSubRoutes.push(subRoute);
|
||||
|
||||
|
||||
const tempRoute = { ...subRoute };
|
||||
|
||||
|
||||
tempRoute.path = '/accounts' + subRoute.path;
|
||||
newSubRoutes.push(tempRoute);
|
||||
}
|
||||
return newSubRoutes;
|
||||
})
|
||||
|
||||
|
||||
.reduce(joinFn);
|
||||
return newRoutes.concat(subRoutes);
|
||||
})
|
||||
|
||||
|
||||
.reduce(joinFn);
|
||||
|
||||
export const getGroups = () => groups;
|
||||
|
||||
@@ -23,7 +23,7 @@ const isLocalhost = Boolean(
|
||||
export function register(config: $TSFixMe) {
|
||||
if ('serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
|
||||
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
@@ -47,15 +47,13 @@ export function register(config: $TSFixMe) {
|
||||
});
|
||||
|
||||
window.addEventListener('fetch', event => {
|
||||
|
||||
event.respondWith(
|
||||
|
||||
caches.match(event.request).then(function(response) {
|
||||
// Cache hit - return response
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
return fetch(event.request);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -42,7 +42,6 @@ const middleware = [thunk, routerMiddleware(history)];
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
let devToolsExtension;
|
||||
if (!isServer) {
|
||||
|
||||
devToolsExtension = window.devToolsExtension;
|
||||
}
|
||||
middleware.push(logger);
|
||||
|
||||
@@ -3,11 +3,9 @@ if ('function' === typeof importScripts) {
|
||||
'https://storage.googleapis.com/workbox-cdn/releases/6.1.1/workbox-sw.js'
|
||||
);
|
||||
|
||||
|
||||
if (workbox) {
|
||||
|
||||
const { skipWaiting, clientsClaim } = workbox.core;
|
||||
|
||||
|
||||
const { precacheAndRoute, cleanupOutdatedCaches } = workbox.precaching;
|
||||
|
||||
// skip waiting and switch to activating stage
|
||||
@@ -18,7 +16,7 @@ if ('function' === typeof importScripts) {
|
||||
cleanupOutdatedCaches();
|
||||
|
||||
/* injection point for manifest files. */
|
||||
|
||||
|
||||
precacheAndRoute(self.__WB_MANIFEST, { cleanUrls: false });
|
||||
} else {
|
||||
// eslint-disable-next-line no-console
|
||||
|
||||
@@ -17,7 +17,6 @@ process.on('uncaughtException', err => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
const app = express();
|
||||
|
||||
@@ -32,9 +32,8 @@ export const fetchAuditLogs = (skip: $TSFixMe, limit: $TSFixMe) => async (
|
||||
dispatch(fetchAuditLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(`audit-logs?skip=${skip}&limit=${limit}`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(fetchAuditLogsSuccess(data));
|
||||
@@ -89,12 +88,11 @@ export const searchAuditLogs = (
|
||||
dispatch(searchAuditLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi(
|
||||
`audit-logs/search?skip=${skip}&limit=${limit}`,
|
||||
values
|
||||
);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(searchAuditLogsSuccess(data));
|
||||
@@ -140,9 +138,8 @@ export const deleteAuditLogs = () => async (dispatch: $TSFixMe) => {
|
||||
dispatch(deleteAuditLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await deleteApi(`audit-logs`);
|
||||
|
||||
|
||||
const message = response.data.message;
|
||||
|
||||
dispatch(deleteAuditLogsSuccess(message));
|
||||
@@ -193,13 +190,11 @@ export const resetFetchAuditLogStatus = () => {
|
||||
|
||||
// Calls the API to fetch auditLogStatus
|
||||
export const fetchAuditLogStatus = () => async (dispatch: $TSFixMe) => {
|
||||
|
||||
dispatch(fetchAuditLogStatusRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi('globalConfig/auditLogMonitoringStatus');
|
||||
|
||||
|
||||
dispatch(fetchAuditLogStatusSuccess(response.data));
|
||||
return response;
|
||||
} catch (error) {
|
||||
@@ -252,15 +247,13 @@ export const resetConfirmAuditLogStatus = () => {
|
||||
export const auditLogStatusChange = (values: $TSFixMe) => async (
|
||||
dispatch: $TSFixMe
|
||||
) => {
|
||||
|
||||
dispatch(changeAuditLogStatusRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi('globalConfig/', [
|
||||
{ name: 'auditLogMonitoringStatus', value: values.status },
|
||||
]);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
dispatch(changeAuditLogStatusSuccess(data));
|
||||
return data;
|
||||
|
||||
@@ -32,9 +32,8 @@ export const fetchCallLogs = (skip: $TSFixMe, limit: $TSFixMe) => async (
|
||||
dispatch(fetchCallLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(`call-logs?skip=${skip}&limit=${limit}`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(fetchCallLogsSuccess(data));
|
||||
@@ -89,12 +88,11 @@ export const searchCallLogs = (
|
||||
dispatch(searchCallLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi(
|
||||
`call-logs/search?skip=${skip}&limit=${limit}`,
|
||||
values
|
||||
);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(searchCallLogsSuccess(data));
|
||||
@@ -140,9 +138,8 @@ export const deleteCallLogs = () => async (dispatch: $TSFixMe) => {
|
||||
dispatch(deleteCallLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await deleteApi(`call-logs`);
|
||||
|
||||
|
||||
const message = response.data.message;
|
||||
|
||||
dispatch(deleteCallLogsSuccess(message));
|
||||
@@ -193,13 +190,11 @@ export const resetFetchCallLogStatus = () => {
|
||||
|
||||
// Calls the API to fetch callLogStatus
|
||||
export const fetchCallLogStatus = () => async (dispatch: $TSFixMe) => {
|
||||
|
||||
dispatch(fetchCallLogStatusRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi('globalConfig/callLogMonitoringStatus');
|
||||
|
||||
|
||||
dispatch(fetchCallLogStatusSuccess(response.data));
|
||||
return response;
|
||||
} catch (error) {
|
||||
@@ -252,15 +247,13 @@ export const resetConfirmCallLogStatus = () => {
|
||||
export const callLogStatusChange = (values: $TSFixMe) => async (
|
||||
dispatch: $TSFixMe
|
||||
) => {
|
||||
|
||||
dispatch(changeCallLogStatusRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi('globalConfig/', [
|
||||
{ name: 'callLogMonitoringStatus', value: values.status },
|
||||
]);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
dispatch(changeCallLogStatusSuccess(data));
|
||||
return data;
|
||||
|
||||
@@ -31,7 +31,6 @@ export const loadDashboard = () => async (dispatch: $TSFixMe) => {
|
||||
dispatch(dashboardLoadRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(`user/users?skip=${skip}&limit=${limit}`);
|
||||
dispatch(dashboardLoadSuccess());
|
||||
|
||||
|
||||
@@ -32,9 +32,8 @@ export const fetchEmailLogs = (skip: $TSFixMe, limit: $TSFixMe) => async (
|
||||
dispatch(fetchEmailLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(`email-logs?skip=${skip}&limit=${limit}`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(fetchEmailLogsSuccess(data));
|
||||
@@ -89,12 +88,11 @@ export const searchEmailLogs = (
|
||||
dispatch(searchEmailLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi(
|
||||
`email-logs/search?skip=${skip}&limit=${limit}`,
|
||||
values
|
||||
);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(searchEmailLogsSuccess(data));
|
||||
@@ -140,9 +138,8 @@ export const deleteEmailLogs = () => async (dispatch: $TSFixMe) => {
|
||||
dispatch(deleteEmailLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await deleteApi(`email-logs`);
|
||||
|
||||
|
||||
const message = response.data.message;
|
||||
|
||||
dispatch(deleteEmailLogsSuccess(message));
|
||||
@@ -193,13 +190,11 @@ export const resetFetchEmailLogStatus = () => {
|
||||
|
||||
// Calls the API to fetch emailLogStatus
|
||||
export const fetchEmailLogStatus = () => async (dispatch: $TSFixMe) => {
|
||||
|
||||
dispatch(fetchEmailLogStatusRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi('globalConfig/emailLogMonitoringStatus');
|
||||
|
||||
|
||||
dispatch(fetchEmailLogStatusSuccess(response.data));
|
||||
return response;
|
||||
} catch (error) {
|
||||
@@ -252,15 +247,13 @@ export const resetConfirmEmailLogStatus = () => {
|
||||
export const emailLogStatusChange = (values: $TSFixMe) => async (
|
||||
dispatch: $TSFixMe
|
||||
) => {
|
||||
|
||||
dispatch(changeEmailLogStatusRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi('globalConfig/', [
|
||||
{ name: 'emailLogMonitoringStatus', value: values.status },
|
||||
]);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
dispatch(changeEmailLogStatusSuccess(data));
|
||||
return data;
|
||||
|
||||
@@ -33,18 +33,16 @@ export const resetFetchLicense = () => {
|
||||
|
||||
// Calls the API to fetch license
|
||||
export const fetchLicense = () => async (dispatch: $TSFixMe) => {
|
||||
|
||||
dispatch(fetchLicenseRequest());
|
||||
dispatch(resetConfirmLicense());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi('globalConfig/configs', [
|
||||
'licenseKey',
|
||||
'licenseEmail',
|
||||
'licenseToken',
|
||||
]);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
dispatch(fetchLicenseSuccess(data));
|
||||
return data;
|
||||
@@ -98,21 +96,19 @@ export const resetConfirmLicense = () => {
|
||||
export const confirmLicense = (values: $TSFixMe) => async (
|
||||
dispatch: $TSFixMe
|
||||
) => {
|
||||
|
||||
dispatch(confirmLicenseRequest());
|
||||
|
||||
try {
|
||||
const response = await postApi('license/validate/', values, true);
|
||||
|
||||
|
||||
let data = response.data;
|
||||
if (data.token) {
|
||||
|
||||
const response = await postApi('globalConfig/', [
|
||||
{ name: 'licenseKey', value: values.license },
|
||||
{ name: 'licenseEmail', value: values.email },
|
||||
{ name: 'licenseToken', value: data.token },
|
||||
]);
|
||||
|
||||
|
||||
data = response.data;
|
||||
}
|
||||
dispatch(confirmLicenseSuccess(data));
|
||||
|
||||
@@ -31,7 +31,7 @@ export function logoutUser() {
|
||||
cookies.remove('data', { path: '/' });
|
||||
localStorage.clear();
|
||||
dispatch(receiveLogout());
|
||||
|
||||
|
||||
window.location = ACCOUNTS_URL;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -33,24 +33,22 @@ export const resetProbe = () => {
|
||||
|
||||
// Gets project Probes
|
||||
export function getProbes(skip = 0, limit = 10) {
|
||||
|
||||
skip = parseInt(skip);
|
||||
|
||||
|
||||
limit = parseInt(limit);
|
||||
|
||||
return function(dispatch: $TSFixMe) {
|
||||
let promise = null;
|
||||
|
||||
|
||||
promise = getApi(`probe/?skip=${skip}&limit=${limit}`);
|
||||
dispatch(probeRequest(promise));
|
||||
|
||||
promise.then(
|
||||
function(probes) {
|
||||
|
||||
probes.data.skip = skip || 0;
|
||||
|
||||
|
||||
probes.data.limit = limit || 10;
|
||||
|
||||
|
||||
dispatch(probeSuccess(probes.data));
|
||||
},
|
||||
function(error) {
|
||||
@@ -104,7 +102,6 @@ export const deleteProbe = (probeId: $TSFixMe) => async (
|
||||
dispatch(deleteProbeRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await deleteApi(`probe/${probeId}`);
|
||||
dispatch(deleteProbeSuccess(probeId));
|
||||
return response;
|
||||
@@ -164,9 +161,8 @@ export const addProbe = (probeKey: $TSFixMe, probeName: $TSFixMe) => async (
|
||||
dispatch(addProbeRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi('probe/', { probeKey, probeName });
|
||||
|
||||
|
||||
const data = response.data;
|
||||
dispatch(addProbeSuccess(data));
|
||||
return 'ok';
|
||||
@@ -224,7 +220,7 @@ export const updateProbe = (values: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
data.append('id', values.id);
|
||||
|
||||
const response = await putApi('probe/update/image', data);
|
||||
|
||||
|
||||
const resp = response.data;
|
||||
if (Object.keys(resp).length > 0) {
|
||||
dispatch(updateProbeSuccess(resp));
|
||||
|
||||
@@ -34,12 +34,10 @@ export const fetchProjects = (skip: $TSFixMe, limit: $TSFixMe) => async (
|
||||
dispatch(fetchProjectsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(
|
||||
`project/projects/allProjects?skip=${skip}&limit=${limit}`
|
||||
);
|
||||
|
||||
|
||||
dispatch(fetchProjectsSuccess(response.data));
|
||||
return response;
|
||||
} catch (error) {
|
||||
@@ -83,9 +81,8 @@ export const fetchProject = (slug: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(fetchProjectRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(`project/projects/${slug}`);
|
||||
|
||||
|
||||
const projects = response.data;
|
||||
|
||||
dispatch(fetchProjectSuccess(projects));
|
||||
@@ -130,12 +127,10 @@ export function userCreateError(error: $TSFixMe) {
|
||||
// Calls the API to add users to project.
|
||||
export function userCreate(projectId: $TSFixMe, values: $TSFixMe) {
|
||||
return function(dispatch: $TSFixMe) {
|
||||
|
||||
const promise = postApi(`team/${projectId}`, values);
|
||||
dispatch(userCreateRequest());
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
const data = response.data;
|
||||
const projectUsers = data.filter(
|
||||
(team: $TSFixMe) => team.projectId === projectId
|
||||
@@ -187,9 +182,8 @@ export const fetchProjectTeam = (projectId: $TSFixMe) => async (
|
||||
) => {
|
||||
dispatch(fetchProjectTeamRequest());
|
||||
try {
|
||||
|
||||
const response = await getApi(`team/${projectId}/teamMembers`);
|
||||
|
||||
|
||||
const team = response.data;
|
||||
const projectTeam = team.filter(
|
||||
(team: $TSFixMe) => team._id === projectId
|
||||
@@ -269,7 +263,6 @@ export function userUpdateRole(projectId: $TSFixMe, values: $TSFixMe) {
|
||||
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
const data = response.data;
|
||||
const projectUsers = data.filter(
|
||||
(user: $TSFixMe) => user.projectId === projectId
|
||||
@@ -326,7 +319,7 @@ export const updateBalance = (
|
||||
const response = await putApi(`project/${projectId}/updateBalance`, {
|
||||
rechargeBalanceAmount,
|
||||
});
|
||||
|
||||
|
||||
const data = response.data;
|
||||
dispatch(updateProjectBalanceSuccess(data));
|
||||
return response;
|
||||
@@ -373,7 +366,6 @@ export function teamDelete(projectId: $TSFixMe, teamMemberId: $TSFixMe) {
|
||||
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
const team = response.data;
|
||||
const projectTeam = team.filter(
|
||||
(team: $TSFixMe) => team.projectId === projectId
|
||||
@@ -444,11 +436,10 @@ export const fetchUserProjects = (
|
||||
dispatch(fetchUserProjectsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(
|
||||
`project/projects/user/${userId}?skip=${skip}&limit=${limit}`
|
||||
);
|
||||
|
||||
|
||||
const users = response.data;
|
||||
|
||||
dispatch(fetchUserProjectsSuccess(users));
|
||||
@@ -503,9 +494,8 @@ export const deleteProject = (projectId: $TSFixMe) => async (
|
||||
dispatch(deleteProjectRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await deleteApi(`project/${projectId}/deleteProject`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(deleteProjectSuccess(data));
|
||||
@@ -560,9 +550,8 @@ export const blockProject = (projectId: $TSFixMe) => async (
|
||||
dispatch(blockProjectRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await putApi(`project/${projectId}/blockProject`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(blockProjectSuccess(data));
|
||||
@@ -621,7 +610,7 @@ export const renewAlertLimit = (
|
||||
const response = await putApi(`project/${projectId}/renewAlertLimit`, {
|
||||
alertLimit,
|
||||
});
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(renewAlertLimitSuccess(data));
|
||||
@@ -676,9 +665,8 @@ export const restoreProject = (projectId: $TSFixMe) => async (
|
||||
dispatch(restoreProjectRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await putApi(`project/${projectId}/restoreProject`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(restoreProjectSuccess(data));
|
||||
@@ -733,9 +721,8 @@ export const unblockProject = (projectId: $TSFixMe) => async (
|
||||
dispatch(unblockProjectRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await putApi(`project/${projectId}/unblockProject`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(unblockProjectSuccess(data));
|
||||
@@ -790,9 +777,8 @@ export const addProjectNote = (projectId: $TSFixMe, values: $TSFixMe) => async (
|
||||
dispatch(addProjectNoteRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi(`project/${projectId}/addNote`, values);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(addProjectNoteSuccess(data));
|
||||
@@ -853,12 +839,11 @@ export const searchProjects = (
|
||||
dispatch(searchProjectsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi(
|
||||
`project/projects/search?skip=${skip}&limit=${limit}`,
|
||||
values
|
||||
);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(searchProjectsSuccess(data));
|
||||
@@ -916,7 +901,7 @@ export const changePlan = (
|
||||
oldPlan,
|
||||
newPlan,
|
||||
});
|
||||
|
||||
|
||||
dispatch(changePlanSuccess(response.data));
|
||||
} catch (error) {
|
||||
const errorMsg =
|
||||
@@ -956,13 +941,12 @@ export function fetchProjectDomains(projectId: $TSFixMe, skip = 0, limit = 10) {
|
||||
dispatch(fetchProjectDomainsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(
|
||||
`domainVerificationToken/${projectId}/domains?skip=${skip}&limit=${limit}`
|
||||
);
|
||||
|
||||
|
||||
dispatch(fetchProjectDomainsSuccess(response.data));
|
||||
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
@@ -1007,15 +991,14 @@ export function resetDeleteProjectDomain() {
|
||||
export function deleteProjectDomain({ projectId, domainId }: $TSFixMe) {
|
||||
return async function(dispatch: $TSFixMe) {
|
||||
dispatch(deleteProjectDomainRequest());
|
||||
|
||||
|
||||
const promise = deleteApi(
|
||||
`domainVerificationToken/${projectId}/domain/${domainId}`
|
||||
);
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
dispatch(deleteProjectDomainSuccess(response.data));
|
||||
|
||||
|
||||
return response.data;
|
||||
},
|
||||
function(error) {
|
||||
@@ -1065,13 +1048,12 @@ export function verifyProjectDomain({ projectId, domainId }: $TSFixMe) {
|
||||
dispatch(verifyProjectDomainRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await putApi(
|
||||
`domainVerificationToken/${projectId}/forceVerify/${domainId}`
|
||||
);
|
||||
|
||||
|
||||
dispatch(verifyProjectDomainSuccess(response.data));
|
||||
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
@@ -1117,13 +1099,11 @@ export function unVerifyProjectDomain(projectId: $TSFixMe, domainId: $TSFixMe) {
|
||||
return async function(dispatch: $TSFixMe) {
|
||||
dispatch(unVerifyProjectDomainRequest());
|
||||
|
||||
|
||||
const promise = putApi(
|
||||
`domainVerificationToken/${projectId}/unverify/${domainId}`
|
||||
);
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
dispatch(unVerifyProjectDomainSuccess(response.data));
|
||||
},
|
||||
function(error) {
|
||||
@@ -1171,13 +1151,12 @@ export function resetProjectDomainOnMount() {
|
||||
export function resetProjectDomain(projectId: $TSFixMe, domainId: $TSFixMe) {
|
||||
return async function(dispatch: $TSFixMe) {
|
||||
dispatch(resetProjectDomainRequest());
|
||||
|
||||
|
||||
const promise = putApi(
|
||||
`domainVerificationToken/${projectId}/resetDomain/${domainId}`
|
||||
);
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
dispatch(resetProjectDomainSuccess(response.data));
|
||||
},
|
||||
function(error) {
|
||||
|
||||
@@ -58,7 +58,6 @@ export const testSmtp = (payload: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(testSmtpRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi('emailSmtp/test', payload);
|
||||
dispatch(testSmtpSuccess(response));
|
||||
return response;
|
||||
@@ -81,7 +80,6 @@ export const testTwilio = (payload: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(testTwilioRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi('twilio/sms/test', payload);
|
||||
dispatch(testTwilioSuccess(response));
|
||||
return response;
|
||||
@@ -103,9 +101,8 @@ export const testTwilio = (payload: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
export const fetchSettings = (type: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(requestingSettings());
|
||||
try {
|
||||
|
||||
const response = await getApi(`globalConfig/${type}`);
|
||||
|
||||
|
||||
const data = response.data || { value: {} };
|
||||
if (type === 'smtp') {
|
||||
data.value = { 'smtp-secure': false, ...data.value };
|
||||
@@ -141,12 +138,11 @@ export const saveSettings = (type: $TSFixMe, settings: $TSFixMe) => async (
|
||||
) => {
|
||||
dispatch(requestingSettings());
|
||||
try {
|
||||
|
||||
const response = await postApi(`globalConfig`, {
|
||||
name: type,
|
||||
value: settings,
|
||||
});
|
||||
|
||||
|
||||
const data = response.data || { value: {} };
|
||||
dispatch(requestingSettingsSucceeded(data.value, type));
|
||||
return response;
|
||||
|
||||
@@ -32,9 +32,8 @@ export const fetchSmsLogs = (skip: $TSFixMe, limit: $TSFixMe) => async (
|
||||
dispatch(fetchSmsLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(`sms-logs?skip=${skip}&limit=${limit}`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(fetchSmsLogsSuccess(data));
|
||||
@@ -89,12 +88,11 @@ export const searchSmsLogs = (
|
||||
dispatch(searchSmsLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi(
|
||||
`sms-logs/search?skip=${skip}&limit=${limit}`,
|
||||
values
|
||||
);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(searchSmsLogsSuccess(data));
|
||||
@@ -140,9 +138,8 @@ export const deleteSmsLogs = () => async (dispatch: $TSFixMe) => {
|
||||
dispatch(deleteSmsLogsRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await deleteApi(`sms-logs`);
|
||||
|
||||
|
||||
const message = response.data.message;
|
||||
|
||||
dispatch(deleteSmsLogsSuccess(message));
|
||||
@@ -193,13 +190,11 @@ export const resetFetchSmsLogStatus = () => {
|
||||
|
||||
// Calls the API to fetch smsLogStatus
|
||||
export const fetchSmsLogStatus = () => async (dispatch: $TSFixMe) => {
|
||||
|
||||
dispatch(fetchSmsLogStatusRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi('globalConfig/smsLogMonitoringStatus');
|
||||
|
||||
|
||||
dispatch(fetchSmsLogStatusSuccess(response.data));
|
||||
return response;
|
||||
} catch (error) {
|
||||
@@ -252,15 +247,13 @@ export const resetConfirmSmsLogStatus = () => {
|
||||
export const smsLogStatusChange = (values: $TSFixMe) => async (
|
||||
dispatch: $TSFixMe
|
||||
) => {
|
||||
|
||||
dispatch(changeSmsLogStatusRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi('globalConfig/', [
|
||||
{ name: 'smsLogMonitoringStatus', value: values.status },
|
||||
]);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
dispatch(changeSmsLogStatusSuccess(data));
|
||||
return data;
|
||||
|
||||
@@ -29,9 +29,8 @@ export const fetchSsos = (skip: $TSFixMe, limit: $TSFixMe) => async (
|
||||
limit = limit ? parseInt(limit) : 10;
|
||||
dispatch(fetchSsosRequest());
|
||||
try {
|
||||
|
||||
const response = await getApi(`sso/?skip=${skip}&limit=${limit}`);
|
||||
|
||||
|
||||
dispatch(fetchSsosSuccess(response.data));
|
||||
} catch (error) {
|
||||
let errorMsg;
|
||||
@@ -72,9 +71,8 @@ export const fetchSsoError = (payload: $TSFixMe) => {
|
||||
export const fetchSso = (ssoId: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(fetchSsoRequest());
|
||||
try {
|
||||
|
||||
const response = await getApi(`sso/${ssoId}`);
|
||||
|
||||
|
||||
dispatch(fetchSsoSuccess(response.data));
|
||||
} catch (error) {
|
||||
let errorMsg;
|
||||
@@ -114,7 +112,6 @@ export const deleteSsoError = (payload: $TSFixMe) => {
|
||||
export const deleteSso = (ssoId: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(deleteSsoRequest());
|
||||
try {
|
||||
|
||||
await deleteApi(`sso/${ssoId}`);
|
||||
dispatch(deleteSsoSuccess());
|
||||
} catch (error) {
|
||||
@@ -155,7 +152,6 @@ export const addSsoError = (payload: $TSFixMe) => {
|
||||
export const addSso = ({ data }: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(addSsoRequest());
|
||||
try {
|
||||
|
||||
await postApi(`sso/`, data);
|
||||
dispatch(addSsoSuccess());
|
||||
} catch (error) {
|
||||
|
||||
@@ -29,11 +29,10 @@ export const fetchSsoDefaultRoles = (skip: $TSFixMe, limit: $TSFixMe) => async (
|
||||
limit = limit ? parseInt(limit) : 10;
|
||||
dispatch(fetchSsoDefaultRolesRequest());
|
||||
try {
|
||||
|
||||
const response = await getApi(
|
||||
`ssoDefaultRoles/?skip=${skip}&limit=${limit}`
|
||||
);
|
||||
|
||||
|
||||
return dispatch(fetchSsoDefaultRolesSuccess(response.data));
|
||||
} catch (error) {
|
||||
let errorMsg;
|
||||
@@ -76,9 +75,8 @@ export const fetchSsoDefaultRole = (ssoDefaultRoleId: $TSFixMe) => async (
|
||||
) => {
|
||||
dispatch(fetchSsoDefaultRoleRequest());
|
||||
try {
|
||||
|
||||
const response = await getApi(`ssoDefaultRoles/${ssoDefaultRoleId}`);
|
||||
|
||||
|
||||
dispatch(fetchSsoDefaultRoleSuccess(response.data));
|
||||
} catch (error) {
|
||||
let errorMsg;
|
||||
@@ -121,11 +119,10 @@ export const deleteSsoDefaultRole = (ssoId: $TSFixMe) => async (
|
||||
) => {
|
||||
dispatch(deleteSsoDefaultRoleRequest());
|
||||
try {
|
||||
|
||||
const response = await deleteApi(`ssoDefaultRoles/${ssoId}`);
|
||||
|
||||
|
||||
dispatch(deleteSsoDefaultRoleSuccess(response.data));
|
||||
|
||||
|
||||
dispatch(fetchSsoDefaultRoles());
|
||||
} catch (error) {
|
||||
let errorMsg;
|
||||
@@ -167,7 +164,6 @@ export const addSsoDefaultRole = ({ data }: $TSFixMe) => async (
|
||||
) => {
|
||||
dispatch(addSsoDefaultRoleRequest());
|
||||
try {
|
||||
|
||||
await postApi(`ssoDefaultRoles/`, data);
|
||||
dispatch(addSsoDefaultRoleSuccess());
|
||||
return true;
|
||||
|
||||
@@ -31,9 +31,8 @@ export const fetchUsers = (skip: $TSFixMe, limit: $TSFixMe) => async (
|
||||
dispatch(fetchUsersRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(`user/users?skip=${skip}&limit=${limit}`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(fetchUsersSuccess(data));
|
||||
@@ -79,9 +78,8 @@ export const fetchUser = (userId: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(fetchUserRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await getApi(`user/users/${userId}`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(fetchUserSuccess(data));
|
||||
@@ -134,12 +132,11 @@ export const resetAddUser = () => {
|
||||
export const addUser = (user: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
try {
|
||||
dispatch(addUserRequest());
|
||||
|
||||
|
||||
const response = await postApi(`user/signup`, user);
|
||||
|
||||
|
||||
const userResponse = await getApi(`user/users/${response.data.id}`);
|
||||
|
||||
|
||||
dispatch(addUserSuccess(userResponse.data));
|
||||
return 'ok';
|
||||
} catch (error) {
|
||||
@@ -201,7 +198,7 @@ export const updateUserSetting = (values: $TSFixMe) => async (
|
||||
|
||||
try {
|
||||
const response = await putApi(`user/profile/${values._id}`, data);
|
||||
|
||||
|
||||
const user = response.data;
|
||||
|
||||
dispatch(updateUserSettingSuccess(user));
|
||||
@@ -266,9 +263,8 @@ export const deleteUser = (userId: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(deleteUserRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await deleteApi(`user/${userId}`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(deleteUserSuccess(data));
|
||||
@@ -321,9 +317,8 @@ export const restoreUser = (userId: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(restoreUserRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await putApi(`user/${userId}/restoreUser`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(restoreUserSuccess(data));
|
||||
@@ -376,9 +371,8 @@ export const blockUser = (userId: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(blockUserRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await putApi(`user/${userId}/blockUser`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(blockUserSuccess(data));
|
||||
@@ -433,12 +427,11 @@ export const enableAdminMode = (userId: $TSFixMe, values: $TSFixMe) => async (
|
||||
dispatch(enableAdminModeRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi(
|
||||
`user/${userId}/switchToAdminMode`,
|
||||
values
|
||||
);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(enableAdminModeSuccess(data));
|
||||
@@ -493,9 +486,8 @@ export const disableAdminMode = (userId: $TSFixMe) => async (
|
||||
dispatch(disableAdminModeRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi(`user/${userId}/exitAdminMode`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(disableAdminModeSuccess(data));
|
||||
@@ -548,9 +540,8 @@ export const unblockUser = (userId: $TSFixMe) => async (dispatch: $TSFixMe) => {
|
||||
dispatch(unblockUserRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await putApi(`user/${userId}/unblockUser`);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(unblockUserSuccess(data));
|
||||
@@ -605,9 +596,8 @@ export const addUserNote = (userId: $TSFixMe, values: $TSFixMe) => async (
|
||||
dispatch(addUserNoteRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi(`user/${userId}/addNote`, values);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(addUserNoteSuccess(data));
|
||||
@@ -670,12 +660,11 @@ export const searchUsers = (
|
||||
dispatch(searchUsersRequest());
|
||||
|
||||
try {
|
||||
|
||||
const response = await postApi(
|
||||
`user/users/search?skip=${skip}&limit=${limit}`,
|
||||
values
|
||||
);
|
||||
|
||||
|
||||
const data = response.data;
|
||||
|
||||
dispatch(searchUsersSuccess(data));
|
||||
@@ -723,7 +712,6 @@ export function updateTwoFactorAuthToken(userId: $TSFixMe, data: $TSFixMe) {
|
||||
dispatch(twoFactorAuthTokenRequest());
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
const payload = response.data;
|
||||
dispatch(twoFactorAuthTokenSuccess(payload));
|
||||
return payload;
|
||||
@@ -782,12 +770,10 @@ export function fetchUserloginHistory(
|
||||
limit = 10
|
||||
) {
|
||||
return function(dispatch: $TSFixMe) {
|
||||
|
||||
const promise = getApi(`history/${userId}?skip=${skip}&limit=${limit}`);
|
||||
dispatch(fetchUserHistoryRequest());
|
||||
promise.then(
|
||||
function(response) {
|
||||
|
||||
const payload = response.data;
|
||||
dispatch(fetchUserHistorySuccess(payload));
|
||||
return payload;
|
||||
|
||||
@@ -36,7 +36,6 @@ export function getVersion() {
|
||||
let docsPromise = null;
|
||||
let dashboardPromise = null;
|
||||
|
||||
|
||||
backendPromise = getApi('version');
|
||||
helmChartPromise = getApiHelm('version');
|
||||
docsPromise = getApiDocs('version');
|
||||
@@ -55,7 +54,6 @@ export function getVersion() {
|
||||
function(versions) {
|
||||
let versionsObject = {};
|
||||
versions.forEach(version => {
|
||||
|
||||
versionsObject = { ...versionsObject, ...version.data };
|
||||
});
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ const headers = {
|
||||
|
||||
export function postApi(url: $TSFixMe, data: $TSFixMe, licensing: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
|
||||
@@ -41,7 +40,7 @@ export function postApi(url: $TSFixMe, data: $TSFixMe, licensing: $TSFixMe) {
|
||||
cookies.remove('admin-data', { path: '/' });
|
||||
cookies.remove('data', { path: '/' });
|
||||
User.clear();
|
||||
|
||||
|
||||
window.location = ACCOUNTS_URL + '/login';
|
||||
}
|
||||
if (error && error.response && error.response.data)
|
||||
@@ -56,7 +55,6 @@ export function postApi(url: $TSFixMe, data: $TSFixMe, licensing: $TSFixMe) {
|
||||
|
||||
export function getApi(url: $TSFixMe, licensing: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
axios({
|
||||
@@ -73,7 +71,7 @@ export function getApi(url: $TSFixMe, licensing: $TSFixMe) {
|
||||
cookies.remove('admin-data', { path: '/' });
|
||||
cookies.remove('data', { path: '/' });
|
||||
User.clear();
|
||||
|
||||
|
||||
window.location = ACCOUNTS_URL + '/login';
|
||||
}
|
||||
if (error && error.response && error.response.data)
|
||||
@@ -89,7 +87,6 @@ export function getApi(url: $TSFixMe, licensing: $TSFixMe) {
|
||||
|
||||
export function putApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
axios({
|
||||
@@ -107,7 +104,7 @@ export function putApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
cookies.remove('admin-data', { path: '/' });
|
||||
cookies.remove('data', { path: '/' });
|
||||
User.clear();
|
||||
|
||||
|
||||
window.location = ACCOUNTS_URL + '/login';
|
||||
}
|
||||
if (error && error.response && error.response.data)
|
||||
@@ -123,7 +120,6 @@ export function putApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
|
||||
export function deleteApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
axios({
|
||||
@@ -141,7 +137,7 @@ export function deleteApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
cookies.remove('admin-data', { path: '/' });
|
||||
cookies.remove('data', { path: '/' });
|
||||
User.clear();
|
||||
|
||||
|
||||
window.location = ACCOUNTS_URL + '/login';
|
||||
}
|
||||
if (error && error.response && error.response.data)
|
||||
@@ -157,7 +153,6 @@ export function deleteApi(url: $TSFixMe, data: $TSFixMe) {
|
||||
|
||||
export function getApiDocs(url: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
axios({
|
||||
@@ -174,7 +169,7 @@ export function getApiDocs(url: $TSFixMe) {
|
||||
cookies.remove('admin-data', { path: '/' });
|
||||
cookies.remove('data', { path: '/' });
|
||||
User.clear();
|
||||
|
||||
|
||||
window.location = ACCOUNTS_URL + '/login';
|
||||
}
|
||||
if (error && error.response && error.response.data)
|
||||
@@ -190,7 +185,6 @@ export function getApiDocs(url: $TSFixMe) {
|
||||
|
||||
export function getApiHelm(url: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
axios({
|
||||
@@ -207,7 +201,7 @@ export function getApiHelm(url: $TSFixMe) {
|
||||
cookies.remove('admin-data', { path: '/' });
|
||||
cookies.remove('data', { path: '/' });
|
||||
User.clear();
|
||||
|
||||
|
||||
window.location = ACCOUNTS_URL + '/login';
|
||||
}
|
||||
if (error && error.response && error.response.data)
|
||||
@@ -223,7 +217,6 @@ export function getApiHelm(url: $TSFixMe) {
|
||||
|
||||
export function getApiDashboard(url: $TSFixMe) {
|
||||
if (User.isLoggedIn())
|
||||
|
||||
headers['Authorization'] = 'Basic ' + User.getAccessToken();
|
||||
const deffered = Q.defer();
|
||||
axios({
|
||||
@@ -240,7 +233,7 @@ export function getApiDashboard(url: $TSFixMe) {
|
||||
cookies.remove('admin-data', { path: '/' });
|
||||
cookies.remove('data', { path: '/' });
|
||||
User.clear();
|
||||
|
||||
|
||||
window.location = ACCOUNTS_URL + '/login';
|
||||
}
|
||||
if (error && error.response && error.response.data)
|
||||
|
||||
@@ -39,7 +39,7 @@ export default (state = initialState, action: $TSFixMe) => {
|
||||
const data = {};
|
||||
for (const config of action.payload.data) {
|
||||
const { name, value } = config;
|
||||
|
||||
|
||||
data[name] = value;
|
||||
}
|
||||
return Object.assign({}, state, {
|
||||
@@ -48,11 +48,10 @@ export default (state = initialState, action: $TSFixMe) => {
|
||||
requesting: false,
|
||||
success: true,
|
||||
data: {
|
||||
|
||||
license: data.licenseKey,
|
||||
|
||||
|
||||
email: data.licenseEmail,
|
||||
|
||||
|
||||
token: data.licenseToken,
|
||||
},
|
||||
},
|
||||
@@ -92,7 +91,7 @@ export default (state = initialState, action: $TSFixMe) => {
|
||||
const data = {};
|
||||
for (const config of action.payload.data) {
|
||||
const { name, value } = config;
|
||||
|
||||
|
||||
data[name] = value;
|
||||
}
|
||||
return Object.assign({}, state, {
|
||||
@@ -101,11 +100,10 @@ export default (state = initialState, action: $TSFixMe) => {
|
||||
requesting: false,
|
||||
success: true,
|
||||
data: {
|
||||
|
||||
license: data.licenseKey,
|
||||
|
||||
|
||||
email: data.licenseEmail,
|
||||
|
||||
|
||||
token: data.licenseToken,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -15,7 +15,6 @@ export default (state = initialState, action: $TSFixMe) => {
|
||||
case CLOSE_MODAL:
|
||||
return Object.assign({}, state, {
|
||||
modals: state.modals.filter(
|
||||
|
||||
item => item.id !== action.payload.id
|
||||
),
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ export default (state = initialState, action: $TSFixMe) => {
|
||||
|
||||
case 'ADD_NOTIFICATION_BY_SOCKET': {
|
||||
const notify = state.notifications.notifications;
|
||||
|
||||
|
||||
notify.unshift(action.payload);
|
||||
return Object.assign({}, state, {
|
||||
notifications: {
|
||||
@@ -94,12 +94,10 @@ export default (state = initialState, action: $TSFixMe) => {
|
||||
notifications: state.notifications.notifications.map(
|
||||
notification => {
|
||||
if (
|
||||
|
||||
notification._id ===
|
||||
action.payload.notificationId._id
|
||||
) {
|
||||
return {
|
||||
|
||||
...notification,
|
||||
read: notification.read.concat([
|
||||
action.payload.userId,
|
||||
|
||||
@@ -80,10 +80,9 @@ export default function probes(state = initialState, action: $TSFixMe) {
|
||||
probes: {
|
||||
...state.probes,
|
||||
data: state.probes.data.filter(
|
||||
|
||||
d => d._id !== action.payload
|
||||
),
|
||||
|
||||
|
||||
count: state.probes.count - 1,
|
||||
},
|
||||
deleteProbe: {
|
||||
@@ -124,9 +123,9 @@ export default function probes(state = initialState, action: $TSFixMe) {
|
||||
return Object.assign({}, state, {
|
||||
probes: {
|
||||
...state.probes,
|
||||
|
||||
|
||||
data: state.probes.data.concat([action.payload]),
|
||||
|
||||
|
||||
count: state.probes.count + 1,
|
||||
},
|
||||
addProbe: {
|
||||
@@ -198,7 +197,6 @@ export default function probes(state = initialState, action: $TSFixMe) {
|
||||
data:
|
||||
state.probes.data.length > 0
|
||||
? state.probes.data.map(probe => {
|
||||
|
||||
return probe._id === action.payload._id
|
||||
? action.payload
|
||||
: probe;
|
||||
|
||||
@@ -350,7 +350,6 @@ export default function project(state = INITIAL_STATE, action: $TSFixMe) {
|
||||
error: null,
|
||||
success: false,
|
||||
updating: state.updateUser.updating.concat([
|
||||
|
||||
action.payload,
|
||||
]),
|
||||
},
|
||||
@@ -612,7 +611,7 @@ export default function project(state = INITIAL_STATE, action: $TSFixMe) {
|
||||
return Object.assign({}, state, {
|
||||
projectTeam: {
|
||||
...state.projectTeam,
|
||||
|
||||
|
||||
page: state.projectTeam.page + 1,
|
||||
},
|
||||
});
|
||||
@@ -621,10 +620,8 @@ export default function project(state = INITIAL_STATE, action: $TSFixMe) {
|
||||
projectTeam: {
|
||||
...state.projectTeam,
|
||||
page:
|
||||
|
||||
state.projectTeam.page > 1
|
||||
?
|
||||
state.projectTeam.page - 1
|
||||
? state.projectTeam.page - 1
|
||||
: 1,
|
||||
},
|
||||
});
|
||||
@@ -638,7 +635,6 @@ export default function project(state = INITIAL_STATE, action: $TSFixMe) {
|
||||
requesting: true,
|
||||
success: false,
|
||||
deleting: state.teamDelete.deleting.concat([
|
||||
|
||||
action.payload,
|
||||
]),
|
||||
},
|
||||
@@ -949,9 +945,7 @@ export default function project(state = INITIAL_STATE, action: $TSFixMe) {
|
||||
error: null,
|
||||
success: true,
|
||||
projects: state.projects.projects.map(project => {
|
||||
|
||||
if (project._id === action.payload._id) {
|
||||
|
||||
project = action.payload;
|
||||
}
|
||||
return project;
|
||||
|
||||
@@ -35,13 +35,10 @@ export default function profileSettings(
|
||||
|
||||
case REQUESTING_SETTINGS_SUCCEEDED:
|
||||
if (action.payloadType === 'smtp') {
|
||||
|
||||
settings.smtp = action.payload;
|
||||
} else if (action.payloadType === 'twilio') {
|
||||
|
||||
settings.twilio = action.payload;
|
||||
} else if (action.payloadType === 'sso') {
|
||||
|
||||
settings.sso = action.payload;
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -106,7 +106,6 @@ export default function ssoDefaultRoles(
|
||||
ssoDefaultRoles: {
|
||||
...state.ssoDefaultRoles,
|
||||
ssoDefaultRoles: state.ssoDefaultRoles.ssoDefaultRoles.filter(
|
||||
|
||||
element => element._id !== action.payload._id
|
||||
),
|
||||
},
|
||||
|
||||
@@ -220,7 +220,7 @@ export default function user(state = INITIAL_STATE, action: $TSFixMe) {
|
||||
action.payload,
|
||||
...state.users.users.slice(0, -1),
|
||||
],
|
||||
|
||||
|
||||
count: state.users.count + 1,
|
||||
},
|
||||
addUser: {
|
||||
@@ -280,7 +280,6 @@ export default function user(state = INITIAL_STATE, action: $TSFixMe) {
|
||||
error: null,
|
||||
success: true,
|
||||
users: state.users.users.map(user =>
|
||||
|
||||
user._id === action.payload._id ? action.payload : user
|
||||
),
|
||||
count: action.payload.count,
|
||||
@@ -571,9 +570,7 @@ export default function user(state = INITIAL_STATE, action: $TSFixMe) {
|
||||
error: null,
|
||||
success: true,
|
||||
users: state.users.users.map(user => {
|
||||
|
||||
if (user._id === action.payload._id) {
|
||||
|
||||
user = action.payload;
|
||||
}
|
||||
return user;
|
||||
|
||||
@@ -282,12 +282,12 @@ export const allRoutes = groups
|
||||
}
|
||||
return newSubRoutes;
|
||||
})
|
||||
|
||||
|
||||
.reduce(joinFn);
|
||||
|
||||
|
||||
return newRoutes.concat(subRoutes);
|
||||
})
|
||||
|
||||
|
||||
.reduce(joinFn);
|
||||
|
||||
export const getGroups = () => groups;
|
||||
|
||||
@@ -26,7 +26,6 @@ const middleware = [thunk, routerMiddleware(history)];
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
let devToolsExtension;
|
||||
if (!isServer) {
|
||||
|
||||
devToolsExtension = window.devToolsExtension;
|
||||
}
|
||||
middleware.push(logger);
|
||||
|
||||
@@ -16,10 +16,8 @@ export default function(text: $TSFixMe) {
|
||||
// Check if there is any content selected previously
|
||||
// Store selection if found
|
||||
const selected =
|
||||
|
||||
document.getSelection().rangeCount > 0
|
||||
?
|
||||
document.getSelection().getRangeAt(0)
|
||||
? document.getSelection().getRangeAt(0)
|
||||
: false;
|
||||
|
||||
el.select();
|
||||
@@ -32,9 +30,8 @@ export default function(text: $TSFixMe) {
|
||||
Unselect everything on the HTML document;
|
||||
Restore the original selection */
|
||||
if (selected) {
|
||||
|
||||
document.getSelection().removeAllRanges();
|
||||
|
||||
|
||||
document.getSelection().addRange(selected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ process.on('uncaughtException', err => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
|
||||
import express from 'express';
|
||||
const app = express();
|
||||
import path from 'path';
|
||||
|
||||
@@ -27,7 +27,6 @@ process.on('uncaughtException', err => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
|
||||
import express from 'express';
|
||||
const app = express();
|
||||
|
||||
@@ -45,7 +44,6 @@ const cronApplicationSecurityStartTime = Math.floor(Math.random() * 50);
|
||||
app.use(cors());
|
||||
app.set('port', process.env.PORT || 3005);
|
||||
|
||||
|
||||
app.get(['/application/status', '/status'], function(req, res) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(
|
||||
@@ -71,7 +69,6 @@ cron.schedule('*/5 * * * *', () => {
|
||||
}, cronApplicationSecurityStartTime * 1000);
|
||||
});
|
||||
|
||||
|
||||
http.listen(app.get('port'), function() {
|
||||
// eslint-disable-next-line
|
||||
console.log(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import { postApi } from './api';
|
||||
|
||||
export default {
|
||||
|
||||
@@ -20,10 +20,8 @@ const {
|
||||
updateApplicationSecurityToFailed,
|
||||
} = require('./applicationSecurityUpdate');
|
||||
|
||||
|
||||
import { Client } from 'ssh2';
|
||||
export default {
|
||||
|
||||
scan: async function(security) {
|
||||
if (
|
||||
security.gitCredential.gitUsername &&
|
||||
@@ -39,7 +37,7 @@ export default {
|
||||
await this.sshScanApplicationSecurity(security);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
decryptPassword: async function(security) {
|
||||
try {
|
||||
const values = [];
|
||||
@@ -60,11 +58,10 @@ export default {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
decrypt: (encText, iv) => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
try {
|
||||
|
||||
const decipher = crypto.createDecipheriv(algorithm, key, iv);
|
||||
let decoded = decipher.update(encText, 'hex', 'utf8');
|
||||
decoded += decipher.final('utf8');
|
||||
@@ -75,11 +72,11 @@ export default {
|
||||
});
|
||||
return promise;
|
||||
},
|
||||
|
||||
|
||||
sshScanApplicationSecurity: async security => {
|
||||
try {
|
||||
let securityDir = 'application_security_dir';
|
||||
|
||||
|
||||
securityDir = await createDir(securityDir);
|
||||
const cloneDirectory = `${uuidv1()}security`; // always create unique paths
|
||||
const repoPath = Path.resolve(securityDir, cloneDirectory);
|
||||
@@ -101,7 +98,6 @@ export default {
|
||||
cwd: repoPath,
|
||||
});
|
||||
output.on('error', error => {
|
||||
|
||||
error.code = 500;
|
||||
throw error;
|
||||
});
|
||||
@@ -117,7 +113,6 @@ export default {
|
||||
);
|
||||
|
||||
audit.on('error', error => {
|
||||
|
||||
error.code = 500;
|
||||
throw error;
|
||||
});
|
||||
@@ -130,21 +125,16 @@ export default {
|
||||
audit.on('close', async () => {
|
||||
let advisories = [];
|
||||
auditOutput = JSON.parse(auditOutput); // parse the stringified json
|
||||
|
||||
|
||||
for (const key in auditOutput.vulnerabilities) {
|
||||
advisories.push(
|
||||
|
||||
auditOutput.vulnerabilities[key]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const criticalArr = [],
|
||||
|
||||
highArr = [],
|
||||
|
||||
moderateArr = [],
|
||||
|
||||
lowArr = [];
|
||||
advisories.map(advisory => {
|
||||
if (advisory.severity === 'critical') {
|
||||
@@ -164,34 +154,28 @@ export default {
|
||||
|
||||
// restructure advisories from the most critical case to the least critical(low)
|
||||
advisories = [
|
||||
|
||||
...criticalArr,
|
||||
|
||||
|
||||
...highArr,
|
||||
|
||||
|
||||
...moderateArr,
|
||||
|
||||
|
||||
...lowArr,
|
||||
];
|
||||
|
||||
const auditData = {
|
||||
dependencies:
|
||||
|
||||
auditOutput.metadata.dependencies,
|
||||
devDependencies:
|
||||
|
||||
auditOutput.metadata
|
||||
.devDependencies,
|
||||
optionalDependencies:
|
||||
|
||||
auditOutput.metadata
|
||||
.optionalDependencies,
|
||||
totalDependencies:
|
||||
|
||||
auditOutput.metadata
|
||||
.totalDependencies,
|
||||
vulnerabilities:
|
||||
|
||||
auditOutput.metadata
|
||||
.vulnerabilities,
|
||||
advisories,
|
||||
@@ -240,11 +224,11 @@ export default {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
scanApplicationSecurity: async security => {
|
||||
try {
|
||||
let securityDir = 'application_security_dir';
|
||||
|
||||
|
||||
securityDir = await createDir(securityDir);
|
||||
|
||||
const USER = security.gitCredential.gitUsername;
|
||||
@@ -269,7 +253,6 @@ export default {
|
||||
cwd: repoPath,
|
||||
});
|
||||
output.on('error', error => {
|
||||
|
||||
error.code = 500;
|
||||
throw error;
|
||||
});
|
||||
@@ -281,7 +264,6 @@ export default {
|
||||
});
|
||||
|
||||
audit.on('error', error => {
|
||||
|
||||
error.code = 500;
|
||||
throw error;
|
||||
});
|
||||
@@ -294,21 +276,16 @@ export default {
|
||||
audit.on('close', async () => {
|
||||
let advisories = [];
|
||||
auditOutput = JSON.parse(auditOutput); // parse the stringified json
|
||||
|
||||
|
||||
for (const key in auditOutput.vulnerabilities) {
|
||||
advisories.push(
|
||||
|
||||
auditOutput.vulnerabilities[key]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const criticalArr = [],
|
||||
|
||||
highArr = [],
|
||||
|
||||
moderateArr = [],
|
||||
|
||||
lowArr = [];
|
||||
advisories.map(advisory => {
|
||||
if (advisory.severity === 'critical') {
|
||||
@@ -328,32 +305,26 @@ export default {
|
||||
|
||||
// restructure advisories from the most critical case to the least critical(low)
|
||||
advisories = [
|
||||
|
||||
...criticalArr,
|
||||
|
||||
|
||||
...highArr,
|
||||
|
||||
|
||||
...moderateArr,
|
||||
|
||||
|
||||
...lowArr,
|
||||
];
|
||||
|
||||
const auditData = {
|
||||
dependencies:
|
||||
|
||||
auditOutput.metadata.dependencies,
|
||||
devDependencies:
|
||||
|
||||
auditOutput.metadata.devDependencies,
|
||||
optionalDependencies:
|
||||
|
||||
auditOutput.metadata
|
||||
.optionalDependencies,
|
||||
totalDependencies:
|
||||
|
||||
auditOutput.metadata.totalDependencies,
|
||||
vulnerabilities:
|
||||
|
||||
auditOutput.metadata.vulnerabilities,
|
||||
advisories,
|
||||
};
|
||||
@@ -436,7 +407,6 @@ function formatUrl(url) {
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
function createDir(dirPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const workPath = Path.resolve(process.cwd(), dirPath);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import packageJson from '../package.json';
|
||||
|
||||
const COMMAND = {
|
||||
|
||||
@@ -7,7 +7,6 @@ if (
|
||||
process.env.SLACK_ERROR_LOG_WEBHOOK &&
|
||||
process.env.SLACK_ERROR_LOG_CHANNEL
|
||||
) {
|
||||
|
||||
winston.add(Slack, {
|
||||
webhook_url: process.env.SLACK_ERROR_LOG_WEBHOOK,
|
||||
channel: '#' + process.env.SLACK_ERROR_LOG_CHANNEL,
|
||||
@@ -26,7 +25,7 @@ export default {
|
||||
functionName: String(functionName),
|
||||
stack: new Error().stack,
|
||||
},
|
||||
|
||||
|
||||
0,
|
||||
2
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ const sendItemResponse = require('../middlewares/response').sendItemResponse;
|
||||
router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
try {
|
||||
const projectId = req.params.projectId;
|
||||
|
||||
|
||||
const userId = req.user.id;
|
||||
const data = req.body;
|
||||
data.projectId = projectId;
|
||||
@@ -43,10 +43,8 @@ router.get('/:projectId', getUser, isAuthorized, getSubProjects, async function(
|
||||
res
|
||||
) {
|
||||
try {
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
const alerts = await alertService.getSubProjectAlerts(subProjectIds);
|
||||
return sendItemResponse(req, res, alerts); // frontend expects sendItemResponse
|
||||
@@ -168,7 +166,7 @@ router.get('/:projectId/:alertId/viewed', async function(req, res) {
|
||||
router.delete('/:projectId', getUser, isUserOwner, async function(req, res) {
|
||||
try {
|
||||
const projectId = req.params.projectId;
|
||||
|
||||
|
||||
const userId = req.user.id;
|
||||
const alert = await alertService.deleteBy(
|
||||
{ projectId: projectId },
|
||||
|
||||
@@ -56,14 +56,12 @@ router.get('/', async (req, res) => {
|
||||
|
||||
// handle redis related operation to test the health
|
||||
try {
|
||||
|
||||
if (global.redisClient) {
|
||||
|
||||
await global.redisClient.set(
|
||||
'status',
|
||||
'Redis status is online'
|
||||
);
|
||||
|
||||
|
||||
const value = await global.redisClient.get('status');
|
||||
|
||||
if (!value) {
|
||||
|
||||
@@ -12,7 +12,6 @@ const getUser = require('../middlewares/user').getUser;
|
||||
const isApplicationLogValid = require('../middlewares/applicationLog')
|
||||
.isApplicationLogValid;
|
||||
|
||||
|
||||
import { isAuthorized } from '../middlewares/authorization';
|
||||
const sendErrorResponse = require('../middlewares/response').sendErrorResponse;
|
||||
const sendItemResponse = require('../middlewares/response').sendItemResponse;
|
||||
@@ -42,7 +41,7 @@ router.post(
|
||||
message: "values can't be null",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
if (!data.name) {
|
||||
return sendErrorResponse(req, res, {
|
||||
@@ -73,17 +72,15 @@ router.post(
|
||||
populate: populateComponent,
|
||||
}),
|
||||
UserService.findOneBy({
|
||||
|
||||
query: { _id: req.user.id },
|
||||
select: 'name _id',
|
||||
}),
|
||||
]);
|
||||
|
||||
try {
|
||||
|
||||
NotificationService.create(
|
||||
component.projectId._id,
|
||||
|
||||
|
||||
`A New Application Log was Created with name ${applicationLog.name} by ${user.name}`,
|
||||
user._id,
|
||||
'applicationlogaddremove'
|
||||
@@ -143,7 +140,7 @@ router.delete(
|
||||
_id: applicationLogId,
|
||||
componentId: componentId,
|
||||
},
|
||||
|
||||
|
||||
req.user.id
|
||||
);
|
||||
if (applicationLog) {
|
||||
@@ -215,18 +212,14 @@ router.post(
|
||||
|
||||
const query = {};
|
||||
|
||||
|
||||
if (applicationLogId) query.applicationLogId = applicationLogId;
|
||||
|
||||
|
||||
if (type) query.type = type;
|
||||
|
||||
if (startDate && endDate)
|
||||
|
||||
query.createdAt = { $gte: startDate, $lte: endDate };
|
||||
|
||||
if (filter) {
|
||||
|
||||
query.stringifiedContent = {
|
||||
$regex: new RegExp(filter),
|
||||
$options: 'i',
|
||||
@@ -278,7 +271,6 @@ router.post(
|
||||
|
||||
const query = {};
|
||||
|
||||
|
||||
if (applicationLogId) query.applicationLogId = applicationLogId;
|
||||
|
||||
const stat = {};
|
||||
@@ -294,13 +286,13 @@ router.post(
|
||||
LogService.countBy({ ...query, type: 'info' }),
|
||||
LogService.countBy({ ...query, type: 'warning' }),
|
||||
]);
|
||||
|
||||
|
||||
stat.all = allCount;
|
||||
|
||||
|
||||
stat.error = errorCount;
|
||||
|
||||
|
||||
stat.info = infoCount;
|
||||
|
||||
|
||||
stat.warning = warningCount;
|
||||
|
||||
return sendListResponse(req, res, stat);
|
||||
@@ -363,7 +355,7 @@ router.put(
|
||||
message: "values can't be null",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
|
||||
if (!data.name && data.showQuickStart === undefined) {
|
||||
@@ -391,7 +383,6 @@ router.put(
|
||||
};
|
||||
|
||||
if (data.resourceCategory != '') {
|
||||
|
||||
existingQuery.resourceCategory = data.resourceCategory;
|
||||
}
|
||||
const existingApplicationCount = await ApplicationLogService.countBy(
|
||||
@@ -412,11 +403,9 @@ router.put(
|
||||
// application Log is valid
|
||||
const applicationLogUpdate = {};
|
||||
if (data.name) {
|
||||
|
||||
applicationLogUpdate.name = data.name;
|
||||
}
|
||||
if (data.showQuickStart !== undefined) {
|
||||
|
||||
applicationLogUpdate.showQuickStart = data.showQuickStart;
|
||||
}
|
||||
|
||||
@@ -430,7 +419,6 @@ router.put(
|
||||
}
|
||||
);
|
||||
if (resourceCategoryCount && resourceCategoryCount > 0) {
|
||||
|
||||
applicationLogUpdate.resourceCategory = data.resourceCategory;
|
||||
} else {
|
||||
unsetData = { resourceCategory: '' };
|
||||
@@ -441,7 +429,7 @@ router.put(
|
||||
const applicationLog = await ApplicationLogService.updateOneBy(
|
||||
{ _id: currentApplicationLog._id },
|
||||
applicationLogUpdate,
|
||||
|
||||
|
||||
unsetData
|
||||
);
|
||||
return sendItemResponse(req, res, applicationLog);
|
||||
@@ -462,7 +450,6 @@ router.post(
|
||||
const endTime = new Date(startTime.getTime() + duration * 60000);
|
||||
let response;
|
||||
if (filter) {
|
||||
|
||||
response = await LogService.search(
|
||||
{ applicationLogId, deleted: false },
|
||||
filter
|
||||
|
||||
@@ -92,15 +92,12 @@ router.post('/log', isAuthorizedApplicationScanner, async function(req, res) {
|
||||
const selectApplicationSecurityLog = '_id securityId componentId data';
|
||||
|
||||
const findLog = await ApplicationSecurityLogService.findOneBy({
|
||||
|
||||
query: { _id: securityLog._id },
|
||||
populate: populateApplicationSecurityLog,
|
||||
select: selectApplicationSecurityLog,
|
||||
});
|
||||
|
||||
|
||||
const project = await ProjectService.findOneBy({
|
||||
|
||||
query: { _id: findLog.componentId.projectId },
|
||||
select: '_id name users',
|
||||
});
|
||||
@@ -110,28 +107,27 @@ router.post('/log', isAuthorizedApplicationScanner, async function(req, res) {
|
||||
.map((e: $TSFixMe) => ({
|
||||
id: e.userId,
|
||||
})); // This cater for projects with multiple registered members
|
||||
|
||||
|
||||
project.critical = findLog.data.vulnerabilities.critical;
|
||||
|
||||
|
||||
project.high = findLog.data.vulnerabilities.high;
|
||||
|
||||
|
||||
project.moderate = findLog.data.vulnerabilities.moderate;
|
||||
|
||||
|
||||
project.low = findLog.data.vulnerabilities.low;
|
||||
|
||||
|
||||
const critical = findLog.data.advisories
|
||||
.filter((e: $TSFixMe) => e.severity === 'critical')
|
||||
.slice(0, 10);
|
||||
|
||||
|
||||
const high = findLog.data.advisories
|
||||
.filter((e: $TSFixMe) => e.severity === 'high')
|
||||
.slice(0, 10);
|
||||
|
||||
|
||||
const moderate = findLog.data.advisories
|
||||
.filter((e: $TSFixMe) => e.severity === 'moderate')
|
||||
.slice(0, 10);
|
||||
|
||||
|
||||
const low = findLog.data.advisories
|
||||
.filter((e: $TSFixMe) => e.severity === 'low')
|
||||
.slice(0, 10);
|
||||
@@ -251,7 +247,6 @@ router.post('/log', isAuthorizedApplicationScanner, async function(req, res) {
|
||||
|
||||
try {
|
||||
RealtimeService.handleLog({
|
||||
|
||||
securityId: securityLog.securityId,
|
||||
securityLog: findLog,
|
||||
});
|
||||
|
||||
@@ -104,17 +104,14 @@ router.put(
|
||||
const data = {};
|
||||
|
||||
if (name) {
|
||||
|
||||
data.name = name;
|
||||
}
|
||||
|
||||
if (gitRepositoryUrl) {
|
||||
|
||||
data.gitRepositoryUrl = gitRepositoryUrl;
|
||||
}
|
||||
|
||||
if (gitCredential) {
|
||||
|
||||
data.gitCredential = gitCredential;
|
||||
}
|
||||
let unsetData;
|
||||
@@ -127,7 +124,6 @@ router.put(
|
||||
}
|
||||
);
|
||||
if (resourceCategoryCount && resourceCategoryCount) {
|
||||
|
||||
data.resourceCategory = resourceCategory;
|
||||
} else {
|
||||
unsetData = { resourceCategory: '' };
|
||||
@@ -137,7 +133,7 @@ router.put(
|
||||
const applicationSecurity = await ApplicationSecurityService.updateOneBy(
|
||||
{ _id: applicationSecurityId, componentId },
|
||||
data,
|
||||
|
||||
|
||||
unsetData
|
||||
);
|
||||
return sendItemResponse(req, res, applicationSecurity);
|
||||
@@ -392,7 +388,7 @@ router.post(
|
||||
const error = new Error(
|
||||
'Application Security not found or does not exist'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
@@ -51,12 +51,10 @@ router.get(
|
||||
});
|
||||
|
||||
if (details.successEvent.length > 0) {
|
||||
|
||||
details.successEvent = formatEvent(details.successEvent);
|
||||
}
|
||||
|
||||
if (details.failureEvent.length > 0) {
|
||||
|
||||
details.failureEvent = formatEvent(details.failureEvent);
|
||||
}
|
||||
|
||||
@@ -221,7 +219,7 @@ router.put(
|
||||
async (req, res) => {
|
||||
try {
|
||||
const { automatedScriptId } = req.params;
|
||||
|
||||
|
||||
const triggeredId = req.user ? req.user.id : null;
|
||||
const response = await AutomatedScriptService.runResource({
|
||||
triggeredId,
|
||||
@@ -253,7 +251,7 @@ router.delete(
|
||||
select,
|
||||
populate,
|
||||
});
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const response = await AutomatedScriptService.deleteBy(
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@ const sendErrorResponse = require('../middlewares/response').sendErrorResponse;
|
||||
const sendListResponse = require('../middlewares/response').sendListResponse;
|
||||
const sendItemResponse = require('../middlewares/response').sendItemResponse;
|
||||
|
||||
|
||||
import { getUser } from '../middlewares/user';
|
||||
|
||||
import { getUserRole } from '../middlewares/project';
|
||||
|
||||
@@ -70,7 +70,7 @@ router.post('/', getUser, isUserMasterAdmin, async (req, res) => {
|
||||
message: 'Call Log Content is required',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const callLog = await CallLogsService.create(data);
|
||||
return sendItemResponse(req, res, callLog);
|
||||
} catch (error) {
|
||||
|
||||
@@ -95,9 +95,9 @@ router.get('/:projectId', getUser, isAuthorized, async (req, res) => {
|
||||
try {
|
||||
let { skip, limit } = req.query;
|
||||
const { projectId } = req.params;
|
||||
|
||||
|
||||
if (typeof skip === 'string') skip = parseInt(skip);
|
||||
|
||||
|
||||
if (typeof limit === 'string') limit = parseInt(limit);
|
||||
|
||||
const populate = [{ path: 'projectId', select: 'name slug _id' }];
|
||||
@@ -214,20 +214,17 @@ router.put(
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
const data = {};
|
||||
|
||||
|
||||
data.audioFieldName = audioFieldName;
|
||||
|
||||
|
||||
data.callRoutingId = callRoutingId;
|
||||
if (
|
||||
req.files &&
|
||||
|
||||
req.files[audioFieldName] &&
|
||||
|
||||
req.files[audioFieldName][0].filename
|
||||
) {
|
||||
|
||||
data.file = req.files[audioFieldName][0].filename;
|
||||
|
||||
|
||||
data.fileName = req.files[audioFieldName][0].originalname;
|
||||
}
|
||||
const CallRouting = await CallRoutingService.updateRoutingSchemaAudio(
|
||||
@@ -248,7 +245,7 @@ router.delete(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const { projectId, callRoutingId } = req.params;
|
||||
|
||||
|
||||
const userId = req.user.id;
|
||||
if (!callRoutingId) {
|
||||
return sendErrorResponse(req, res, {
|
||||
@@ -290,12 +287,10 @@ router.delete(
|
||||
routingSchema = routingSchema.routingSchema;
|
||||
const query = {};
|
||||
if (backup) {
|
||||
|
||||
query.filename = routingSchema.backup_introAudio;
|
||||
routingSchema.backup_introAudio = null;
|
||||
routingSchema.backup_introAudioName = '';
|
||||
} else {
|
||||
|
||||
query.filename = routingSchema.introAudio;
|
||||
routingSchema.introAudio = null;
|
||||
routingSchema.introAudioName = '';
|
||||
|
||||
@@ -82,7 +82,7 @@ router.delete('/store/:id', async (req, res) => {
|
||||
router.post('/certOrder', async (req, res) => {
|
||||
try {
|
||||
const domains = [];
|
||||
|
||||
|
||||
const greenlock = global.greenlock;
|
||||
// to refresh the managers set clearManager to true
|
||||
const { domain, clearManagers } = req.body;
|
||||
@@ -123,7 +123,6 @@ router.post('/certOrder', async (req, res) => {
|
||||
select: 'domains',
|
||||
});
|
||||
|
||||
|
||||
for (const statusPage of statusPages) {
|
||||
for (const domain of statusPage.domains) {
|
||||
if (
|
||||
@@ -168,7 +167,6 @@ router.post('/certOrder', async (req, res) => {
|
||||
// id => domain/subdomain
|
||||
router.delete('/certDelete/:id', async (req, res) => {
|
||||
try {
|
||||
|
||||
const greenlock = global.greenlock;
|
||||
const { id } = req.body;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ const isUserAdmin = require('../middlewares/project').isUserAdmin;
|
||||
const getUser = require('../middlewares/user').getUser;
|
||||
const getSubProjects = require('../middlewares/subProject').getSubProjects;
|
||||
|
||||
|
||||
import { isAuthorized } from '../middlewares/authorization';
|
||||
const sendErrorResponse = require('../middlewares/response').sendErrorResponse;
|
||||
const sendItemResponse = require('../middlewares/response').sendItemResponse;
|
||||
@@ -46,7 +45,7 @@ router.post('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
message: "values can't be null",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
|
||||
if (!data.name) {
|
||||
@@ -68,14 +67,12 @@ router.post('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
const component = await ComponentService.create(data);
|
||||
|
||||
const user = await UserService.findOneBy({
|
||||
|
||||
query: { _id: req.user.id },
|
||||
select: 'name _id',
|
||||
});
|
||||
|
||||
if (component) {
|
||||
try {
|
||||
|
||||
NotificationService.create(
|
||||
component.projectId._id || component.projectId,
|
||||
`A New Component was Created with name ${component.name} by ${user.name}`,
|
||||
@@ -205,10 +202,9 @@ router.get(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const type = req.query.type;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
const query = type
|
||||
? { projectId: { $in: subProjectIds }, type }
|
||||
@@ -250,10 +246,9 @@ router.get(
|
||||
try {
|
||||
const componentId = req.params.componentId;
|
||||
const type = req.query.type;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
const query = type
|
||||
? { _id: componentId, projectId: { $in: subProjectIds }, type }
|
||||
@@ -288,10 +283,9 @@ router.post(
|
||||
try {
|
||||
const { startDate, endDate } = req.body;
|
||||
const componentId = req.params.componentId;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
|
||||
// Check that component exists
|
||||
@@ -349,9 +343,7 @@ router.post(
|
||||
const monitorUptime =
|
||||
uptimePercents.reduce(
|
||||
(a, b) =>
|
||||
|
||||
parseFloat(a || 100) +
|
||||
|
||||
parseFloat(b || 100)
|
||||
) / uptimePercents.length;
|
||||
|
||||
@@ -391,10 +383,9 @@ router.get(
|
||||
try {
|
||||
const componentId = req.params.componentId;
|
||||
const type = req.query.type;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
|
||||
const query = type
|
||||
@@ -704,10 +695,8 @@ router.get(
|
||||
getSubProjects,
|
||||
async function(req, res) {
|
||||
try {
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
|
||||
// Call the ComponentService.
|
||||
@@ -719,7 +708,6 @@ router.get(
|
||||
let allComponents: $TSFixMe = [];
|
||||
|
||||
components.map(component => {
|
||||
|
||||
allComponents = [...allComponents, ...component.components];
|
||||
return component;
|
||||
});
|
||||
@@ -736,7 +724,6 @@ router.get(
|
||||
{ path: 'resourceCategory', select: 'name' },
|
||||
];
|
||||
await Promise.all(
|
||||
|
||||
allComponents.map(async component => {
|
||||
const componentErrorTrackers = await ErrorTrackerService.findBy(
|
||||
{
|
||||
@@ -778,7 +765,7 @@ router.delete(
|
||||
componentId: componentId,
|
||||
projectId: projectId,
|
||||
},
|
||||
|
||||
|
||||
req.user.id
|
||||
);
|
||||
const component = await ComponentService.deleteBy(
|
||||
@@ -786,7 +773,7 @@ router.delete(
|
||||
_id: componentId,
|
||||
projectId: projectId,
|
||||
},
|
||||
|
||||
|
||||
req.user.id
|
||||
);
|
||||
if (component) {
|
||||
|
||||
@@ -78,14 +78,12 @@ router.post('/log', isAuthorizedContainerScanner, async function(req, res) {
|
||||
{ path: 'componentId', select: 'name slug projectId' },
|
||||
];
|
||||
const findLog = await ContainerSecurityLogService.findOneBy({
|
||||
|
||||
query: { _id: securityLog._id },
|
||||
select: selectContainerLog,
|
||||
populate: populateContainerLog,
|
||||
});
|
||||
|
||||
|
||||
const project = await ProjectService.findOneBy({
|
||||
|
||||
query: { _id: findLog.componentId.projectId },
|
||||
select: '_id name users',
|
||||
});
|
||||
@@ -94,27 +92,27 @@ router.post('/log', isAuthorizedContainerScanner, async function(req, res) {
|
||||
.map((e: $TSFixMe) => ({
|
||||
id: e.userId,
|
||||
})); // This cater for projects with multiple registered members
|
||||
|
||||
|
||||
project.critical = findLog.data.vulnerabilityInfo.critical;
|
||||
|
||||
|
||||
project.high = findLog.data.vulnerabilityInfo.high;
|
||||
|
||||
|
||||
project.moderate = findLog.data.vulnerabilityInfo.moderate;
|
||||
|
||||
|
||||
project.low = findLog.data.vulnerabilityInfo.low;
|
||||
|
||||
|
||||
const critical = findLog.data.vulnerabilityData
|
||||
.filter((e: $TSFixMe) => e.severity === 'critical')
|
||||
.slice(0, 10);
|
||||
|
||||
|
||||
const high = findLog.data.vulnerabilityData
|
||||
.filter((e: $TSFixMe) => e.severity === 'high')
|
||||
.slice(0, 10);
|
||||
|
||||
|
||||
const moderate = findLog.data.vulnerabilityData
|
||||
.filter((e: $TSFixMe) => e.severity === 'moderate')
|
||||
.slice(0, 5);
|
||||
|
||||
|
||||
const low = findLog.data.vulnerabilityData
|
||||
.filter((e: $TSFixMe) => e.severity === 'low')
|
||||
.slice(0, 5);
|
||||
|
||||
@@ -104,22 +104,18 @@ router.put(
|
||||
const data = {};
|
||||
|
||||
if (name) {
|
||||
|
||||
data.name = name;
|
||||
}
|
||||
|
||||
if (dockerCredential) {
|
||||
|
||||
data.dockerCredential = dockerCredential;
|
||||
}
|
||||
|
||||
if (imagePath) {
|
||||
|
||||
data.imagePath = imagePath;
|
||||
}
|
||||
|
||||
if (imageTags) {
|
||||
|
||||
data.imageTags = imageTags;
|
||||
}
|
||||
let unsetData;
|
||||
@@ -132,7 +128,6 @@ router.put(
|
||||
}
|
||||
);
|
||||
if (resourceCategoryCount && resourceCategoryCount > 0) {
|
||||
|
||||
data.resourceCategory = resourceCategory;
|
||||
} else {
|
||||
unsetData = { resourceCategory: '' };
|
||||
@@ -142,7 +137,7 @@ router.put(
|
||||
const containerSecurity = await ContainerSecurityService.updateOneBy(
|
||||
{ _id: containerSecurityId, componentId },
|
||||
data,
|
||||
|
||||
|
||||
unsetData
|
||||
);
|
||||
return sendItemResponse(req, res, containerSecurity);
|
||||
@@ -377,7 +372,7 @@ router.post(
|
||||
const error = new Error(
|
||||
'Container Security not found or does not exist'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
|
||||
if (!fieldName || !fieldName.trim()) {
|
||||
const error = new Error('Field name is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!fieldType || !fieldType.trim()) {
|
||||
const error = new Error('Field type is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Custom field with this name already exist'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -96,14 +96,14 @@ router.put('/:projectId/:customFieldId', getUser, isAuthorized, async function(
|
||||
|
||||
if (!fieldName || !fieldName.trim()) {
|
||||
const error = new Error('Field name is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!fieldType || !fieldType.trim()) {
|
||||
const error = new Error('Field type is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -119,7 +119,7 @@ router.put('/:projectId/:customFieldId', getUser, isAuthorized, async function(
|
||||
const error = new Error(
|
||||
'Custom field with this name already exist'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -24,21 +24,21 @@ router.put('/default', async (req, res) => {
|
||||
}
|
||||
|
||||
const data = {};
|
||||
|
||||
|
||||
if (store) data.store = store;
|
||||
|
||||
|
||||
if (challenges) data.challenges = challenges;
|
||||
|
||||
|
||||
if (renewOffset) data.renewOffset = renewOffset;
|
||||
|
||||
|
||||
if (renewStagger) data.renewStagger = renewStagger;
|
||||
|
||||
|
||||
if (accountKeyType) data.accountKeyType = accountKeyType;
|
||||
|
||||
|
||||
if (serverKeyType) data.serverKeyType = serverKeyType;
|
||||
|
||||
|
||||
if (subscriberEmail) data.subscriberEmail = subscriberEmail;
|
||||
|
||||
|
||||
if (agreeToTerms) data.agreeToTerms = agreeToTerms;
|
||||
|
||||
// if there's no default value
|
||||
|
||||
@@ -98,15 +98,12 @@ router.put(
|
||||
|
||||
const data = {};
|
||||
if (dockerRegistryUrl) {
|
||||
|
||||
data.dockerRegistryUrl = dockerRegistryUrl;
|
||||
}
|
||||
if (dockerUsername) {
|
||||
|
||||
data.dockerUsername = dockerUsername;
|
||||
}
|
||||
if (dockerPassword) {
|
||||
|
||||
data.dockerPassword = dockerPassword;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ router.put(
|
||||
const response = await DomainVerificationService.updateOneBy(
|
||||
{ _id: domainId },
|
||||
{ verified: true, verifiedAt: Date.now() },
|
||||
|
||||
|
||||
subDomain
|
||||
);
|
||||
return sendItemResponse(req, res, response);
|
||||
@@ -135,7 +135,7 @@ router.post('/:projectId/domain', getUser, isAuthorized, async (req, res) => {
|
||||
|
||||
if (!domain || !domain.trim()) {
|
||||
const error = new Error('Please specify a domain');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -148,7 +148,7 @@ router.post('/:projectId/domain', getUser, isAuthorized, async (req, res) => {
|
||||
const error = new Error(
|
||||
'Please specify only domains and not sub-domains'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ router.post('/:projectId/domain', getUser, isAuthorized, async (req, res) => {
|
||||
);
|
||||
if (doesDomainBelongToProject) {
|
||||
const error = new Error('Domain already belong to another project');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -207,7 +207,7 @@ router.put(
|
||||
|
||||
if (!domain || !domain.trim()) {
|
||||
const error = new Error('Please specify a domain');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -220,7 +220,7 @@ router.put(
|
||||
const error = new Error(
|
||||
'Please specify only domains and not sub-domains'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -234,7 +234,7 @@ router.put(
|
||||
const error = new Error(
|
||||
'Domain already belong to another project'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -278,7 +278,7 @@ router.delete(
|
||||
const projectArr = await ProjectService.findSubprojectId(projectId);
|
||||
const projectIdInArr = await DomainVerificationService.findDomain(
|
||||
domainId,
|
||||
|
||||
|
||||
projectArr
|
||||
);
|
||||
const response = await DomainVerificationService.deleteBy({
|
||||
|
||||
@@ -85,7 +85,6 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
const data = req.body;
|
||||
data.projectId = req.params.projectId;
|
||||
const user = await UserService.findOneBy({
|
||||
|
||||
query: { _id: req.user.id },
|
||||
select: 'email',
|
||||
});
|
||||
@@ -167,7 +166,6 @@ router.put('/:projectId/:emailSmtpId', getUser, isAuthorized, async function(
|
||||
const data = req.body;
|
||||
const emailSmtpId = req.params.emailSmtpId;
|
||||
const user = await UserService.findOneBy({
|
||||
|
||||
query: { _id: req.user.id },
|
||||
select: 'email',
|
||||
});
|
||||
|
||||
@@ -3,13 +3,11 @@ import EmailTemplateService from '../services/emailTemplateService';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
import createDOMPurify from 'dompurify';
|
||||
const jsdom = require('jsdom').jsdom;
|
||||
const window = jsdom('').defaultView;
|
||||
const DOMPurify = createDOMPurify(window);
|
||||
|
||||
|
||||
import { isAuthorized } from '../middlewares/authorization';
|
||||
const getUser = require('../middlewares/user').getUser;
|
||||
const isUserOwner = require('../middlewares/project').isUserOwner;
|
||||
@@ -185,7 +183,7 @@ router.delete(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const emailTemplateId = req.params.emailTemplateId;
|
||||
|
||||
|
||||
const userId = req.user.id;
|
||||
const emailTemplate = await EmailTemplateService.deleteBy(
|
||||
{ _id: emailTemplateId },
|
||||
|
||||
@@ -46,7 +46,7 @@ router.post(
|
||||
message: "values can't be null",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
if (!data.name) {
|
||||
return sendErrorResponse(req, res, {
|
||||
@@ -76,17 +76,15 @@ router.post(
|
||||
populate: populateComponent,
|
||||
}),
|
||||
UserService.findOneBy({
|
||||
|
||||
query: { _id: req.user.id },
|
||||
select: 'name _id',
|
||||
}),
|
||||
]);
|
||||
|
||||
try {
|
||||
|
||||
NotificationService.create(
|
||||
component.projectId._id,
|
||||
|
||||
|
||||
`A New Error Tracker was Created with name ${errorTracker.name} by ${user.name}`,
|
||||
user._id,
|
||||
'errortrackeraddremove'
|
||||
@@ -146,7 +144,7 @@ router.delete(
|
||||
_id: errorTrackerId,
|
||||
componentId: componentId,
|
||||
},
|
||||
|
||||
|
||||
req.user.id
|
||||
);
|
||||
if (errorTracker) {
|
||||
@@ -223,7 +221,7 @@ router.put(
|
||||
message: "values can't be null",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
if (!data.name && data.showQuickStart === undefined) {
|
||||
return sendErrorResponse(req, res, {
|
||||
@@ -255,7 +253,6 @@ router.put(
|
||||
componentId: componentId,
|
||||
};
|
||||
if (data.resourceCategory != '') {
|
||||
|
||||
existingQuery.resourceCategory = data.resourceCategory;
|
||||
}
|
||||
const existingErrorTracking = await ErrorTrackerService.findBy({
|
||||
@@ -286,11 +283,9 @@ router.put(
|
||||
// Error Tracker is valid
|
||||
const errorTrackerUpdate = {};
|
||||
if (data.name) {
|
||||
|
||||
errorTrackerUpdate.name = data.name;
|
||||
}
|
||||
if (data.showQuickStart !== undefined) {
|
||||
|
||||
errorTrackerUpdate.showQuickStart = data.showQuickStart;
|
||||
}
|
||||
|
||||
@@ -304,7 +299,6 @@ router.put(
|
||||
}
|
||||
);
|
||||
if (resourceCategoryCount && resourceCategoryCount > 0) {
|
||||
|
||||
errorTrackerUpdate.resourceCategory = data.resourceCategory;
|
||||
} else {
|
||||
unsetData = { resourceCategory: '' };
|
||||
@@ -315,7 +309,7 @@ router.put(
|
||||
const errorTracker = await ErrorTrackerService.updateOneBy(
|
||||
{ _id: currentErrorTracker._id },
|
||||
errorTrackerUpdate,
|
||||
|
||||
|
||||
unsetData
|
||||
);
|
||||
return sendItemResponse(req, res, errorTracker);
|
||||
@@ -417,16 +411,13 @@ router.post(
|
||||
|
||||
const query = {};
|
||||
|
||||
|
||||
if (errorTrackerId) query.errorTrackerId = errorTrackerId;
|
||||
|
||||
if (startDate && endDate)
|
||||
|
||||
query.createdAt = { $gte: startDate, $lte: endDate };
|
||||
|
||||
if (filters) {
|
||||
for (const [key, value] of Object.entries(filters)) {
|
||||
|
||||
query[key] = value;
|
||||
}
|
||||
}
|
||||
@@ -624,7 +615,7 @@ router.post(
|
||||
updateData = {
|
||||
ignored: true,
|
||||
ignoredAt: new Date(),
|
||||
|
||||
|
||||
ignoredById: req.user.id,
|
||||
resolved: false,
|
||||
resolvedAt: '',
|
||||
@@ -658,7 +649,7 @@ router.post(
|
||||
ignoredById: null,
|
||||
resolved: true,
|
||||
resolvedAt: new Date(),
|
||||
|
||||
|
||||
resolvedById: req.user.id,
|
||||
};
|
||||
break;
|
||||
@@ -680,7 +671,7 @@ router.post(
|
||||
// add action to timeline for this particular issue
|
||||
const timelineData = {
|
||||
issueId: currentIssueId,
|
||||
|
||||
|
||||
createdById: req.user ? req.user.id : null,
|
||||
status: action,
|
||||
};
|
||||
@@ -768,14 +759,11 @@ router.post(
|
||||
|
||||
const query = {};
|
||||
|
||||
|
||||
query.fingerprintHash = fingerprintHash;
|
||||
|
||||
|
||||
if (errorTrackerId) query.errorTrackerId = errorTrackerId;
|
||||
|
||||
if (startDate && endDate)
|
||||
|
||||
query.createdAt = { $gte: startDate, $lte: endDate };
|
||||
|
||||
const errorEvents = await ErrorEventService.findBy({
|
||||
@@ -968,7 +956,7 @@ router.post(
|
||||
const data = {
|
||||
issueId,
|
||||
userId: teamMemberUserId,
|
||||
|
||||
|
||||
createdById: req.user ? req.user.id : null,
|
||||
};
|
||||
// find if the issue member exist in the project
|
||||
@@ -1116,7 +1104,7 @@ router.post(
|
||||
const data = {
|
||||
removed: true,
|
||||
removedAt: new Date(),
|
||||
|
||||
|
||||
removedById: req.user ? req.user.id : null,
|
||||
};
|
||||
// find the issueMember by the 3 parameters, and update it
|
||||
@@ -1203,7 +1191,7 @@ router.delete(
|
||||
_id: issueId,
|
||||
errorTrackerId,
|
||||
},
|
||||
|
||||
|
||||
req.user.id,
|
||||
componentId
|
||||
);
|
||||
|
||||
@@ -22,7 +22,7 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
req.params.projectId,
|
||||
req.body.feedback,
|
||||
req.body.page,
|
||||
|
||||
|
||||
req.user.id
|
||||
);
|
||||
return sendItemResponse(req, res, feedback);
|
||||
|
||||
@@ -91,21 +91,17 @@ router.put(
|
||||
const data = {};
|
||||
|
||||
if (gitUsername) {
|
||||
|
||||
data.gitUsername = gitUsername;
|
||||
}
|
||||
if (gitPassword) {
|
||||
|
||||
data.gitPassword = gitPassword;
|
||||
}
|
||||
|
||||
if (sshTitle) {
|
||||
|
||||
data.sshTitle = sshTitle;
|
||||
}
|
||||
|
||||
if (sshPrivateKey) {
|
||||
|
||||
data.sshPrivateKey = sshPrivateKey;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ router.post('/:projectId', getUser, isAuthorized, async (req, res) => {
|
||||
try {
|
||||
const { name, teams } = req.body;
|
||||
const { projectId } = req.params;
|
||||
|
||||
|
||||
const userId = req.user.id;
|
||||
|
||||
if (!name) {
|
||||
@@ -43,17 +43,14 @@ router.get(
|
||||
isAuthorized,
|
||||
getSubProjects,
|
||||
async (req, res) => {
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => {
|
||||
? req.user.subProjects.map((project: $TSFixMe) => {
|
||||
return { id: project._id, name: project.name };
|
||||
})
|
||||
: null;
|
||||
try {
|
||||
const groups = await Promise.all(
|
||||
subProjectIds.map(async (project: $TSFixMe) => {
|
||||
|
||||
const groups = await GroupService.findBy({
|
||||
projectId: project.id,
|
||||
});
|
||||
@@ -94,11 +91,9 @@ router.put('/:projectId/:groupId', getUser, isAuthorized, async (req, res) => {
|
||||
|
||||
const data = {};
|
||||
if (name) {
|
||||
|
||||
data.name = name;
|
||||
}
|
||||
if (teams) {
|
||||
|
||||
data.teams = teams;
|
||||
}
|
||||
|
||||
@@ -120,7 +115,7 @@ router.delete(
|
||||
async (req, res) => {
|
||||
try {
|
||||
const { groupId, projectId } = req.params;
|
||||
|
||||
|
||||
const userId = req.user.id;
|
||||
|
||||
const [deleteGroup] = await Promise.all([
|
||||
|
||||
@@ -12,7 +12,6 @@ import UserService from '../services/userService';
|
||||
import MonitorService from '../services/monitorService';
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
import { isAuthorized } from '../middlewares/authorization';
|
||||
import errorService from 'common-server/utils/error';
|
||||
const isUserAdmin = require('../middlewares/project').isUserAdmin;
|
||||
@@ -58,7 +57,6 @@ router.post(
|
||||
try {
|
||||
const { incidentId, name, probeId } = req.body;
|
||||
|
||||
|
||||
const incident = await IncidentService.acknowledge(
|
||||
incidentId,
|
||||
null,
|
||||
@@ -81,7 +79,6 @@ router.post(
|
||||
try {
|
||||
const { incidentId, name, probeId } = req.body;
|
||||
|
||||
|
||||
const incident = await IncidentService.resolve(
|
||||
incidentId,
|
||||
null,
|
||||
@@ -131,16 +128,14 @@ router.post(
|
||||
const description = req.body.description;
|
||||
const customFields = req.body.customFields;
|
||||
const monitors = req.body.monitors;
|
||||
|
||||
|
||||
const userId = req.user
|
||||
?
|
||||
req.user.id === 'API'
|
||||
? req.user.id === 'API'
|
||||
? null
|
||||
:
|
||||
req.user.id
|
||||
: req.user.id
|
||||
: null;
|
||||
let createdByApi = false;
|
||||
|
||||
|
||||
if (req.user && req.user.id === 'API') {
|
||||
createdByApi = true;
|
||||
}
|
||||
@@ -258,7 +253,7 @@ router.post(
|
||||
const end = moment(endDate).toDate();
|
||||
query = {
|
||||
'monitors.monitorId': { $in: [monitorId] },
|
||||
|
||||
|
||||
createdAt: { $gte: start, $lte: end },
|
||||
};
|
||||
}
|
||||
@@ -519,19 +514,17 @@ router.get(
|
||||
getSubProjects,
|
||||
async function(req, res) {
|
||||
try {
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
// Call the IncidentService.
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const { isHome } = req.query;
|
||||
const incident = await IncidentService.getUnresolvedIncidents(
|
||||
subProjectIds,
|
||||
userId,
|
||||
|
||||
|
||||
isHome
|
||||
);
|
||||
return sendItemResponse(req, res, incident);
|
||||
@@ -547,16 +540,13 @@ router.post(
|
||||
isAuthorized,
|
||||
async function(req, res) {
|
||||
try {
|
||||
|
||||
const userId = req.user
|
||||
?
|
||||
req.user.id === 'API'
|
||||
? req.user.id === 'API'
|
||||
? null
|
||||
:
|
||||
req.user.id
|
||||
: req.user.id
|
||||
: null;
|
||||
let acknowledgedByApi = false;
|
||||
|
||||
|
||||
if (req.user && req.user.id === 'API') {
|
||||
acknowledgedByApi = true;
|
||||
}
|
||||
@@ -566,11 +556,11 @@ router.post(
|
||||
const incident = await IncidentService.acknowledge(
|
||||
incidentId,
|
||||
userId,
|
||||
|
||||
|
||||
req.user.name,
|
||||
null,
|
||||
null,
|
||||
|
||||
|
||||
null,
|
||||
acknowledgedByApi
|
||||
);
|
||||
@@ -717,16 +707,13 @@ router.post(
|
||||
isAuthorized,
|
||||
async function(req, res) {
|
||||
try {
|
||||
|
||||
const userId = req.user
|
||||
?
|
||||
req.user.id === 'API'
|
||||
? req.user.id === 'API'
|
||||
? null
|
||||
:
|
||||
req.user.id
|
||||
: req.user.id
|
||||
: null;
|
||||
let resolvedByApi = false;
|
||||
|
||||
|
||||
if (req.user && req.user.id === 'API') {
|
||||
resolvedByApi = true;
|
||||
}
|
||||
@@ -739,7 +726,7 @@ router.post(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
||||
|
||||
null,
|
||||
resolvedByApi
|
||||
);
|
||||
@@ -883,7 +870,6 @@ router.post(
|
||||
isAuthorized,
|
||||
async function(req, res) {
|
||||
try {
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const { incidentId } = req.params;
|
||||
// Call the IncidentService
|
||||
@@ -984,7 +970,6 @@ router.post(
|
||||
});
|
||||
const idNumber = incident.idNumber;
|
||||
|
||||
|
||||
const userId = req.user.id;
|
||||
if (!data.content) {
|
||||
return sendErrorResponse(req, res, {
|
||||
@@ -1081,7 +1066,6 @@ router.post(
|
||||
|
||||
// handle creation or updating
|
||||
if (!data.id) {
|
||||
|
||||
data.createdById = req.user.id;
|
||||
data.monitors = incident.monitors.map(
|
||||
(monitor: $TSFixMe) => monitor.monitorId
|
||||
@@ -1218,7 +1202,7 @@ router.post(
|
||||
}),
|
||||
IncidentTimelineService.create({
|
||||
incidentId: incident._id,
|
||||
|
||||
|
||||
createdById: req.user.id,
|
||||
incident_state: data.incident_state,
|
||||
status,
|
||||
@@ -1333,9 +1317,9 @@ router.get(
|
||||
count,
|
||||
} = await StatusPageService.getStatusPagesForIncident(
|
||||
incident._id,
|
||||
|
||||
|
||||
parseInt(req.query.skip) || 0,
|
||||
|
||||
|
||||
parseInt(req.query.limit) || 10
|
||||
);
|
||||
return sendListResponse(req, res, statusPages, count);
|
||||
@@ -1378,7 +1362,7 @@ router.delete(
|
||||
_id: incidentMessageId,
|
||||
incidentId,
|
||||
},
|
||||
|
||||
|
||||
req.user.id
|
||||
),
|
||||
]);
|
||||
@@ -1467,7 +1451,7 @@ router.delete(
|
||||
}),
|
||||
IncidentTimelineService.create({
|
||||
incidentId,
|
||||
|
||||
|
||||
createdById: req.user.id,
|
||||
status,
|
||||
}),
|
||||
@@ -1562,9 +1546,8 @@ router.get(
|
||||
let skip = 0,
|
||||
limit = 0;
|
||||
if (type === 'investigation') {
|
||||
|
||||
skip = req.query.skip || 0;
|
||||
|
||||
|
||||
limit = req.query.limit || 10;
|
||||
}
|
||||
|
||||
@@ -1691,7 +1674,6 @@ router.get(
|
||||
...callScheduleStatus,
|
||||
];
|
||||
incidentMessages.sort(
|
||||
|
||||
(a, b) =>
|
||||
typeof a.schedule !== 'object' &&
|
||||
b.createdAt - a.createdAt
|
||||
@@ -1702,7 +1684,6 @@ router.get(
|
||||
a.status !== 'internal notes updated'
|
||||
);
|
||||
|
||||
|
||||
result = await Services.rearrangeDuty(filteredMsg);
|
||||
}
|
||||
}
|
||||
@@ -1721,7 +1702,7 @@ router.delete('/:projectId/:incidentId', getUser, isUserAdmin, async function(
|
||||
const { projectId, incidentId } = req.params;
|
||||
const incident = await IncidentService.deleteBy(
|
||||
{ _id: incidentId, projectId },
|
||||
|
||||
|
||||
req.user.id
|
||||
);
|
||||
if (incident) {
|
||||
@@ -1774,7 +1755,6 @@ router.get(
|
||||
isAuthorized,
|
||||
async function(req, res) {
|
||||
try {
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
|
||||
// get incident properties to build url
|
||||
@@ -1786,7 +1766,7 @@ router.get(
|
||||
select: 'idNumber projectId slug',
|
||||
populate: [{ path: 'projectId', select: 'slug' }],
|
||||
}),
|
||||
|
||||
|
||||
IncidentService.resolve(incidentId, userId),
|
||||
]);
|
||||
|
||||
@@ -1797,9 +1777,9 @@ router.get(
|
||||
title_message: 'Incident Resolved',
|
||||
body_message: 'Your incident is now resolved.',
|
||||
action: 'resolve',
|
||||
|
||||
|
||||
dashboard_url: `${global.dashboardHost}/project/${project.slug}/incidents/${incident.slug}`,
|
||||
|
||||
|
||||
apiUrl: global.apiHost,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -1820,7 +1800,6 @@ router.get(
|
||||
isAuthorized,
|
||||
async function(req, res) {
|
||||
try {
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
|
||||
// get incident properties to build url
|
||||
@@ -1832,7 +1811,7 @@ router.get(
|
||||
select: 'idNumber projectId slug',
|
||||
populate: [{ path: 'projectId', select: 'slug' }],
|
||||
}),
|
||||
|
||||
|
||||
IncidentService.acknowledge(incidentId, userId, req.user.name),
|
||||
]);
|
||||
|
||||
@@ -1843,9 +1822,9 @@ router.get(
|
||||
title_message: 'Incident Acknowledged',
|
||||
body_message: 'Your incident is now acknowledged.',
|
||||
action: 'acknowledge',
|
||||
|
||||
|
||||
dashboard_url: `${global.dashboardHost}/project/${project.slug}/incidents/${incident.slug}`,
|
||||
|
||||
|
||||
apiUrl: global.apiHost,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@@ -48,28 +48,28 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
|
||||
if (!name || !name.trim()) {
|
||||
const error = new Error('SLA name is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (duration && isNaN(duration)) {
|
||||
const error = new Error('Please use numeric values for duration');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (!alertTime || !alertTime.trim()) {
|
||||
const error = new Error('Please set alert time for this SLA');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (isNaN(alertTime)) {
|
||||
const error = new Error('Please use numeric values for alert time');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Alert time should be always less than duration'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -102,28 +102,28 @@ router.put('/:projectId/:incidentSlaId', getUser, isAuthorized, async function(
|
||||
|
||||
if (!handleDefault && (!name || !name.trim())) {
|
||||
const error = new Error('SLA name is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (!handleDefault && duration && isNaN(duration)) {
|
||||
const error = new Error('Please use numeric values for duration');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (!handleDefault && (!alertTime || !alertTime.trim())) {
|
||||
const error = new Error('Please set alert time for this SLA');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (!handleDefault && isNaN(alertTime)) {
|
||||
const error = new Error('Please use numeric values for alert time');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -132,7 +132,7 @@ router.put('/:projectId/:incidentSlaId', getUser, isAuthorized, async function(
|
||||
const error = new Error(
|
||||
'Alert time should be always less than duration'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
@@ -15,25 +15,25 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
|
||||
if (!projectId) {
|
||||
const error = new Error('Project Id must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
if (!name) {
|
||||
const error = new Error('Name must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
if (!incidentState) {
|
||||
const error = new Error('Incident state must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
if (!incidentNote) {
|
||||
const error = new Error('Incident note must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ router.get('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
|
||||
if (!projectId) {
|
||||
const error = new Error('Project Id must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ router.put('/:projectId/:templateId', getUser, isAuthorized, async function(
|
||||
|
||||
if (!projectId) {
|
||||
const error = new Error('Project Id must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -100,25 +100,25 @@ router.put('/:projectId/:templateId', getUser, isAuthorized, async function(
|
||||
const error = new Error(
|
||||
'Incident note template Id must be present'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
if (!name) {
|
||||
const error = new Error('Name must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
if (!incidentState) {
|
||||
const error = new Error('Incident state must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
if (!incidentNote) {
|
||||
const error = new Error('Incident note must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ router.delete('/:projectId/:templateId', getUser, isAuthorized, async function(
|
||||
|
||||
if (!projectId) {
|
||||
const error = new Error('Project Id must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ router.delete('/:projectId/:templateId', getUser, isAuthorized, async function(
|
||||
const error = new Error(
|
||||
'Incident note template Id must be present'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ router.get('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
const [IncidentPriorities, count] = await Promise.all([
|
||||
IncidentPrioritiesService.findBy(
|
||||
{ query: { projectId }, select: selectIncPriority },
|
||||
|
||||
|
||||
limit,
|
||||
skip
|
||||
),
|
||||
|
||||
@@ -28,7 +28,7 @@ router.get('/:projectId/default', getUser, isAuthorized, async function(
|
||||
const { projectId } = req.params;
|
||||
if (!projectId) {
|
||||
const error = new Error('Project Id must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ router.get('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
|
||||
if (!projectId) {
|
||||
const error = new Error('Project Id must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -187,13 +187,13 @@ router.delete('/:projectId/:templateId', getUser, isAuthorized, async function(
|
||||
|
||||
if (!projectId) {
|
||||
const error = new Error('Project Id must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
if (!templateId) {
|
||||
const error = new Error('Incident settings Id must be present.');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -222,25 +222,25 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
|
||||
if (!projectId) {
|
||||
const error = new Error('Project Id must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
if (!name) {
|
||||
const error = new Error('Name must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
if (!title) {
|
||||
const error = new Error('Title must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
if (!incidentPriority) {
|
||||
const error = new Error('Incident priority must be present');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -251,7 +251,7 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
});
|
||||
if (!priority) {
|
||||
const error = new Error("Incident priority doesn't exist.");
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ router.post(
|
||||
const error = new Error(
|
||||
'Please specify a name for the incoming request'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ router.post(
|
||||
const error = new Error(
|
||||
'Incoming request with this name already exist'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ router.put(
|
||||
const error = new Error(
|
||||
'Please specify a name for the incoming request'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -148,12 +148,11 @@ router.put(
|
||||
const error = new Error(
|
||||
'Incoming request with this name already exist'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
incomingRequest = await IncomingRequestService.updateOneBy(
|
||||
{ requestId, projectId },
|
||||
data
|
||||
@@ -260,12 +259,11 @@ router.post(
|
||||
const error = new Error(
|
||||
'Incoming request with this name already exist'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
incomingRequest = await IncomingRequestService.updateOneBy(
|
||||
{ requestId, projectId },
|
||||
data
|
||||
|
||||
@@ -14,26 +14,26 @@ router.post('/', async function(req, res) {
|
||||
body.volume = JSON.parse(body.volume);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
data.type = body.type;
|
||||
|
||||
|
||||
data.name = body.fullname;
|
||||
|
||||
|
||||
data.email = body.email;
|
||||
|
||||
|
||||
data.phone = body.phone;
|
||||
|
||||
|
||||
data.website = body.website;
|
||||
|
||||
|
||||
data.companySize =
|
||||
body.volume && body.volume.text ? body.volume.text : null;
|
||||
|
||||
|
||||
data.country = body.country;
|
||||
|
||||
|
||||
data.message = body.message || null;
|
||||
|
||||
|
||||
data.whitepaperName = body.whitepaper_name || null;
|
||||
|
||||
|
||||
data.source = JSON.parse(body.source) || null;
|
||||
const lead = await LeadService.create(data);
|
||||
return sendItemResponse(req, res, lead);
|
||||
|
||||
@@ -46,47 +46,43 @@ router.post('/ping/:monitorId', isAuthorizedLighthouse, async function(
|
||||
data = {};
|
||||
|
||||
data = req.body;
|
||||
|
||||
|
||||
data.lighthouseScanStatus =
|
||||
resp && resp.lighthouseScanStatus
|
||||
? resp.lighthouseScanStatus
|
||||
: null;
|
||||
|
||||
|
||||
data.performance = resp && resp.performance ? resp.performance : null;
|
||||
|
||||
|
||||
data.accessibility =
|
||||
resp && resp.accessibility ? resp.accessibility : null;
|
||||
|
||||
|
||||
data.bestPractices =
|
||||
resp && resp.bestPractices ? resp.bestPractices : null;
|
||||
|
||||
|
||||
data.seo = resp && resp.seo ? resp.seo : null;
|
||||
|
||||
|
||||
data.pwa = resp && resp.pwa ? resp.pwa : null;
|
||||
|
||||
|
||||
data.lighthouseData =
|
||||
resp && resp.lighthouseData ? resp.lighthouseData : null;
|
||||
|
||||
|
||||
data.monitorId = req.params.monitorId || monitor._id;
|
||||
|
||||
|
||||
const probeId = await ProbeService.findBy({ query: {}, select: '_id' });
|
||||
|
||||
|
||||
data.probeId = probeId ? probeId[0]._id : null;
|
||||
|
||||
|
||||
if (data.lighthouseScanStatus === 'scanning') {
|
||||
|
||||
await MonitorService.updateLighthouseScanStatus(
|
||||
|
||||
data.monitorId,
|
||||
|
||||
|
||||
data.lighthouseScanStatus
|
||||
);
|
||||
|
||||
await LighthouseLogService.updateAllLighthouseLogs(
|
||||
|
||||
data.monitor.projectId,
|
||||
|
||||
|
||||
data.monitorId,
|
||||
{
|
||||
scanning: true,
|
||||
@@ -94,47 +90,43 @@ router.post('/ping/:monitorId', isAuthorizedLighthouse, async function(
|
||||
);
|
||||
} else {
|
||||
await MonitorService.updateLighthouseScanStatus(
|
||||
|
||||
data.monitorId,
|
||||
|
||||
|
||||
data.lighthouseScanStatus,
|
||||
|
||||
|
||||
data.probeId
|
||||
);
|
||||
|
||||
|
||||
if (data.lighthouseData) {
|
||||
// The scanned results are published
|
||||
|
||||
|
||||
data.scanning = false;
|
||||
log = await ProbeService.saveLighthouseLog(data);
|
||||
|
||||
/* For Email Service */
|
||||
|
||||
|
||||
const project = await ProjectService.findOneBy({
|
||||
|
||||
query: { _id: data.monitor.projectId },
|
||||
select: '_id name users',
|
||||
});
|
||||
|
||||
|
||||
project.monitor = data.monitor.name;
|
||||
const userIds = project.users
|
||||
.filter((e: $TSFixMe) => e.role !== 'Viewer')
|
||||
.map((e: $TSFixMe) => ({
|
||||
id: e.userId,
|
||||
})); // This cater for projects with multiple registered members
|
||||
|
||||
|
||||
const performance = data.performance;
|
||||
|
||||
|
||||
const accessibility = data.accessibility;
|
||||
|
||||
|
||||
const bestPractices = data.bestPractices;
|
||||
|
||||
|
||||
const seo = data.seo;
|
||||
|
||||
|
||||
const pwa = data.pwa;
|
||||
|
||||
|
||||
const performanceIssues = data.lighthouseData.issues.performance
|
||||
.slice(0, 10)
|
||||
.map((desc: $TSFixMe) => {
|
||||
@@ -150,7 +142,6 @@ router.post('/ping/:monitorId', isAuthorizedLighthouse, async function(
|
||||
return desc;
|
||||
});
|
||||
|
||||
|
||||
const accessibilityIssues = data.lighthouseData.issues.accessibility
|
||||
.slice(0, 10)
|
||||
.map((desc: $TSFixMe) => {
|
||||
@@ -166,7 +157,6 @@ router.post('/ping/:monitorId', isAuthorizedLighthouse, async function(
|
||||
return desc;
|
||||
});
|
||||
|
||||
|
||||
const bestPracticesIssues = data.lighthouseData.issues[
|
||||
'best-practices'
|
||||
]
|
||||
@@ -184,7 +174,6 @@ router.post('/ping/:monitorId', isAuthorizedLighthouse, async function(
|
||||
return desc;
|
||||
});
|
||||
|
||||
|
||||
const seoIssues = data.lighthouseData.issues.seo
|
||||
.slice(0, 10)
|
||||
.map((desc: $TSFixMe) => {
|
||||
@@ -199,7 +188,7 @@ router.post('/ping/:monitorId', isAuthorizedLighthouse, async function(
|
||||
|
||||
return desc;
|
||||
});
|
||||
|
||||
|
||||
const pwaIssues = data.lighthouseData.issues.pwa
|
||||
.slice(0, 10)
|
||||
.map((desc: $TSFixMe) => {
|
||||
|
||||
@@ -13,11 +13,9 @@ router.get('/:userId', getUser, isAuthorized, async function(req, res) {
|
||||
const userId = req.params.userId;
|
||||
let { skip, limit } = req.query;
|
||||
if (!skip) {
|
||||
|
||||
skip = 0;
|
||||
}
|
||||
if (!limit) {
|
||||
|
||||
limit = 10;
|
||||
}
|
||||
const select = 'userId createdAt ipLocation device status';
|
||||
|
||||
@@ -47,7 +47,7 @@ router.post('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
message: "values can't be null",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
|
||||
/* if (!data.componentId) {
|
||||
@@ -163,11 +163,9 @@ router.post('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
httpsAgent,
|
||||
};
|
||||
if (headers && Object.keys(headers).length) {
|
||||
|
||||
payload.headers = headers;
|
||||
}
|
||||
if (body && Object.keys(body).length) {
|
||||
|
||||
payload.data = body;
|
||||
}
|
||||
const apiResponse = await axios(payload);
|
||||
@@ -239,7 +237,6 @@ router.post('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
const [monitor, user] = await Promise.all([
|
||||
MonitorService.create(data),
|
||||
UserService.findOneBy({
|
||||
|
||||
query: { _id: req.user.id },
|
||||
select: 'name _id',
|
||||
}),
|
||||
@@ -254,7 +251,6 @@ router.post('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
|
||||
if (monitor) {
|
||||
try {
|
||||
|
||||
NotificationService.create(
|
||||
monitor.projectId._id || monitor.projectId,
|
||||
`A New Monitor was Created with name ${monitor.name} by ${user.name}`,
|
||||
@@ -292,12 +288,9 @@ router.post('/:projectId/identityFile', async function(req, res) {
|
||||
}
|
||||
if (
|
||||
req.files &&
|
||||
|
||||
req.files.identityFile &&
|
||||
|
||||
req.files.identityFile[0].filename
|
||||
) {
|
||||
|
||||
identityFile = req.files.identityFile[0].filename;
|
||||
}
|
||||
return sendItemResponse(req, res, { identityFile });
|
||||
@@ -324,12 +317,9 @@ router.post('/:projectId/configurationFile', async function(req, res) {
|
||||
}
|
||||
if (
|
||||
req.files &&
|
||||
|
||||
req.files.configurationFile &&
|
||||
|
||||
req.files.configurationFile[0].filename
|
||||
) {
|
||||
|
||||
configurationFile = req.files.configurationFile[0].filename;
|
||||
}
|
||||
return sendItemResponse(req, res, { configurationFile });
|
||||
@@ -372,11 +362,9 @@ router.put(
|
||||
httpsAgent,
|
||||
};
|
||||
if (headers && Object.keys(headers).length) {
|
||||
|
||||
payload.headers = headers;
|
||||
}
|
||||
if (body && Object.keys(body).length) {
|
||||
|
||||
payload.data = body;
|
||||
}
|
||||
const apiResponse = await axios(payload);
|
||||
@@ -442,10 +430,8 @@ router.get('/:projectId', getUser, isAuthorized, getSubProjects, async function(
|
||||
res
|
||||
) {
|
||||
try {
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
|
||||
const { limit, skip } = req.query;
|
||||
@@ -512,10 +498,9 @@ router.get(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const type = req.query.type;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
const query = type
|
||||
? { projectId: { $in: subProjectIds }, type }
|
||||
@@ -559,10 +544,9 @@ router.get(
|
||||
try {
|
||||
const monitorId = req.params.monitorId;
|
||||
const type = req.query.type;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
const query = type
|
||||
? { _id: monitorId, projectId: { $in: subProjectIds }, type }
|
||||
@@ -619,16 +603,15 @@ router.post(
|
||||
'createdAt lastAlive probeKey probeName version probeImage deleted',
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
if (monitorId && !incidentId) query.monitorId = monitorId;
|
||||
|
||||
|
||||
if (incidentId) query.incidentIds = incidentId;
|
||||
|
||||
|
||||
if (probeValue) query.probeId = probeValue;
|
||||
|
||||
|
||||
if (type === 'incomingHttpRequest') query.probeId = null;
|
||||
if (startDate && endDate)
|
||||
|
||||
query.createdAt = { $gte: startDate, $lte: endDate };
|
||||
|
||||
const [monitorLogs, count] = await Promise.all([
|
||||
@@ -658,7 +641,7 @@ router.delete(
|
||||
try {
|
||||
const monitor = await MonitorService.deleteBy(
|
||||
{ _id: monitorId, projectId: projectId },
|
||||
|
||||
|
||||
req.user.id
|
||||
);
|
||||
if (monitor) {
|
||||
@@ -702,8 +685,7 @@ router.post(
|
||||
failedReasons: upFailedReasons,
|
||||
} =
|
||||
monitor && monitor.criteria && monitor.criteria.up
|
||||
?
|
||||
ProbeService.conditions(
|
||||
? ProbeService.conditions(
|
||||
monitor.type,
|
||||
monitor.criteria.up,
|
||||
data
|
||||
@@ -715,8 +697,7 @@ router.post(
|
||||
failedReasons: degradedFailedReasons,
|
||||
} =
|
||||
monitor && monitor.criteria && monitor.criteria.degraded
|
||||
?
|
||||
ProbeService.conditions(
|
||||
? ProbeService.conditions(
|
||||
monitor.type,
|
||||
monitor.criteria.degraded,
|
||||
data
|
||||
@@ -728,8 +709,7 @@ router.post(
|
||||
failedReasons: downFailedReasons,
|
||||
} =
|
||||
monitor && monitor.criteria && monitor.criteria.down
|
||||
?
|
||||
ProbeService.conditions(
|
||||
? ProbeService.conditions(
|
||||
monitor.type,
|
||||
monitor.criteria.down,
|
||||
data
|
||||
@@ -1016,7 +996,7 @@ router.post(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const { projectId, monitorId } = req.params;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const monitor = await MonitorService.closeBreachedMonitorSla(
|
||||
projectId,
|
||||
@@ -1100,12 +1080,11 @@ router.post('/:monitorId/calculate-time', async function(req, res) {
|
||||
|
||||
if (!monitor) {
|
||||
const error = new Error('Monitor not found or does not exist');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
result.monitorId = monitor._id;
|
||||
|
||||
return sendItemResponse(req, res, result);
|
||||
|
||||
@@ -19,14 +19,14 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
|
||||
if (!fieldName || !fieldName.trim()) {
|
||||
const error = new Error('Field name is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!fieldType || !fieldType.trim()) {
|
||||
const error = new Error('Field type is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Custom field with this name already exist'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -100,14 +100,14 @@ router.put('/:projectId/:customFieldId', getUser, isAuthorized, async function(
|
||||
|
||||
if (!fieldName || !fieldName.trim()) {
|
||||
const error = new Error('Field name is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!fieldType || !fieldType.trim()) {
|
||||
const error = new Error('Field type is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ router.put('/:projectId/:customFieldId', getUser, isAuthorized, async function(
|
||||
const error = new Error(
|
||||
'Custom field with this name already exist'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -46,28 +46,28 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
|
||||
if (!name || !name.trim()) {
|
||||
const error = new Error('SLA name is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (!monitorUptime || !monitorUptime.trim()) {
|
||||
const error = new Error('Monitor uptime is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (frequency && isNaN(frequency)) {
|
||||
const error = new Error('Please use numeric values for frequency');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (frequency && Number(frequency) < 1) {
|
||||
const error = new Error('At lease a single day is needed');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please use numeric values for monitor uptime'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Monitor Uptime less than 1 is not allowed'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Monitor Uptime greater than 100 is not allowed'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -118,28 +118,28 @@ router.put('/:projectId/:monitorSlaId', getUser, isAuthorized, async function(
|
||||
|
||||
if (!handleDefault && (!name || !name.trim())) {
|
||||
const error = new Error('SLA name is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (!handleDefault && (!monitorUptime || !monitorUptime.trim())) {
|
||||
const error = new Error('Monitor uptime is required');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (!handleDefault && frequency && isNaN(frequency)) {
|
||||
const error = new Error('Please use numeric values for frequency');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
if (!handleDefault && frequency && Number(frequency) < 1) {
|
||||
const error = new Error('At lease a single day is needed');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -148,7 +148,7 @@ router.put('/:projectId/:monitorSlaId', getUser, isAuthorized, async function(
|
||||
const error = new Error(
|
||||
'Please use numeric values for monitor uptime'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ router.put('/:projectId/:monitorSlaId', getUser, isAuthorized, async function(
|
||||
const error = new Error(
|
||||
'Monitor Uptime less than 1 is not allowed'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -166,7 +166,7 @@ router.put('/:projectId/:monitorSlaId', getUser, isAuthorized, async function(
|
||||
const error = new Error(
|
||||
'Monitor Uptime greater than 100 is not allowed'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,8 @@ router.get('/:projectId', getUser, isAuthorized, getSubProjects, async function(
|
||||
res
|
||||
) {
|
||||
try {
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
|
||||
const populateNotification = [
|
||||
@@ -59,7 +57,7 @@ router.get('/:projectId', getUser, isAuthorized, getSubProjects, async function(
|
||||
router.put('/:projectId/read', getUser, isAuthorized, async function(req, res) {
|
||||
try {
|
||||
// const notificationId = req.params.notificationId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
|
||||
const { notificationIds } = req.body;
|
||||
@@ -87,7 +85,7 @@ router.put(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const notificationId = req.params.notificationId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const notification = await NotificationService.updateOneBy(
|
||||
{ _id: notificationId },
|
||||
@@ -97,7 +95,7 @@ router.put(
|
||||
return sendItemResponse(req, res, notification);
|
||||
} else {
|
||||
const error = new Error('Notification not found.');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -114,12 +112,10 @@ router.put(
|
||||
getSubProjects,
|
||||
async function(req, res) {
|
||||
try {
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const notifications = await NotificationService.updateManyBy(
|
||||
{ projectId: { $in: subProjectIds } },
|
||||
@@ -133,7 +129,7 @@ router.put(
|
||||
});
|
||||
} else {
|
||||
const error = new Error('No notification found.');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -158,7 +154,7 @@ router.put('/:projectId/:notificationId', getUser, isAuthorized, async function(
|
||||
return sendItemResponse(req, res, notification);
|
||||
} else {
|
||||
const error = new Error('Notification not found.');
|
||||
|
||||
|
||||
error.code = 400;
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -170,10 +166,10 @@ router.put('/:projectId/:notificationId', getUser, isAuthorized, async function(
|
||||
router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
try {
|
||||
const projectId = req.params.projectId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const data = req.body;
|
||||
|
||||
|
||||
const notification = await NotificationService.create(
|
||||
projectId,
|
||||
data.message,
|
||||
|
||||
@@ -34,7 +34,7 @@ router.post(
|
||||
message: "values can't be null",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
if (!data.name) {
|
||||
return sendErrorResponse(req, res, {
|
||||
@@ -50,13 +50,11 @@ router.post(
|
||||
);
|
||||
|
||||
try {
|
||||
|
||||
NotificationService.create(
|
||||
|
||||
performanceTracker.componentId.projectId._id,
|
||||
|
||||
|
||||
`A New Performance Tracker was Created with name ${performanceTracker.name} by ${performanceTracker.createdById.name}`,
|
||||
|
||||
|
||||
performanceTracker.createdById._id,
|
||||
'performanceTrackeraddremove'
|
||||
);
|
||||
@@ -137,7 +135,7 @@ router.get(
|
||||
const error = new Error(
|
||||
'Please specify the performance tracker ID or attach the slug as a query parameter'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -161,7 +159,7 @@ router.delete(
|
||||
{
|
||||
_id: performanceTrackerId,
|
||||
},
|
||||
|
||||
|
||||
req.user.id
|
||||
);
|
||||
if (performanceTracker) {
|
||||
@@ -321,11 +319,9 @@ router.put(
|
||||
|
||||
const performanceTrackerData = {};
|
||||
if (data.name) {
|
||||
|
||||
performanceTrackerData.name = data.name;
|
||||
}
|
||||
if (data.showQuickStart !== undefined) {
|
||||
|
||||
performanceTrackerData.showQuickStart = data.showQuickStart;
|
||||
}
|
||||
|
||||
@@ -351,9 +347,9 @@ router.get(
|
||||
try {
|
||||
const { performanceTrackerId } = req.params;
|
||||
let { startDate, endDate } = req.query;
|
||||
|
||||
|
||||
startDate = decode(startDate);
|
||||
|
||||
|
||||
endDate = decode(endDate);
|
||||
|
||||
// get each of the individual metrics
|
||||
@@ -378,17 +374,15 @@ router.get(
|
||||
|
||||
const result = {
|
||||
performanceTrackerId,
|
||||
|
||||
|
||||
time: time.length > 0 ? time[time.length - 1].value : 0,
|
||||
throughput:
|
||||
throughput.length > 0
|
||||
?
|
||||
throughput[throughput.length - 1].value
|
||||
? throughput[throughput.length - 1].value
|
||||
: 0,
|
||||
errorRate:
|
||||
errorRate.length > 0
|
||||
?
|
||||
errorRate[errorRate.length - 1].value
|
||||
? errorRate[errorRate.length - 1].value
|
||||
: 0,
|
||||
};
|
||||
return sendItemResponse(req, res, result);
|
||||
|
||||
@@ -45,16 +45,16 @@ router.get('/:appId/key/:key/time', isValidAPIKey, async function(req, res) {
|
||||
try {
|
||||
const { appId } = req.params;
|
||||
let { startDate, endDate } = req.query;
|
||||
|
||||
|
||||
startDate = decode(startDate);
|
||||
|
||||
|
||||
endDate = decode(endDate);
|
||||
|
||||
if (!startDate) {
|
||||
const error = new Error(
|
||||
'Please specify startDate in the query parameter'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ router.get('/:appId/key/:key/time', isValidAPIKey, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please specify startDate as utc time or millisecond time'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ router.get('/:appId/key/:key/time', isValidAPIKey, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please specify endDate in the query parameter'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -78,18 +78,16 @@ router.get('/:appId/key/:key/time', isValidAPIKey, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please specify endDate as utc time or millisecond time'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
if (!isNaN(startDate)) {
|
||||
|
||||
startDate = Number(startDate);
|
||||
}
|
||||
|
||||
|
||||
if (!isNaN(endDate)) {
|
||||
|
||||
endDate = Number(endDate);
|
||||
}
|
||||
|
||||
@@ -113,16 +111,16 @@ router.get('/:appId/key/:key/throughput', isValidAPIKey, async function(
|
||||
try {
|
||||
const { appId } = req.params;
|
||||
let { startDate, endDate } = req.query;
|
||||
|
||||
|
||||
startDate = decode(startDate);
|
||||
|
||||
|
||||
endDate = decode(endDate);
|
||||
|
||||
if (!startDate) {
|
||||
const error = new Error(
|
||||
'Please specify startDate in the query parameter'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -130,7 +128,7 @@ router.get('/:appId/key/:key/throughput', isValidAPIKey, async function(
|
||||
const error = new Error(
|
||||
'Please specify startDate as utc time or millisecond time'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -138,7 +136,7 @@ router.get('/:appId/key/:key/throughput', isValidAPIKey, async function(
|
||||
const error = new Error(
|
||||
'Please specify endDate in the query parameter'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -146,18 +144,16 @@ router.get('/:appId/key/:key/throughput', isValidAPIKey, async function(
|
||||
const error = new Error(
|
||||
'Please specify endDate as utc time or millisecond time'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
if (!isNaN(startDate)) {
|
||||
|
||||
startDate = Number(startDate);
|
||||
}
|
||||
|
||||
|
||||
if (!isNaN(endDate)) {
|
||||
|
||||
endDate = Number(endDate);
|
||||
}
|
||||
|
||||
@@ -177,16 +173,16 @@ router.get('/:appId/key/:key/error', isValidAPIKey, async function(req, res) {
|
||||
try {
|
||||
const { appId } = req.params;
|
||||
let { startDate, endDate } = req.query;
|
||||
|
||||
|
||||
startDate = decode(startDate);
|
||||
|
||||
|
||||
endDate = decode(endDate);
|
||||
|
||||
if (!startDate) {
|
||||
const error = new Error(
|
||||
'Please specify startDate in the query parameter'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -194,7 +190,7 @@ router.get('/:appId/key/:key/error', isValidAPIKey, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please specify startDate as utc time or millisecond time'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -202,7 +198,7 @@ router.get('/:appId/key/:key/error', isValidAPIKey, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please specify endDate in the query parameter'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -210,18 +206,16 @@ router.get('/:appId/key/:key/error', isValidAPIKey, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please specify endDate as utc time or millisecond time'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
if (!isNaN(startDate)) {
|
||||
|
||||
startDate = Number(startDate);
|
||||
}
|
||||
|
||||
|
||||
if (!isNaN(endDate)) {
|
||||
|
||||
endDate = Number(endDate);
|
||||
}
|
||||
|
||||
@@ -244,16 +238,16 @@ router.get('/:appId/key/:key', isValidAPIKey, async function(req, res) {
|
||||
const { appId } = req.params;
|
||||
const { type, skip, limit } = req.query;
|
||||
let { startDate, endDate } = req.query;
|
||||
|
||||
|
||||
startDate = decode(startDate);
|
||||
|
||||
|
||||
endDate = decode(endDate);
|
||||
|
||||
if (!type) {
|
||||
const error = new Error(
|
||||
'Please specify the type in the query parameter'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -261,7 +255,7 @@ router.get('/:appId/key/:key', isValidAPIKey, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please specify startDate in the query parameter'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -269,7 +263,7 @@ router.get('/:appId/key/:key', isValidAPIKey, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please specify startDate as utc time or millisecond time'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -277,7 +271,7 @@ router.get('/:appId/key/:key', isValidAPIKey, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please specify endDate in the query parameter'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
@@ -285,18 +279,16 @@ router.get('/:appId/key/:key', isValidAPIKey, async function(req, res) {
|
||||
const error = new Error(
|
||||
'Please specify endDate as utc time or millisecond time'
|
||||
);
|
||||
|
||||
|
||||
error.code = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
if (!isNaN(startDate)) {
|
||||
|
||||
startDate = Number(startDate);
|
||||
}
|
||||
|
||||
|
||||
if (!isNaN(endDate)) {
|
||||
|
||||
endDate = Number(endDate);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ router.get('/', getUser, isAuthorizedAdmin, async function(req, res) {
|
||||
const selectProbe =
|
||||
'createdAt probeKey probeName version lastAlive deleted deletedAt probeImage';
|
||||
const [probe, count] = await Promise.all([
|
||||
|
||||
ProbeService.findBy({
|
||||
query: {},
|
||||
limit,
|
||||
@@ -95,12 +94,9 @@ router.put('/update/image', getUser, async function(req, res) {
|
||||
}
|
||||
if (
|
||||
req.files &&
|
||||
|
||||
req.files.probeImage &&
|
||||
|
||||
req.files.probeImage[0].filename
|
||||
) {
|
||||
|
||||
data.probeImage = req.files.probeImage[0].filename;
|
||||
}
|
||||
|
||||
@@ -116,7 +112,6 @@ router.put('/update/image', getUser, async function(req, res) {
|
||||
router.get('/monitors', isAuthorizedProbe, async function(req, res) {
|
||||
try {
|
||||
const monitors = await MonitorService.getProbeMonitors(
|
||||
|
||||
req.probe.id,
|
||||
new Date(new Date().getTime() - 60 * 1000)
|
||||
);
|
||||
@@ -161,7 +156,6 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
select: 'lastPingTime _id criteria',
|
||||
});
|
||||
|
||||
|
||||
const probeId = req.probe && req.probe.id ? req.probe.id : null;
|
||||
log = await ProbeService.probeHttpRequest(newMonitor, probeId);
|
||||
} else {
|
||||
@@ -258,9 +252,9 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
data.status = status;
|
||||
|
||||
|
||||
data.reason = reason;
|
||||
}
|
||||
if (type === 'ip') {
|
||||
@@ -324,9 +318,9 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
data.status = status;
|
||||
|
||||
|
||||
data.reason = reason;
|
||||
}
|
||||
if (type === 'script') {
|
||||
@@ -413,9 +407,8 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
data.status = status;
|
||||
|
||||
|
||||
data.reason = reason;
|
||||
}
|
||||
if (type === 'server-monitor') {
|
||||
@@ -427,8 +420,7 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
matchedCriterion: matchedUpCriterion,
|
||||
}: $TSFixMe =
|
||||
monitor && monitor.criteria && monitor.criteria.up
|
||||
?
|
||||
ProbeService.conditions(
|
||||
? ProbeService.conditions(
|
||||
monitor.type,
|
||||
monitor.criteria.up,
|
||||
data
|
||||
@@ -445,8 +437,7 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
matchedCriterion: matchedDegradedCriterion,
|
||||
}: $TSFixMe =
|
||||
monitor && monitor.criteria && monitor.criteria.degraded
|
||||
?
|
||||
ProbeService.conditions(
|
||||
? ProbeService.conditions(
|
||||
monitor.type,
|
||||
monitor.criteria.degraded,
|
||||
data
|
||||
@@ -463,8 +454,7 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
matchedCriterion: matchedDownCriterion,
|
||||
}: $TSFixMe =
|
||||
monitor && monitor.criteria && monitor.criteria.down
|
||||
?
|
||||
ProbeService.conditions(
|
||||
? ProbeService.conditions(
|
||||
monitor.type,
|
||||
[
|
||||
...monitor.criteria.down.filter(
|
||||
@@ -481,24 +471,21 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
};
|
||||
|
||||
if (validUp) {
|
||||
|
||||
data.status = 'online';
|
||||
|
||||
|
||||
data.reason = upSuccessReasons;
|
||||
matchedCriterion = matchedUpCriterion;
|
||||
} else if (validDegraded) {
|
||||
|
||||
data.status = 'degraded';
|
||||
|
||||
|
||||
data.reason = [
|
||||
...degradedSuccessReasons,
|
||||
...upFailedReasons,
|
||||
];
|
||||
matchedCriterion = matchedDegradedCriterion;
|
||||
} else if (validDown) {
|
||||
|
||||
data.status = 'offline';
|
||||
|
||||
|
||||
data.reason = [
|
||||
...downSuccessReasons,
|
||||
...degradedFailedReasons,
|
||||
@@ -506,9 +493,8 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
];
|
||||
matchedCriterion = matchedDownCriterion;
|
||||
} else {
|
||||
|
||||
data.status = 'offline';
|
||||
|
||||
|
||||
data.reason = [
|
||||
...downFailedReasons,
|
||||
...degradedFailedReasons,
|
||||
@@ -522,41 +508,41 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
}
|
||||
} else {
|
||||
data = req.body;
|
||||
|
||||
|
||||
data.responseTime = res || 0;
|
||||
|
||||
|
||||
data.responseStatus = resp && resp.status ? resp.status : null;
|
||||
|
||||
|
||||
data.status = status;
|
||||
|
||||
|
||||
data.sslCertificate =
|
||||
resp && resp.sslCertificate ? resp.sslCertificate : null;
|
||||
|
||||
|
||||
data.lighthouseScanStatus =
|
||||
resp && resp.lighthouseScanStatus
|
||||
? resp.lighthouseScanStatus
|
||||
: null;
|
||||
|
||||
|
||||
data.performance =
|
||||
resp && resp.performance ? resp.performance : null;
|
||||
|
||||
|
||||
data.accessibility =
|
||||
resp && resp.accessibility ? resp.accessibility : null;
|
||||
|
||||
|
||||
data.bestPractices =
|
||||
resp && resp.bestPractices ? resp.bestPractices : null;
|
||||
|
||||
|
||||
data.seo = resp && resp.seo ? resp.seo : null;
|
||||
|
||||
|
||||
data.pwa = resp && resp.pwa ? resp.pwa : null;
|
||||
|
||||
|
||||
data.lighthouseData =
|
||||
resp && resp.lighthouseData ? resp.lighthouseData : null;
|
||||
|
||||
|
||||
data.retryCount = retryCount || 0;
|
||||
|
||||
|
||||
data.reason = reason;
|
||||
|
||||
|
||||
data.response = rawResp;
|
||||
}
|
||||
if (type === 'kubernetes') {
|
||||
@@ -569,11 +555,10 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
matchedCriterion: matchedUpCriterion,
|
||||
}: $TSFixMe =
|
||||
monitor && monitor.criteria && monitor.criteria.up
|
||||
?
|
||||
ProbeService.conditions(
|
||||
? ProbeService.conditions(
|
||||
monitor.type,
|
||||
monitor.criteria.up,
|
||||
|
||||
|
||||
data.kubernetesData
|
||||
)
|
||||
: {
|
||||
@@ -589,11 +574,10 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
matchedCriterion: matchedDegradedCriterion,
|
||||
}: $TSFixMe =
|
||||
monitor && monitor.criteria && monitor.criteria.degraded
|
||||
?
|
||||
ProbeService.conditions(
|
||||
? ProbeService.conditions(
|
||||
monitor.type,
|
||||
monitor.criteria.degraded,
|
||||
|
||||
|
||||
data.kubernetesData
|
||||
)
|
||||
: {
|
||||
@@ -609,8 +593,7 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
matchedCriterion: matchedDownCriterion,
|
||||
}: $TSFixMe =
|
||||
monitor && monitor.criteria && monitor.criteria.down
|
||||
?
|
||||
ProbeService.conditions(
|
||||
? ProbeService.conditions(
|
||||
monitor.type,
|
||||
[
|
||||
...monitor.criteria.down.filter(
|
||||
@@ -618,7 +601,7 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
criterion.default !== true
|
||||
),
|
||||
],
|
||||
|
||||
|
||||
data.kubernetesData
|
||||
)
|
||||
: {
|
||||
@@ -628,24 +611,21 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
};
|
||||
|
||||
if (validUp) {
|
||||
|
||||
data.status = 'online';
|
||||
|
||||
|
||||
data.reason = upSuccessReasons;
|
||||
matchedCriterion = matchedUpCriterion;
|
||||
} else if (validDegraded) {
|
||||
|
||||
data.status = 'degraded';
|
||||
|
||||
|
||||
data.reason = [
|
||||
...degradedSuccessReasons,
|
||||
...upFailedReasons,
|
||||
];
|
||||
matchedCriterion = matchedDegradedCriterion;
|
||||
} else if (validDown) {
|
||||
|
||||
data.status = 'offline';
|
||||
|
||||
|
||||
data.reason = [
|
||||
...downSuccessReasons,
|
||||
...degradedFailedReasons,
|
||||
@@ -653,9 +633,8 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
];
|
||||
matchedCriterion = matchedDownCriterion;
|
||||
} else {
|
||||
|
||||
data.status = 'offline';
|
||||
|
||||
|
||||
data.reason = [
|
||||
...downFailedReasons,
|
||||
...degradedFailedReasons,
|
||||
@@ -670,7 +649,6 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
}
|
||||
|
||||
if (type === 'script') {
|
||||
|
||||
data.scriptMetadata = {
|
||||
executionTime: resp.executionTime,
|
||||
consoleLogs: resp.consoleLogs,
|
||||
@@ -679,58 +657,43 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
data.matchedCriterion = matchedCriterion;
|
||||
// update monitor to save the last matched criterion
|
||||
|
||||
await MonitorService.updateCriterion(monitor._id, matchedCriterion);
|
||||
|
||||
|
||||
data.monitorId = monitorId || monitor._id;
|
||||
|
||||
|
||||
data.probeId = req.probe && req.probe.id ? req.probe.id : null;
|
||||
|
||||
|
||||
data.reason =
|
||||
|
||||
data && data.reason && data.reason.length
|
||||
?
|
||||
data.reason.filter(
|
||||
? data.reason.filter(
|
||||
(item: $TSFixMe, pos: $TSFixMe, self: $TSFixMe) =>
|
||||
self.indexOf(item) === pos
|
||||
)
|
||||
:
|
||||
data.reason;
|
||||
: data.reason;
|
||||
const index =
|
||||
|
||||
data.reason && data.reason.indexOf('Request Timed out');
|
||||
if (index > -1) {
|
||||
|
||||
data.reason =
|
||||
|
||||
data && data.reason && data.reason.length
|
||||
?
|
||||
data.reason.filter(
|
||||
? data.reason.filter(
|
||||
(item: $TSFixMe) =>
|
||||
!item.includes('Response Time is')
|
||||
)
|
||||
:
|
||||
data.reason;
|
||||
: data.reason;
|
||||
}
|
||||
|
||||
|
||||
if (data.lighthouseScanStatus) {
|
||||
|
||||
if (data.lighthouseScanStatus === 'scanning') {
|
||||
await Promise.all([
|
||||
|
||||
MonitorService.updateLighthouseScanStatus(
|
||||
|
||||
data.monitorId,
|
||||
'scanning'
|
||||
),
|
||||
|
||||
|
||||
LighthouseLogService.updateAllLighthouseLogs(
|
||||
|
||||
data.monitorId,
|
||||
{ scanning: true }
|
||||
),
|
||||
@@ -738,28 +701,24 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
} else {
|
||||
// when this is scanned success or failed.
|
||||
await MonitorService.updateLighthouseScanStatus(
|
||||
|
||||
data.monitorId,
|
||||
|
||||
|
||||
data.lighthouseScanStatus,
|
||||
|
||||
|
||||
data.probeId
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (data.lighthouseData) {
|
||||
|
||||
data.scanning = false;
|
||||
log = await ProbeService.saveLighthouseLog(data);
|
||||
} else {
|
||||
|
||||
data.matchedUpCriterion =
|
||||
monitor && monitor.criteria && monitor.criteria.up;
|
||||
|
||||
|
||||
data.matchedDownCriterion =
|
||||
monitor && monitor.criteria && monitor.criteria.down;
|
||||
|
||||
|
||||
data.matchedDegradedCriterion =
|
||||
monitor &&
|
||||
monitor.criteria &&
|
||||
@@ -771,7 +730,7 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
await MonitorService.updateScriptStatus(
|
||||
monitorId,
|
||||
'completed',
|
||||
|
||||
|
||||
req.probe.id
|
||||
);
|
||||
}
|
||||
@@ -787,7 +746,7 @@ router.post('/ping/:monitorId', isAuthorizedProbe, async function(
|
||||
router.post('/setTime/:monitorId', isAuthorizedProbe, async function(req, res) {
|
||||
try {
|
||||
const data = req.body;
|
||||
|
||||
|
||||
data.probeId = req.probe.id;
|
||||
data.monitorId = req.params.monitorId;
|
||||
const log = await ProbeService.saveMonitorLog(data);
|
||||
@@ -800,7 +759,7 @@ router.post('/setTime/:monitorId', isAuthorizedProbe, async function(req, res) {
|
||||
router.post('/getTime/:monitorId', isAuthorizedProbe, async function(req, res) {
|
||||
try {
|
||||
const data = req.body;
|
||||
|
||||
|
||||
data.probeId = req.probe.id;
|
||||
data.monitorId = req.params.monitorId;
|
||||
const log = await ProbeService.getMonitorLog(data);
|
||||
@@ -820,7 +779,6 @@ router.get('/:projectId/probes', getUser, isAuthorized, async function(
|
||||
const selectProbe =
|
||||
'createdAt probeKey probeName version lastAlive deleted deletedAt probeImage';
|
||||
const [probe, count] = await Promise.all([
|
||||
|
||||
ProbeService.findBy({
|
||||
query: {},
|
||||
limit,
|
||||
|
||||
@@ -71,7 +71,7 @@ router.post('/create', getUser, async function(req, res) {
|
||||
}
|
||||
|
||||
const projectName = data.projectName;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
data.userId = userId;
|
||||
|
||||
@@ -119,7 +119,7 @@ router.post('/create', getUser, async function(req, res) {
|
||||
{ _id: userId },
|
||||
{ stripeCustomerId: checkedPaymentIntent.customer }
|
||||
),
|
||||
|
||||
|
||||
PaymentService.subscribePlan(
|
||||
stripePlanId,
|
||||
checkedPaymentIntent.customer
|
||||
@@ -144,15 +144,12 @@ router.post('/create', getUser, async function(req, res) {
|
||||
return sendItemResponse(req, res, project);
|
||||
} else {
|
||||
if (IS_SAAS_SERVICE) {
|
||||
|
||||
const subscription = await PaymentService.subscribePlan(
|
||||
stripePlanId,
|
||||
user.stripeCustomerId
|
||||
);
|
||||
if (
|
||||
|
||||
subscription.subscriptionPaymentStatus === 'canceled' ||
|
||||
|
||||
subscription.subscriptionPaymentStatus === 'unpaid'
|
||||
) {
|
||||
user = await UserService.findOneBy({
|
||||
@@ -160,7 +157,6 @@ router.post('/create', getUser, async function(req, res) {
|
||||
select: 'email name',
|
||||
});
|
||||
try {
|
||||
|
||||
MailService.sendPaymentFailedEmail(
|
||||
projectName,
|
||||
user.email,
|
||||
@@ -216,10 +212,9 @@ router.post('/create', getUser, async function(req, res) {
|
||||
// Returns: 200: [{project}]; 400: Error.
|
||||
router.get('/projects', getUser, async function(req, res) {
|
||||
try {
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
// find user subprojects and parent projects
|
||||
|
||||
|
||||
const userProjects = await ProjectService.findBy({
|
||||
query: { 'users.userId': userId },
|
||||
select: 'parentProjectId _id',
|
||||
@@ -404,7 +399,7 @@ router.put(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const projectId = req.params.projectId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
|
||||
if (!projectId) {
|
||||
@@ -500,7 +495,7 @@ router.delete(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const projectId = req.params.projectId;
|
||||
|
||||
|
||||
const userId = req.user.id;
|
||||
const feedback = req.body.feedback;
|
||||
|
||||
@@ -570,7 +565,7 @@ router.delete(
|
||||
}
|
||||
|
||||
let userId = null;
|
||||
|
||||
|
||||
let project = await ProjectService.findOneBy({
|
||||
query: { _id: projectId },
|
||||
select: 'users _id',
|
||||
@@ -611,7 +606,7 @@ router.post(
|
||||
const projectId = req.params.projectId;
|
||||
const projectName = req.body.projectName;
|
||||
const planId = req.body.planId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const oldPlan = req.body.oldPlan;
|
||||
const newPlan = req.body.newPlan;
|
||||
@@ -684,7 +679,7 @@ router.put(
|
||||
const projectId = req.params.projectId;
|
||||
const projectName = req.body.projectName;
|
||||
const planId = req.body.planId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const oldPlan = req.body.oldPlan;
|
||||
const newPlan = req.body.newPlan;
|
||||
@@ -731,7 +726,6 @@ router.put(
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const project = await ProjectService.findOneBy({
|
||||
query: { _id: projectId },
|
||||
select: 'users',
|
||||
@@ -778,7 +772,7 @@ router.post(
|
||||
try {
|
||||
const projectId = req.params.projectId;
|
||||
const projectName = req.body.projectName;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const oldPlan = req.body.oldPlan;
|
||||
|
||||
@@ -838,10 +832,9 @@ router.delete(
|
||||
async function(req, res) {
|
||||
// Call the ProjectService
|
||||
try {
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const projectId = req.params.projectId;
|
||||
|
||||
|
||||
const teamMember = await ProjectService.exitProject(
|
||||
projectId,
|
||||
userId
|
||||
@@ -862,7 +855,6 @@ router.post('/:projectId/subProject', getUser, isAuthorized, async function(
|
||||
res
|
||||
) {
|
||||
try {
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const parentProjectId = req.params.projectId;
|
||||
const subProjectName =
|
||||
@@ -902,7 +894,7 @@ router.post('/:projectId/subProject', getUser, isAuthorized, async function(
|
||||
const populate = [{ path: 'parentProjectId', select: 'name' }];
|
||||
const select =
|
||||
'_id slug name users stripePlanId stripeSubscriptionId parentProjectId seats deleted apiKey alertEnable alertLimit alertLimitReached balance alertOptions isBlocked adminNotes';
|
||||
|
||||
|
||||
subProjects = await ProjectService.findBy({
|
||||
query: { _id: subProjects._id },
|
||||
select,
|
||||
@@ -923,7 +915,7 @@ router.delete(
|
||||
try {
|
||||
const parentProjectId = req.params.projectId;
|
||||
const subProjectId = req.params.subProjectId;
|
||||
|
||||
|
||||
const userId = req.user.id;
|
||||
|
||||
if (!subProjectId) {
|
||||
@@ -954,7 +946,7 @@ router.get('/:projectId/subProjects', getUser, isAuthorized, async function(
|
||||
// Call the ProjectService
|
||||
try {
|
||||
const parentProjectId = req.params.projectId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const skip = req.query.skip || 0;
|
||||
const limit = req.query.limit || 10;
|
||||
@@ -1090,7 +1082,7 @@ router.put(
|
||||
message: 'New alert limit must be present.',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const oldProject = await ProjectService.findOneBy({
|
||||
query: { _id: projectId, deleted: false },
|
||||
select: 'alertLimit',
|
||||
|
||||
@@ -22,10 +22,9 @@ router.get(
|
||||
async (req, res) => {
|
||||
try {
|
||||
const { startDate, endDate, skip, limit } = req.query;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
// Call ReportService
|
||||
const members = await ReportService.getMostActiveMembers(
|
||||
@@ -35,9 +34,9 @@ router.get(
|
||||
skip,
|
||||
limit
|
||||
);
|
||||
|
||||
|
||||
const count = members.count;
|
||||
|
||||
|
||||
return sendListResponse(req, res, members.members, count);
|
||||
} catch (error) {
|
||||
return sendErrorResponse(req, res, error);
|
||||
@@ -59,10 +58,9 @@ router.get(
|
||||
async (req, res) => {
|
||||
try {
|
||||
const { startDate, endDate, skip, limit } = req.query;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
// Call Reports Service
|
||||
const monitors = await ReportService.getMostActiveMonitors(
|
||||
@@ -72,9 +70,9 @@ router.get(
|
||||
skip,
|
||||
limit
|
||||
);
|
||||
|
||||
|
||||
const count = monitors.count;
|
||||
|
||||
|
||||
return sendListResponse(req, res, monitors.monitors, count);
|
||||
} catch (error) {
|
||||
return sendErrorResponse(req, res, error);
|
||||
@@ -96,10 +94,9 @@ router.get(
|
||||
async (req, res) => {
|
||||
try {
|
||||
const { startDate, endDate, filter } = req.query;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
// Reports Service
|
||||
const resolveTime = await ReportService.getAverageTimeBy(
|
||||
@@ -129,10 +126,9 @@ router.get(
|
||||
async (req, res) => {
|
||||
try {
|
||||
const { startDate, endDate, filter } = req.query;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
// Reports Service
|
||||
const incidents = await ReportService.getIncidentCountBy(
|
||||
|
||||
@@ -2,7 +2,6 @@ import express from 'express';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
import { isAuthorized } from '../middlewares/authorization';
|
||||
|
||||
const getUser = require('../middlewares/user').getUser;
|
||||
@@ -27,7 +26,6 @@ router.post('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
const resourceCategoryName = req.body.resourceCategoryName;
|
||||
const projectId = req.params.projectId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
|
||||
if (!resourceCategoryName) {
|
||||
@@ -80,7 +78,6 @@ router.delete(
|
||||
const resourceCategoryId = req.params.resourceCategoryId;
|
||||
const projectId = req.params.projectId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
|
||||
if (!resourceCategoryId) {
|
||||
|
||||
@@ -16,7 +16,7 @@ router.post('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
) {
|
||||
try {
|
||||
const data = req.body;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
data.createdById = userId;
|
||||
data.projectId = req.params.projectId;
|
||||
@@ -88,10 +88,8 @@ router.get(
|
||||
getSubProjects,
|
||||
async function(req, res) {
|
||||
try {
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
const schedules = await ScheduleService.getSubProjectSchedules(
|
||||
subProjectIds
|
||||
@@ -173,7 +171,7 @@ router.delete(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const scheduleId = req.params.scheduleId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
|
||||
if (!scheduleId) {
|
||||
@@ -200,10 +198,8 @@ router.get(
|
||||
getSubProjects,
|
||||
async (req, res) => {
|
||||
try {
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
const userId = req.params.userId;
|
||||
const escalations = await ScheduleService.getUserEscalations(
|
||||
@@ -244,7 +240,6 @@ router.post(
|
||||
isUserAdmin,
|
||||
async (req, res) => {
|
||||
try {
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const scheduleId = req.params.scheduleId;
|
||||
const escalations = [];
|
||||
@@ -406,39 +401,36 @@ router.post(
|
||||
value.firstRotationOn = new Date(value.firstRotationOn);
|
||||
}
|
||||
|
||||
|
||||
storagevalue.callReminders = value.callReminders;
|
||||
|
||||
|
||||
storagevalue.smsReminders = value.smsReminders;
|
||||
|
||||
|
||||
storagevalue.emailReminders = value.emailReminders;
|
||||
|
||||
|
||||
storagevalue.pushReminders = value.pushReminders;
|
||||
|
||||
|
||||
storagevalue.rotateBy = value.rotateBy;
|
||||
|
||||
|
||||
storagevalue.rotationInterval = value.rotationInterval;
|
||||
|
||||
|
||||
storagevalue.firstRotationOn = value.firstRotationOn;
|
||||
|
||||
|
||||
storagevalue.rotationTimezone = value.rotationTimezone;
|
||||
|
||||
|
||||
storagevalue.email = value.email;
|
||||
|
||||
|
||||
storagevalue.call = value.call;
|
||||
|
||||
|
||||
storagevalue.sms = value.sms;
|
||||
|
||||
|
||||
storagevalue.push = value.push;
|
||||
|
||||
|
||||
storagevalue.projectId = req.params.projectId;
|
||||
|
||||
|
||||
storagevalue.scheduleId = scheduleId;
|
||||
|
||||
|
||||
storagevalue.createdById = userId;
|
||||
|
||||
|
||||
if (value._id) storagevalue._id = value._id;
|
||||
|
||||
for (const team of value.teams) {
|
||||
@@ -507,34 +499,31 @@ router.post(
|
||||
teamMember.endTime = new Date(teamMember.endTime);
|
||||
}
|
||||
if (teamMember.userId) {
|
||||
|
||||
data.userId = teamMember.userId;
|
||||
|
||||
|
||||
data.startTime = teamMember.startTime;
|
||||
|
||||
|
||||
data.endTime = teamMember.endTime;
|
||||
|
||||
|
||||
data.timezone = teamMember.timezone;
|
||||
teamMembers.push(data);
|
||||
}
|
||||
if (teamMember.groupId) {
|
||||
|
||||
data.groupId = teamMember.groupId;
|
||||
|
||||
|
||||
data.startTime = teamMember.startTime;
|
||||
|
||||
|
||||
data.endTime = teamMember.endTime;
|
||||
|
||||
|
||||
data.timezone = teamMember.timezone;
|
||||
teamMembers.push(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rotationData.teamMembers = teamMembers;
|
||||
tempTeam.push(rotationData);
|
||||
}
|
||||
|
||||
|
||||
storagevalue.teams = tempTeam;
|
||||
escalations.push(storagevalue);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
try {
|
||||
const projectId = req.params.projectId;
|
||||
const data = req.body;
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
|
||||
if (!data) {
|
||||
@@ -87,7 +87,6 @@ router.post('/:projectId', getUser, isAuthorized, async function(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const scheduledEvent = await ScheduledEventService.create(
|
||||
{ projectId },
|
||||
data
|
||||
@@ -218,7 +217,7 @@ router.put(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const data = {};
|
||||
|
||||
|
||||
data.resolvedBy = req.user ? req.user.id : null;
|
||||
const { eventId } = req.params;
|
||||
|
||||
@@ -262,7 +261,6 @@ router.delete('/:projectId/:eventId', getUser, isAuthorized, async function(
|
||||
res
|
||||
) {
|
||||
try {
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const { eventId } = req.params;
|
||||
|
||||
@@ -283,7 +281,6 @@ router.put('/:projectId/:eventId/cancel', getUser, isAuthorized, async function(
|
||||
res
|
||||
) {
|
||||
try {
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const { eventId } = req.params;
|
||||
|
||||
@@ -338,7 +335,6 @@ router.put('/:projectId/:eventId/cancel', getUser, isAuthorized, async function(
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
await ScheduledEventNoteService.create({
|
||||
content: 'THIS SCHEDULED EVENT HAS BEEN CANCELLED',
|
||||
scheduledEventId: scheduledEvent._id,
|
||||
@@ -420,10 +416,9 @@ router.get(
|
||||
try {
|
||||
const currentDate = moment();
|
||||
// this contains both projectIds and subProjectIds
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
|
||||
const ongoingScheduledEvents = await ScheduledEventService.getSubProjectOngoingScheduledEvents(
|
||||
@@ -563,10 +558,9 @@ router.get(
|
||||
async function(req, res) {
|
||||
try {
|
||||
// this contains both projectIds and subProjectIds
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
|
||||
const scheduledEvents = await ScheduledEventService.getSubProjectScheduledEvents(
|
||||
@@ -664,7 +658,7 @@ router.post('/:projectId/:eventId/notes', getUser, isAuthorized, async function(
|
||||
) {
|
||||
try {
|
||||
const { eventId, projectId } = req.params;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const data = req.body;
|
||||
data.scheduledEventId = eventId;
|
||||
@@ -888,7 +882,7 @@ router.delete(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const { eventId, noteId, projectId } = req.params;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
|
||||
const deletedEventMessage = await ScheduledEventNoteService.deleteBy(
|
||||
|
||||
@@ -116,16 +116,15 @@ router.post('/ping/:monitorId', isAuthorizedService, async function(req, res) {
|
||||
|
||||
// aggregate data for logging
|
||||
data = req.body;
|
||||
|
||||
|
||||
data.status = status;
|
||||
|
||||
|
||||
data.reason = reason;
|
||||
|
||||
|
||||
data.matchedCriterion = matchedCriterion;
|
||||
|
||||
|
||||
data.responseStatus = resp && resp.status ? resp.status : null;
|
||||
|
||||
|
||||
data.scriptMetadata = {
|
||||
executionTime: resp.executionTime,
|
||||
consoleLogs: resp.consoleLogs,
|
||||
@@ -133,27 +132,22 @@ router.post('/ping/:monitorId', isAuthorizedService, async function(req, res) {
|
||||
statusText: resp.statusText,
|
||||
};
|
||||
|
||||
|
||||
data.monitorId = req.params.monitorId || monitor._id;
|
||||
|
||||
|
||||
data.reason =
|
||||
|
||||
data && data.reason && data.reason.length
|
||||
?
|
||||
data.reason.filter(
|
||||
? data.reason.filter(
|
||||
(item: $TSFixMe, pos: $TSFixMe, self: $TSFixMe) =>
|
||||
self.indexOf(item) === pos
|
||||
)
|
||||
:
|
||||
data.reason;
|
||||
: data.reason;
|
||||
|
||||
|
||||
data.matchedUpCriterion =
|
||||
monitor && monitor.criteria && monitor.criteria.up;
|
||||
|
||||
|
||||
data.matchedDownCriterion =
|
||||
monitor && monitor.criteria && monitor.criteria.down;
|
||||
|
||||
|
||||
data.matchedDegradedCriterion =
|
||||
monitor && monitor.criteria && monitor.criteria.degraded;
|
||||
|
||||
|
||||
@@ -22,10 +22,9 @@ router.post('/:projectId', getUser, getSubProjects, async function(req, res) {
|
||||
try {
|
||||
const val = req.body.search;
|
||||
const parentProjectId = req.params.projectId;
|
||||
|
||||
|
||||
const subProjectIds = req.user.subProjects
|
||||
?
|
||||
req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
? req.user.subProjects.map((project: $TSFixMe) => project._id)
|
||||
: null;
|
||||
|
||||
const searchResponse = [];
|
||||
@@ -45,7 +44,7 @@ router.post('/:projectId', getUser, getSubProjects, async function(req, res) {
|
||||
getComponents(subProjectIds, val, parentProjectId),
|
||||
getMonitors(subProjectIds, val, parentProjectId),
|
||||
getStatusPages(subProjectIds, val, parentProjectId),
|
||||
|
||||
|
||||
getUsers(subProjectIds, val, parentProjectId),
|
||||
getOnCallDuty(subProjectIds, val, parentProjectId),
|
||||
getSchedultEvent(subProjectIds, val, parentProjectId),
|
||||
@@ -217,11 +216,11 @@ const getStatusPages = async (
|
||||
select: selectStatusPage,
|
||||
populate: populateStatusPage,
|
||||
});
|
||||
|
||||
|
||||
if (statusPages.length > 0) {
|
||||
const resultObj = {
|
||||
title: 'Status Pages',
|
||||
|
||||
|
||||
values: statusPages.map((statusPage: $TSFixMe) => ({
|
||||
name: statusPage.name,
|
||||
statusPageSlug: statusPage.slug,
|
||||
@@ -243,7 +242,7 @@ const getStatusPages = async (
|
||||
const getUsers = async (projectIds: $TSFixMe, val: $TSFixMe) => {
|
||||
//get project users id so as to search for only users in a project and its subproject
|
||||
const projectUsers: $TSFixMe = [];
|
||||
|
||||
|
||||
const projects = await ProjectService.findBy({
|
||||
query: { _id: { $in: projectIds } },
|
||||
select: 'users',
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import express from 'express';
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
import { IS_SAAS_SERVICE } from '../config/server';
|
||||
const sendItemResponse = require('../middlewares/response').sendItemResponse;
|
||||
|
||||
@@ -16,13 +15,12 @@ router.get('/is-saas-service', function(req, res) {
|
||||
|
||||
router.get('/hosts', function(req, res) {
|
||||
return sendItemResponse(req, res, {
|
||||
|
||||
api: global.apiHost,
|
||||
|
||||
|
||||
home: global.homeHost,
|
||||
|
||||
|
||||
accounts: global.accountsHost,
|
||||
|
||||
|
||||
dashboard: global.dashboardHost,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,7 +86,6 @@ router.post('/site/opts', async (req, res) => {
|
||||
if (issuedBefore) {
|
||||
query.$or.push({
|
||||
issuedAt: {
|
||||
|
||||
$lt: issuedBefore,
|
||||
},
|
||||
});
|
||||
@@ -94,7 +93,6 @@ router.post('/site/opts', async (req, res) => {
|
||||
if (expiresBefore) {
|
||||
query.$or.push({
|
||||
expiresAt: {
|
||||
|
||||
$lt: expiresBefore,
|
||||
},
|
||||
});
|
||||
@@ -102,13 +100,11 @@ router.post('/site/opts', async (req, res) => {
|
||||
if (renewBefore) {
|
||||
query.$or.push({
|
||||
renewAt: {
|
||||
|
||||
$lt: renewBefore,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
query.deleted = false;
|
||||
const sites = await SiteManagerService.findBy({
|
||||
query,
|
||||
@@ -128,7 +124,7 @@ router.delete('/site', async (req, res) => {
|
||||
const { domains } = req.body;
|
||||
|
||||
let site = null;
|
||||
|
||||
|
||||
if (subject && subject.trim()) {
|
||||
site = await SiteManagerService.hardDelete({ subject });
|
||||
} else if (domains && domains.length > 0) {
|
||||
|
||||
@@ -35,12 +35,11 @@ router.get('/auth/redirect', function(req, res) {
|
||||
});
|
||||
}
|
||||
// hack that gets the user authToken and project ID, not very secure, but sufficient for now
|
||||
|
||||
|
||||
state = state.split(',', 2);
|
||||
|
||||
|
||||
const projectId = state[0];
|
||||
|
||||
|
||||
const userToken = state[1];
|
||||
|
||||
const options = {
|
||||
@@ -65,7 +64,7 @@ router.get('/auth/redirect', function(req, res) {
|
||||
router.post('/:projectId/link', getUser, isUserAdmin, async function(req, res) {
|
||||
const projectId = req.params.projectId;
|
||||
const code = req.query.code;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const slug = req.body.slug;
|
||||
|
||||
@@ -139,7 +138,7 @@ router.delete(
|
||||
async function(req, res) {
|
||||
const projectId = req.params.projectId;
|
||||
const teamId = req.params.teamId;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
|
||||
const integrationType = 'slack';
|
||||
|
||||
@@ -75,7 +75,7 @@ router.post('/', getUser, isUserMasterAdmin, async (req, res) => {
|
||||
message: 'SMS Log Content is required',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const smsLog = await SmsLogsService.create(data);
|
||||
return sendItemResponse(req, res, smsLog);
|
||||
} catch (error) {
|
||||
|
||||
@@ -3,13 +3,11 @@ import SmsTemplateService from '../services/smsTemplateService';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
import createDOMPurify from 'dompurify';
|
||||
const jsdom = require('jsdom').jsdom;
|
||||
const window = jsdom('').defaultView;
|
||||
const DOMPurify = createDOMPurify(window);
|
||||
|
||||
|
||||
import { isAuthorized } from '../middlewares/authorization';
|
||||
const getUser = require('../middlewares/user').getUser;
|
||||
const isUserOwner = require('../middlewares/project').isUserOwner;
|
||||
@@ -151,7 +149,7 @@ router.delete(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const smsTemplateId = req.params.smsTemplateId;
|
||||
|
||||
|
||||
const userId = req.user.id;
|
||||
const smsTemplate = await SmsTemplateService.deleteBy(
|
||||
{ _id: smsTemplateId },
|
||||
|
||||
@@ -18,7 +18,7 @@ router.get('/', getUser, isUserMasterAdmin, async function(req, res) {
|
||||
try {
|
||||
const [ssos, count] = await Promise.all([
|
||||
SsoService.findBy({ query: {}, limit, skip, select: selectSso }),
|
||||
|
||||
|
||||
SsoService.countBy(),
|
||||
]);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ router.get('/', getUser, isUserMasterAdmin, async function(req, res) {
|
||||
select: selectDefaultRoleSso,
|
||||
populate: populateDefaultRoleSso,
|
||||
}),
|
||||
|
||||
|
||||
SsoDefaultRolesService.countBy(),
|
||||
]);
|
||||
return sendListResponse(req, res, ssos, count);
|
||||
@@ -74,7 +74,7 @@ router.get('/:id', getUser, isUserMasterAdmin, async function(req, res) {
|
||||
});
|
||||
if (!sso) {
|
||||
const error = new Error("Requested resource doesn't exist.");
|
||||
|
||||
|
||||
error.code = 404;
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import ErrorService from 'common-server/utils/error';
|
||||
import { toXML } from 'jstoxml';
|
||||
import moment from 'moment';
|
||||
|
||||
|
||||
import { getUser, checkUser } from '../middlewares/user';
|
||||
|
||||
import { isUserAdmin } from '../middlewares/project';
|
||||
@@ -133,7 +132,7 @@ router.put(
|
||||
|
||||
const updatedStatusPage = await StatusPageService.getStatusPage({
|
||||
query: { _id: statusPage._id },
|
||||
|
||||
|
||||
userId: req.user.id,
|
||||
populate: populateStatusPage,
|
||||
select: selectStatusPage,
|
||||
@@ -184,7 +183,7 @@ router.put('/:projectId/theme', getUser, isAuthorized, async (req, res) => {
|
||||
|
||||
const updatedStatusPage = await StatusPageService.getStatusPage({
|
||||
query: { _id: statusPage._id },
|
||||
|
||||
|
||||
userId: req.user.id,
|
||||
populate: populateStatusPage,
|
||||
select: selectStatusPage,
|
||||
@@ -364,9 +363,8 @@ router.post('/:projectId/certFile', async function(req, res) {
|
||||
if (error) {
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
|
||||
|
||||
if (req.files && req.files.cert && req.files.cert[0].filename) {
|
||||
|
||||
cert = req.files.cert[0].filename;
|
||||
}
|
||||
return sendItemResponse(req, res, { cert });
|
||||
@@ -393,12 +391,9 @@ router.post('/:projectId/privateKeyFile', async function(req, res) {
|
||||
}
|
||||
if (
|
||||
req.files &&
|
||||
|
||||
req.files.privateKey &&
|
||||
|
||||
req.files.privateKey[0].filename
|
||||
) {
|
||||
|
||||
privateKey = req.files.privateKey[0].filename;
|
||||
}
|
||||
return sendItemResponse(req, res, { privateKey });
|
||||
@@ -413,7 +408,7 @@ router.post('/:projectId/privateKeyFile', async function(req, res) {
|
||||
router.get('/tlsCredential', async function(req, res) {
|
||||
try {
|
||||
const { domain } = req.query;
|
||||
|
||||
|
||||
const user = req.user;
|
||||
|
||||
if (!domain) {
|
||||
@@ -445,15 +440,14 @@ router.get('/tlsCredential', async function(req, res) {
|
||||
});
|
||||
|
||||
return sendItemResponse(req, res, {
|
||||
|
||||
cert: domainObj.cert,
|
||||
|
||||
|
||||
privateKey: domainObj.privateKey,
|
||||
|
||||
|
||||
autoProvisioning: domainObj.autoProvisioning,
|
||||
|
||||
|
||||
enableHttps: domainObj.enableHttps,
|
||||
|
||||
|
||||
domain: domainObj.domain,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -568,10 +562,9 @@ router.put('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
const files = req.files || {};
|
||||
const data = req.body;
|
||||
data.projectId = req.params.projectId;
|
||||
|
||||
|
||||
data.subProjectId = req.params.subProjectId;
|
||||
if (error) {
|
||||
|
||||
ErrorService.log(error);
|
||||
return sendErrorResponse(req, res, error);
|
||||
}
|
||||
@@ -583,11 +576,10 @@ router.put('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
select: 'faviconPath logoPath bannerPath',
|
||||
});
|
||||
const imagesPath = {
|
||||
|
||||
faviconPath: statusPage.faviconPath,
|
||||
|
||||
|
||||
logoPath: statusPage.logoPath,
|
||||
|
||||
|
||||
bannerPath: statusPage.bannerPath,
|
||||
};
|
||||
if (
|
||||
@@ -607,20 +599,15 @@ router.put('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
data.bannerPath = null;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (files && files.favicon && files.favicon[0].filename) {
|
||||
|
||||
data.faviconPath = files.favicon[0].filename;
|
||||
}
|
||||
|
||||
|
||||
if (files && files.logo && files.logo[0].filename) {
|
||||
|
||||
data.logoPath = files.logo[0].filename;
|
||||
}
|
||||
|
||||
|
||||
if (files && files.banner && files.banner[0].filename) {
|
||||
|
||||
data.bannerPath = files.banner[0].filename;
|
||||
}
|
||||
}
|
||||
@@ -660,7 +647,7 @@ router.put('/:projectId', getUser, isAuthorized, isUserAdmin, async function(
|
||||
|
||||
const updatedStatusPage = await StatusPageService.getStatusPage({
|
||||
query: { _id: statusPage._id },
|
||||
|
||||
|
||||
userId: req.user.id,
|
||||
populate: populateStatusPage,
|
||||
select: selectStatusPage,
|
||||
@@ -700,7 +687,7 @@ router.get('/statusBubble', async function(req, res) {
|
||||
try {
|
||||
const selectProbe =
|
||||
'createdAt probeKey probeName version lastAlive deleted deletedAt probeImage';
|
||||
|
||||
|
||||
const probes = await ProbeService.findBy({
|
||||
query: {},
|
||||
limit: 0,
|
||||
@@ -748,7 +735,7 @@ router.get('/statusBubble', async function(req, res) {
|
||||
populate: populateStatusPage,
|
||||
select: selectStatusPage,
|
||||
});
|
||||
|
||||
|
||||
if (!(statusPages && statusPages.length)) {
|
||||
return sendErrorResponse(req, res, {
|
||||
code: 400,
|
||||
@@ -892,7 +879,7 @@ router.get('/:statusPageSlug', checkUser, ipWhitelist, async function(
|
||||
) {
|
||||
const statusPageSlug = req.params.statusPageSlug;
|
||||
const url = req.query.url;
|
||||
|
||||
|
||||
const user = req.user;
|
||||
let statusPage = {};
|
||||
const populateStatusPage = [
|
||||
@@ -941,7 +928,6 @@ router.get('/:statusPageSlug', checkUser, ipWhitelist, async function(
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (statusPage.isPrivate && !req.user) {
|
||||
return sendErrorResponse(req, res, {
|
||||
code: 401,
|
||||
@@ -975,7 +961,6 @@ router.post(
|
||||
let statusPageProjectId = projectId;
|
||||
let filterMonitors = false;
|
||||
if (subProjectId) {
|
||||
|
||||
statusPageProjectId = subProjectId;
|
||||
filterMonitors = true;
|
||||
}
|
||||
@@ -997,7 +982,7 @@ router.post(
|
||||
router.get('/:statusPageId/rss', checkUser, async function(req, res) {
|
||||
const statusPageId = req.params.statusPageId;
|
||||
const url = req.query.url;
|
||||
|
||||
|
||||
const user = req.user;
|
||||
let statusPage = {};
|
||||
|
||||
@@ -1022,7 +1007,6 @@ router.get('/:statusPageId/rss', checkUser, async function(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (statusPage.isPrivate && !req.user) {
|
||||
return sendErrorResponse(req, res, {
|
||||
code: 401,
|
||||
@@ -1037,7 +1021,7 @@ router.get('/:statusPageId/rss', checkUser, async function(req, res) {
|
||||
refinedIncidents.push({
|
||||
item: {
|
||||
title: incident.title,
|
||||
|
||||
|
||||
guid: `${global.apiHost}/status-page/${statusPageId}/rss/${incident._id}`,
|
||||
pubDate: new Date(incident.createdAt).toUTCString(),
|
||||
description: `<![CDATA[Description: ${
|
||||
@@ -1069,7 +1053,6 @@ router.get('/:statusPageId/rss', checkUser, async function(req, res) {
|
||||
_content: {
|
||||
channel: [
|
||||
{
|
||||
|
||||
title: `Incidents for status page ${statusPage.name}`,
|
||||
},
|
||||
{
|
||||
@@ -1077,7 +1060,6 @@ router.get('/:statusPageId/rss', checkUser, async function(req, res) {
|
||||
'RSS feed for all incidents related to monitors attached to status page',
|
||||
},
|
||||
{
|
||||
|
||||
link: `${global.apiHost}/status-page/${statusPageId}/rss`,
|
||||
},
|
||||
{
|
||||
@@ -1137,7 +1119,7 @@ router.get(
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
result = formatNotes(updatedNotes, days);
|
||||
result = checkDuplicateDates(result);
|
||||
} else {
|
||||
@@ -1201,26 +1183,24 @@ router.get('/:projectId/:monitorId/individualnotes', checkUser, async function(
|
||||
res
|
||||
) {
|
||||
let date = req.query.date;
|
||||
|
||||
|
||||
date = new Date(date);
|
||||
const theme = req.query.theme;
|
||||
const start = new Date(
|
||||
|
||||
date.getFullYear(),
|
||||
|
||||
|
||||
date.getMonth(),
|
||||
|
||||
|
||||
date.getDate(),
|
||||
0,
|
||||
0,
|
||||
0
|
||||
);
|
||||
const end = new Date(
|
||||
|
||||
date.getFullYear(),
|
||||
|
||||
|
||||
date.getMonth(),
|
||||
|
||||
|
||||
date.getDate(),
|
||||
23,
|
||||
59,
|
||||
@@ -1286,7 +1266,7 @@ router.get(
|
||||
{ slug: statusPageSlug },
|
||||
skip,
|
||||
limit,
|
||||
|
||||
|
||||
theme
|
||||
);
|
||||
|
||||
@@ -1359,7 +1339,6 @@ const fetchNotes = async (events: $TSFixMe, limit: $TSFixMe) => {
|
||||
const updatedEvents = [];
|
||||
if (events.length > 0) {
|
||||
for (const event of events) {
|
||||
|
||||
const statusPageEvent = await StatusPageService.getEventNotes({
|
||||
scheduledEventId: event._id,
|
||||
type: 'investigation',
|
||||
@@ -1370,7 +1349,6 @@ const fetchNotes = async (events: $TSFixMe, limit: $TSFixMe) => {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
events = formatNotes(updatedEvents, limit);
|
||||
events = checkDuplicateDates(events);
|
||||
return events;
|
||||
@@ -1408,7 +1386,7 @@ router.get('/:projectId/:monitorId/individualevents', checkUser, async function(
|
||||
res
|
||||
) {
|
||||
let date = req.query.date;
|
||||
|
||||
|
||||
date = moment(date)
|
||||
.endOf('day')
|
||||
.format();
|
||||
@@ -1441,7 +1419,6 @@ router.get('/:projectId/:monitorId/individualevents', checkUser, async function(
|
||||
const updatedEvents = [];
|
||||
if (events.length > 0) {
|
||||
for (const event of events) {
|
||||
|
||||
const statusPageEvent = await StatusPageService.getEventNotes(
|
||||
{ scheduledEventId: event._id, type: 'investigation' }
|
||||
);
|
||||
@@ -1547,7 +1524,6 @@ router.get('/:projectId/probes', checkUser, async function(req, res) {
|
||||
const selectProbe =
|
||||
'createdAt probeKey probeName version lastAlive deleted deletedAt probeImage';
|
||||
const [probes, count] = await Promise.all([
|
||||
|
||||
ProbeService.findBy({
|
||||
query: {},
|
||||
limit,
|
||||
@@ -1569,7 +1545,7 @@ router.delete(
|
||||
isUserAdmin,
|
||||
async function(req, res) {
|
||||
const statusPageSlug = req.params.statusPageSlug;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
try {
|
||||
// Call the StatusPageService.
|
||||
@@ -1629,7 +1605,6 @@ router.get(
|
||||
try {
|
||||
const { statusPageSlug } = req.params;
|
||||
|
||||
|
||||
const incidents = await StatusPageService.getNotes({
|
||||
slug: statusPageSlug,
|
||||
});
|
||||
@@ -1664,7 +1639,6 @@ router.get('/:projectId/monitor/:statusPageId', checkUser, async function(
|
||||
populate: populateStatusPage,
|
||||
});
|
||||
|
||||
|
||||
const monitors = statusPage.monitors.map(
|
||||
(mon: $TSFixMe) => mon.monitor._id
|
||||
);
|
||||
@@ -1705,9 +1679,8 @@ router.post(
|
||||
const { name, url } = req.body;
|
||||
const data = {};
|
||||
|
||||
|
||||
data.name = name;
|
||||
|
||||
|
||||
data.url = url;
|
||||
|
||||
if (!data) {
|
||||
@@ -1717,14 +1690,13 @@ router.post(
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (!data.name || !data.name.trim()) {
|
||||
return sendErrorResponse(req, res, {
|
||||
code: 400,
|
||||
message: 'External Status Page Name is required.',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (!data.url || !data.url.trim()) {
|
||||
return sendErrorResponse(req, res, {
|
||||
code: 400,
|
||||
@@ -1741,11 +1713,11 @@ router.post(
|
||||
// To confirm the name and url is not created already
|
||||
const nameQuery = { name };
|
||||
const urlQuery = { url };
|
||||
|
||||
|
||||
const existingExternalStatusPageId = await StatusPageService.getExternalStatusPage(
|
||||
nameQuery
|
||||
);
|
||||
|
||||
|
||||
const existingExternalStatusPageUrl = await StatusPageService.getExternalStatusPage(
|
||||
urlQuery
|
||||
);
|
||||
@@ -1763,7 +1735,6 @@ router.post(
|
||||
}
|
||||
// This scrapes the External Status Page
|
||||
try {
|
||||
|
||||
const res = await axios.get(`${data.url}`);
|
||||
const $ = cheerio.load(res.data);
|
||||
const status = $('span.status.font-large')
|
||||
@@ -1779,7 +1750,6 @@ router.post(
|
||||
});
|
||||
}
|
||||
if (status === 'All Systems Operational') {
|
||||
|
||||
data.description = status;
|
||||
} else {
|
||||
$('div.component-container.border-color').each((i, el) => {
|
||||
@@ -1788,7 +1758,6 @@ router.post(
|
||||
.text()
|
||||
.replace(/\s\s+/g, '');
|
||||
if (componentStatus !== 'Operational') {
|
||||
|
||||
data.description = componentStatus;
|
||||
}
|
||||
});
|
||||
@@ -1800,15 +1769,14 @@ router.post(
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
|
||||
|
||||
data.projectId = projectId;
|
||||
|
||||
|
||||
data.statusPageId = statusPageId;
|
||||
|
||||
await StatusPageService.createExternalStatusPage(data);
|
||||
|
||||
|
||||
const response = await StatusPageService.getExternalStatusPage();
|
||||
return sendItemResponse(req, res, response);
|
||||
} catch (error) {
|
||||
@@ -1825,9 +1793,9 @@ router.post(
|
||||
const { projectId, externalStatusPageId } = req.params;
|
||||
const { name, url } = req.body;
|
||||
const data = {};
|
||||
|
||||
|
||||
data.name = name;
|
||||
|
||||
|
||||
data.url = url;
|
||||
if (!data) {
|
||||
return sendErrorResponse(req, res, {
|
||||
@@ -1835,14 +1803,14 @@ router.post(
|
||||
message: "Values can't be null",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (!data.name || !data.name.trim()) {
|
||||
return sendErrorResponse(req, res, {
|
||||
code: 400,
|
||||
message: 'External Status Page Name is required.',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (!data.url || !data.url.trim()) {
|
||||
return sendErrorResponse(req, res, {
|
||||
code: 400,
|
||||
@@ -1863,7 +1831,6 @@ router.post(
|
||||
}
|
||||
// This scrapes the External Status Page
|
||||
try {
|
||||
|
||||
const res = await axios.get(`${data.url}`);
|
||||
const $ = cheerio.load(res.data);
|
||||
const status = $('span.status.font-large')
|
||||
@@ -1879,7 +1846,6 @@ router.post(
|
||||
});
|
||||
}
|
||||
if (status === 'All Systems Operational') {
|
||||
|
||||
data.description = status;
|
||||
} else {
|
||||
$('div.component-container.border-color').each((i, el) => {
|
||||
@@ -1888,7 +1854,6 @@ router.post(
|
||||
.text()
|
||||
.replace(/\s\s+/g, '');
|
||||
if (componentStatus !== 'Operational') {
|
||||
|
||||
data.description = componentStatus;
|
||||
}
|
||||
});
|
||||
@@ -1905,7 +1870,7 @@ router.post(
|
||||
externalStatusPageId,
|
||||
data
|
||||
);
|
||||
|
||||
|
||||
const response = await StatusPageService.getExternalStatusPage();
|
||||
return sendItemResponse(req, res, response);
|
||||
} catch (error) {
|
||||
@@ -1937,7 +1902,6 @@ router.get(
|
||||
// To fetch all created external statuspages
|
||||
const query = { projectId, statusPageId };
|
||||
|
||||
|
||||
const response = await StatusPageService.getExternalStatusPage(
|
||||
query
|
||||
);
|
||||
@@ -1955,7 +1919,7 @@ router.post(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const { projectId, externalStatusPageId } = req.params;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
|
||||
if (!projectId) {
|
||||
@@ -1978,7 +1942,6 @@ router.post(
|
||||
userId
|
||||
);
|
||||
|
||||
|
||||
const response = await StatusPageService.getExternalStatusPage();
|
||||
return sendItemResponse(req, res, response);
|
||||
} catch (error) {
|
||||
@@ -1994,7 +1957,7 @@ router.post('/:projectId/announcement/:statusPageId', checkUser, async function(
|
||||
try {
|
||||
const { projectId, statusPageId } = req.params;
|
||||
const { data } = req.body;
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
|
||||
if (!data) {
|
||||
@@ -2043,7 +2006,7 @@ router.put(
|
||||
try {
|
||||
const { projectId, statusPageId, announcementId } = req.params;
|
||||
const { data } = req.body;
|
||||
|
||||
|
||||
data.createdById = req.user ? req.user.id : null;
|
||||
|
||||
if (!data.announcementToggle) {
|
||||
@@ -2091,27 +2054,25 @@ router.put(
|
||||
if (response && data.announcementToggle) {
|
||||
const date = new Date();
|
||||
const log = {};
|
||||
|
||||
|
||||
log.statusPageId = statusPageId;
|
||||
if (data.hideAnnouncement) {
|
||||
|
||||
log.endDate = date;
|
||||
|
||||
|
||||
log.updatedById = data.createdById;
|
||||
|
||||
|
||||
log.active = false;
|
||||
await StatusPageService.updateAnnouncementLog(
|
||||
{ active: true },
|
||||
log
|
||||
);
|
||||
} else {
|
||||
|
||||
log.announcementId = announcementId;
|
||||
|
||||
|
||||
log.createdById = data.createdById;
|
||||
|
||||
|
||||
log.startDate = date;
|
||||
|
||||
|
||||
log.active = true;
|
||||
await StatusPageService.createAnnouncementLog(log);
|
||||
}
|
||||
@@ -2150,7 +2111,7 @@ router.get(
|
||||
for (const log of announcementLogs) {
|
||||
updatedLogs.push({ ...log });
|
||||
}
|
||||
|
||||
|
||||
announcementLogs = formatNotes(updatedLogs, 20);
|
||||
announcementLogs = checkDuplicateDates(announcementLogs);
|
||||
}
|
||||
@@ -2175,7 +2136,7 @@ router.get('/:projectId/announcement/:statusPageId', checkUser, async function(
|
||||
const { projectId, statusPageId } = req.params;
|
||||
const { skip, limit, show } = req.query;
|
||||
const query = { projectId, statusPageId };
|
||||
|
||||
|
||||
if (show) query.hideAnnouncement = false;
|
||||
|
||||
const [allAnnouncements, count] = await Promise.all([
|
||||
@@ -2200,7 +2161,7 @@ router.get(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const { projectId, statusPageSlug, announcementSlug } = req.params;
|
||||
|
||||
|
||||
const { _id } = await StatusPageService.findOneBy({
|
||||
query: { slug: statusPageSlug },
|
||||
select: '_id',
|
||||
@@ -2223,7 +2184,7 @@ router.delete(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const { projectId, announcementId } = req.params;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const response = await StatusPageService.deleteAnnouncement(
|
||||
{
|
||||
@@ -2245,7 +2206,7 @@ router.delete(
|
||||
async function(req, res) {
|
||||
try {
|
||||
const { announcementLogId } = req.params;
|
||||
|
||||
|
||||
const userId = req.user ? req.user.id : null;
|
||||
const response = await StatusPageService.deleteAnnouncementLog(
|
||||
{
|
||||
@@ -2299,10 +2260,9 @@ function checkDuplicateDates(items: $TSFixMe) {
|
||||
for (const item of items) {
|
||||
const date = String(item.createdAt).slice(0, 10);
|
||||
|
||||
|
||||
if (!track[date]) {
|
||||
item.style = true;
|
||||
|
||||
|
||||
track[date] = date;
|
||||
} else {
|
||||
item.style = false;
|
||||
@@ -2340,15 +2300,14 @@ router.get(
|
||||
|
||||
//get status pages
|
||||
const statusPage = await getStatusPage(req, statusPageSlug);
|
||||
|
||||
|
||||
if (statusPage.error) {
|
||||
|
||||
return sendErrorResponse(req, res, statusPage.data);
|
||||
}
|
||||
|
||||
const ongoingEvents = await getOngoingScheduledEvents(
|
||||
req,
|
||||
|
||||
|
||||
statusPage.slug
|
||||
);
|
||||
|
||||
@@ -2369,13 +2328,11 @@ router.get(
|
||||
|
||||
//get status pages
|
||||
const statusPage = await getStatusPage(req, statusPageSlug);
|
||||
|
||||
|
||||
if (statusPage.error) {
|
||||
|
||||
return sendErrorResponse(req, res, statusPage.data);
|
||||
}
|
||||
|
||||
|
||||
const futureEvents = await getFutureEvents(req, statusPage.slug);
|
||||
|
||||
return sendItemResponse(req, res, futureEvents);
|
||||
@@ -2395,13 +2352,11 @@ router.get(
|
||||
|
||||
//get status pages
|
||||
const statusPage = await getStatusPage(req, statusPageSlug);
|
||||
|
||||
|
||||
if (statusPage.error) {
|
||||
|
||||
return sendErrorResponse(req, res, statusPage.data);
|
||||
}
|
||||
|
||||
|
||||
const pastEvents = await getPastEvents(req, statusPage.slug);
|
||||
|
||||
return sendItemResponse(req, res, pastEvents);
|
||||
@@ -2421,9 +2376,8 @@ router.get(
|
||||
|
||||
//get status pages
|
||||
const statusPage = await getStatusPage(req, statusPageSlug);
|
||||
|
||||
|
||||
if (statusPage.error) {
|
||||
|
||||
return sendErrorResponse(req, res, statusPage.data);
|
||||
}
|
||||
|
||||
@@ -2446,13 +2400,11 @@ router.get(
|
||||
|
||||
//get status pages
|
||||
const statusPage = await getStatusPage(req, statusPageSlug);
|
||||
|
||||
|
||||
if (statusPage.error) {
|
||||
|
||||
return sendErrorResponse(req, res, statusPage.data);
|
||||
}
|
||||
|
||||
|
||||
const monitorLogs = await getMonitorLogs(req, statusPage.monitors);
|
||||
|
||||
return sendItemResponse(req, res, monitorLogs);
|
||||
@@ -2472,13 +2424,11 @@ router.get(
|
||||
|
||||
//get status pages
|
||||
const statusPage = await getStatusPage(req, statusPageSlug);
|
||||
|
||||
|
||||
if (statusPage.error) {
|
||||
|
||||
return sendErrorResponse(req, res, statusPage.data);
|
||||
}
|
||||
|
||||
|
||||
const { _id: statusPageId, projectId } = statusPage;
|
||||
|
||||
const announcements = await getAnnouncements(
|
||||
@@ -2504,9 +2454,8 @@ router.get(
|
||||
|
||||
//get status pages
|
||||
const statusPage = await getStatusPage(req, statusPageSlug);
|
||||
|
||||
|
||||
if (statusPage.error) {
|
||||
|
||||
return sendErrorResponse(req, res, statusPage.data);
|
||||
}
|
||||
|
||||
@@ -2529,13 +2478,11 @@ router.get(
|
||||
|
||||
//get status pages
|
||||
const statusPage = await getStatusPage(req, statusPageSlug);
|
||||
|
||||
|
||||
if (statusPage.error) {
|
||||
|
||||
return sendErrorResponse(req, res, statusPage.data);
|
||||
}
|
||||
|
||||
|
||||
const timelines = await getMonitorTimelines(statusPage.slug);
|
||||
|
||||
return sendItemResponse(req, res, timelines);
|
||||
@@ -2555,17 +2502,16 @@ router.get(
|
||||
|
||||
//get status pages
|
||||
const statusPage = await getStatusPage(req, statusPageSlug);
|
||||
|
||||
|
||||
if (statusPage.error) {
|
||||
|
||||
return sendErrorResponse(req, res, statusPage.data);
|
||||
}
|
||||
|
||||
const statusPageNote = await getStatusPageNote(
|
||||
req,
|
||||
|
||||
|
||||
statusPage.slug,
|
||||
|
||||
|
||||
statusPage.theme
|
||||
);
|
||||
|
||||
@@ -2587,28 +2533,22 @@ router.get(
|
||||
const response = {};
|
||||
//get status pages
|
||||
const statusPage = await getStatusPage(req, statusPageSlug);
|
||||
|
||||
|
||||
if (statusPage.error) {
|
||||
|
||||
return sendErrorResponse(req, res, statusPage.data);
|
||||
}
|
||||
|
||||
|
||||
const { monitors } = statusPage;
|
||||
|
||||
const monitorStatus = await getMonitorStatuses(req, monitors);
|
||||
|
||||
|
||||
response.monitorStatus = monitorStatus || {};
|
||||
|
||||
|
||||
statusPage.monitorsData.map((data: $TSFixMe) => {
|
||||
|
||||
data.statuses = response.monitorStatus[data._id];
|
||||
return data;
|
||||
});
|
||||
|
||||
|
||||
response.statusPages = statusPage;
|
||||
|
||||
const probes = await getProbes(req);
|
||||
@@ -2620,7 +2560,6 @@ router.get(
|
||||
range
|
||||
);
|
||||
|
||||
|
||||
response.time = time || {};
|
||||
return sendItemResponse(req, res, response);
|
||||
} catch (error) {
|
||||
@@ -2681,7 +2620,6 @@ async function getStatusPage(req: $TSFixMe, statusPageSlug: $TSFixMe) {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
if (statusPage.isPrivate && !req.user) {
|
||||
return {
|
||||
error: true,
|
||||
@@ -2705,7 +2643,7 @@ async function getOngoingScheduledEvents(
|
||||
{ slug: statusPageSlug },
|
||||
skip,
|
||||
limit,
|
||||
|
||||
|
||||
theme
|
||||
);
|
||||
|
||||
@@ -2750,7 +2688,7 @@ async function getProbes(req: $TSFixMe) {
|
||||
const limit = req.query.limit || 0;
|
||||
const selectProbe =
|
||||
'createdAt probeKey probeName version lastAlive deleted deletedAt probeImage';
|
||||
|
||||
|
||||
const probes = await ProbeService.findBy({
|
||||
query: {},
|
||||
limit,
|
||||
@@ -2820,7 +2758,7 @@ async function getAnnouncements(
|
||||
) {
|
||||
const { skip, limit, show = true } = req.query;
|
||||
const query = { projectId, statusPageId };
|
||||
|
||||
|
||||
if (show) query.hideAnnouncement = false;
|
||||
|
||||
const allAnnouncements = await StatusPageService.getAnnouncements(
|
||||
@@ -2850,7 +2788,7 @@ async function getMonitorStatuses(req: $TSFixMe, monitors: $TSFixMe) {
|
||||
startDate,
|
||||
endDate
|
||||
);
|
||||
|
||||
|
||||
status[monitorId] = monitorStatuses;
|
||||
}
|
||||
|
||||
@@ -2858,7 +2796,6 @@ async function getMonitorStatuses(req: $TSFixMe, monitors: $TSFixMe) {
|
||||
}
|
||||
//get timelines
|
||||
async function getMonitorTimelines(statusPageSlug: $TSFixMe) {
|
||||
|
||||
const incidents = await StatusPageService.getNotes({
|
||||
slug: statusPageSlug,
|
||||
});
|
||||
@@ -2904,7 +2841,7 @@ async function getStatusPageNote(
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
result = formatNotes(updatedNotes, days);
|
||||
result = checkDuplicateDates(result);
|
||||
} else {
|
||||
@@ -2930,13 +2867,12 @@ async function getAnnouncementLogs(statusPage: $TSFixMe, limit = 5, skip = 0) {
|
||||
statusPageId: statusPage._id,
|
||||
});
|
||||
|
||||
|
||||
if ((theme && typeof theme === 'boolean') || theme === 'true') {
|
||||
const updatedLogs = [];
|
||||
for (const log of announcementLogs) {
|
||||
updatedLogs.push({ ...log });
|
||||
}
|
||||
|
||||
|
||||
announcementLogs = formatNotes(updatedLogs, 20);
|
||||
announcementLogs = checkDuplicateDates(announcementLogs);
|
||||
}
|
||||
@@ -2981,7 +2917,7 @@ async function calculateTime(
|
||||
);
|
||||
|
||||
const time = await MonitorService.calcTime(statuses, start, range);
|
||||
|
||||
|
||||
result[monitorId] = time;
|
||||
})
|
||||
);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user