From 15bedb021b3ce8c81169b63c142dbf335fbff134 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Fri, 15 Apr 2022 18:24:58 +0100 Subject: [PATCH] fix --- Backend/utils/secondsToHms.ts | 4 +- Backend/utils/services.ts | 4 +- Common/Types/API/Hostname.ts | 2 +- Common/Types/API/Route.ts | 2 +- Common/Types/Email.ts | 2 +- .../Middleware/ClusterKeyAuthorization.ts | 4 +- CommonServer/Services/AlertService.ts | 2 +- .../Services/DomainVerificationService.ts | 45 +- CommonServer/Services/IncidentService.ts | 4 +- .../Services/IncomingRequestService.ts | 7 +- CommonServer/Services/MonitorService.ts | 2 +- .../PerformanceTrackerMetricService.ts | 2 +- CommonServer/Services/ProbeService.ts | 2 +- CommonServer/Services/ProjectService.ts | 6 +- CommonServer/Services/TeamService.ts | 2 +- Dashboard/src/Actions/security.ts | 2 +- Dashboard/src/Actions/subProject.ts | 2 +- Dashboard/src/Reducers/applicationLog.ts | 6 +- Dashboard/src/Reducers/customField.ts | 20 +- Dashboard/src/Reducers/monitor.ts | 1909 +++++++++-------- Dashboard/src/Reducers/monitorCustomField.ts | 2 +- Dashboard/src/Reducers/monitorSla.ts | 8 +- Dashboard/src/Reducers/statusPage.ts | 8 +- Dashboard/src/Reducers/statusPageCategory.ts | 4 +- Dashboard/src/Reducers/team.ts | 6 +- Dashboard/src/Utils/joinNames.ts | 2 +- Dashboard/src/Utils/keybinding.ts | 5 +- DataIngestor/services/probeService.ts | 2 +- DataIngestor/utils/api.ts | 2 +- .../types/HttpTestServerResponse.ts | 2 +- InitScript/util/encryptDecrypt.ts | 2 +- InitScript/util/randomChar.ts | 2 +- .../src/cli/server-monitor/bin/index.ts | 2 +- .../src/cli/server-monitor/lib/api.ts | 19 +- .../src/cli/server-monitor/lib/helpers.ts | 2 +- .../test/server-monitor.test.ts | 2 +- JavaScriptSDK/src/listener.ts | 2 +- JavaScriptSDK/src/listeners/mongoose.ts | 2 +- JavaScriptSDK/src/performanceTracker.ts | 4 +- JavaScriptSDK/src/util.ts | 2 +- JavaScriptSDK/src/utils/perfTimer.ts | 2 +- JavaScriptSDK/test/tracker.test.ts | 2 +- Mail/Services/MailService.ts | 7 +- ScriptRunner/utils/scriptSandbox.ts | 4 +- StatusPage/src/Actions/status.ts | 2 +- 45 files changed, 1175 insertions(+), 951 deletions(-) diff --git a/Backend/utils/secondsToHms.ts b/Backend/utils/secondsToHms.ts index ebe926d99e..04446f1177 100644 --- a/Backend/utils/secondsToHms.ts +++ b/Backend/utils/secondsToHms.ts @@ -8,8 +8,8 @@ const secondsToHms: Function = (value: $TSFixMe): void => { if (!isNaN(value)) { value = Number(value); const hr: $TSFixMe = Math.floor(value / 3600), - min = Math.floor((value % 3600) / 60), - sec = Math.floor((value % 3600) % 60); + min: $TSFixMe = Math.floor((value % 3600) / 60), + sec: $TSFixMe = Math.floor((value % 3600) % 60); const formattedValue: string = `${hr > 0 ? `${hr} hr` : ''} ${ min > 0 diff --git a/Backend/utils/services.ts b/Backend/utils/services.ts index e025f6568a..4f53c1f48d 100644 --- a/Backend/utils/services.ts +++ b/Backend/utils/services.ts @@ -1,5 +1,5 @@ export default { - deduplicate: async (acc: $TSFixMe = []) => { + deduplicate: async (arr: $TSFixMe = []) => { const map: $TSFixMe = {}; let curr: $TSFixMe; @@ -18,7 +18,7 @@ export default { return Object.values(map); }, - rearrangeDuty: async (acc: $TSFixMe = []) => { + rearrangeDuty: async (main: $TSFixMe = []) => { let closeStringId: $TSFixMe; for (let i: $TSFixMe = 0; i < main.length; i++) { if (typeof main[i].schedule == 'object') { diff --git a/Common/Types/API/Hostname.ts b/Common/Types/API/Hostname.ts index 99f19ae776..361988e8a5 100644 --- a/Common/Types/API/Hostname.ts +++ b/Common/Types/API/Hostname.ts @@ -13,7 +13,7 @@ export default class Hostname { } } - toString(): string { + public toString(): string { return this.hostname; } } diff --git a/Common/Types/API/Route.ts b/Common/Types/API/Route.ts index 2cc6d7ab39..c72ed20e47 100644 --- a/Common/Types/API/Route.ts +++ b/Common/Types/API/Route.ts @@ -13,7 +13,7 @@ export default class Route { } } - toString(): string { + public toString(): string { return this.route; } } diff --git a/Common/Types/Email.ts b/Common/Types/Email.ts index 8cb345d475..10da1f5487 100644 --- a/Common/Types/Email.ts +++ b/Common/Types/Email.ts @@ -19,7 +19,7 @@ export default class Email { this.email = email; } - toString(): string { + public toString(): string { return this.email; } } diff --git a/CommonServer/Middleware/ClusterKeyAuthorization.ts b/CommonServer/Middleware/ClusterKeyAuthorization.ts index 30b71a34d3..a6737ba770 100644 --- a/CommonServer/Middleware/ClusterKeyAuthorization.ts +++ b/CommonServer/Middleware/ClusterKeyAuthorization.ts @@ -9,7 +9,7 @@ import { sendErrorResponse } from '../Utils/Response'; import BadDataException from 'Common/Types/Exception/BadDataException'; export default class ClusterKeyAuthorization { -public static async isAuthorizedService( + public static async isAuthorizedService( req: ExpressRequest, res: ExpressResponse, next: NextFunction @@ -36,7 +36,7 @@ public static async isAuthorizedService( ); } - const isAuthorized: $TSFixMe = clusterKey: $TSFixMe === CLUSTER_KEY; + const isAuthorized: $TSFixMe = clusterKey === CLUSTER_KEY; if (!isAuthorized) { return sendErrorResponse( diff --git a/CommonServer/Services/AlertService.ts b/CommonServer/Services/AlertService.ts index b7dbdfb49e..bafbdb5419 100755 --- a/CommonServer/Services/AlertService.ts +++ b/CommonServer/Services/AlertService.ts @@ -343,7 +343,7 @@ public async sendRealTimeUpdate({ incidentId, projectId }: $TSFixMe): void { ...timeline, ...alerts, ...incidentMessages, - ].sort((a: $TSFixMe, b: $TSFixMe){ + ].sort((a: $TSFixMe, b: $TSFixMe) => { return b.createdAt - a.createdAt; }); incidentMessages = [ diff --git a/CommonServer/Services/DomainVerificationService.ts b/CommonServer/Services/DomainVerificationService.ts index 317519b1e5..b3a108e25b 100644 --- a/CommonServer/Services/DomainVerificationService.ts +++ b/CommonServer/Services/DomainVerificationService.ts @@ -13,7 +13,7 @@ import Query from '../Types/DB/Query'; import errorService from '../Utils/error'; export default class Service { -public async create({ domain, projectId }: $TSFixMe): void { + public async create({ domain, projectId }: $TSFixMe): void { const parsed: $TSFixMe = psl.parse(domain); const token: string = 'oneuptime=' + randomChar(); @@ -28,7 +28,14 @@ public async create({ domain, projectId }: $TSFixMe): void { return await DomainVerificationTokenModel.create(creationData); } -public async findBy({ query, limit, skip, populate, select, sort }: FindBy): void { + public async findBy({ + query, + limit, + skip, + populate, + select, + sort, + }: FindBy): void { if (!skip) { skip = 0; } @@ -61,7 +68,9 @@ public async findBy({ query, limit, skip, populate, select, sort }: FindBy): voi query: { parentProjectId: query.projectId }, select: '_id', }); - subProjects = subProjects.map((project: $TSFixMe) => project._id); // grab just the project ids + subProjects = subProjects.map((project: $TSFixMe) => { + return project._id; + }); // grab just the project ids const totalProjects: $TSFixMe = [query.projectId, ...subProjects]; query = { ...query, projectId: { $in: totalProjects } }; @@ -79,7 +88,7 @@ public async findBy({ query, limit, skip, populate, select, sort }: FindBy): voi return domains; } -public async resetDomain(domain: $TSFixMe): void { + public async resetDomain(domain: $TSFixMe): void { const updateObj: $TSFixMe = { verificationToken: 'oneuptime=' + randomChar(), verified: false, @@ -92,7 +101,7 @@ public async resetDomain(domain: $TSFixMe): void { return updatedDomain; } -public async doesTxtRecordExist( + public async doesTxtRecordExist( subDomain: $TSFixMe, verificationToken: $TSFixMe ): void { @@ -110,9 +119,9 @@ public async doesTxtRecordExist( // records is an array of arrays // flatten the array to a single array const txtRecords: $TSFixMe = flatten(records); - const result: $TSFixMe = txtRecords.some( - txtRecord => verificationToken === txtRecord - ); + const result: $TSFixMe = txtRecords.some((txtRecord: $TSFixMe) => { + return verificationToken === txtRecord; + }); if (result) { return { result, txtRecords }; @@ -123,9 +132,9 @@ public async doesTxtRecordExist( // records is an array of arrays // flatten the array to a single array const txtRecords: $TSFixMe = flatten(records); - const result: $TSFixMe = txtRecords.some( - txtRecord => verificationToken === txtRecord - ); + const result: $TSFixMe = txtRecords.some((txtRecord: $TSFixMe) => { + return verificationToken === txtRecord; + }); return { result, txtRecords }; } @@ -149,7 +158,7 @@ public async doesTxtRecordExist( } } -public async doesDomainBelongToProject( + public async doesDomainBelongToProject( projectId: ObjectID, subDomain: $TSFixMe ): void { @@ -183,11 +192,15 @@ public async doesDomainBelongToProject( select: '_id', }); } - subProjects = subProjects.map((project: $TSFixMe) => project._id); // grab just the project ids + subProjects = subProjects.map((project: $TSFixMe) => { + return project._id; + }); // grab just the project ids projectList.push(...subProjects); projectList = projectList.filter( - (projectId: $TSFixMe, index: $TSFixMe)projectList.indexOf(projectId) === index + (projectId: $TSFixMe, index: $TSFixMe) => { + return projectList.indexOf(projectId) === index; + } ); const parsed: $TSFixMe = psl.parse(subDomain); @@ -213,7 +226,7 @@ public async doesDomainBelongToProject( return false; } -public async deleteBy(query: Query): void { + public async deleteBy(query: Query): void { const domainCount: $TSFixMe = await this.countBy(query); if (!domainCount || domainCount === 0) { @@ -262,7 +275,7 @@ public async deleteBy(query: Query): void { return domain; } -public async findDomain(domainId: $TSFixMe, projectArr = []): void { + public async findDomain(domainId: $TSFixMe, projectArr = []): void { let projectId: $TSFixMe; for (const pId of projectArr) { const populateDomainVerify: $TSFixMe = [ diff --git a/CommonServer/Services/IncidentService.ts b/CommonServer/Services/IncidentService.ts index 42d6272220..278d7b4eed 100755 --- a/CommonServer/Services/IncidentService.ts +++ b/CommonServer/Services/IncidentService.ts @@ -618,7 +618,7 @@ export default class Service { return updatedData; } - async _sendIncidentCreatedAlert(incident: $TSFixMe): void { + public async _sendIncidentCreatedAlert(incident: $TSFixMe): void { ZapierService.pushToZapier('incident_created', incident); // await RealTimeService.sendCreatedIncident(incident); @@ -1639,7 +1639,7 @@ export default class Service { } } - clearInterval(incidentId: $TSFixMe): void { + public clearInterval(incidentId: $TSFixMe): void { intervals = intervals.filter((interval: $TSFixMe) => { if (String(interval.incidentId) === String(incidentId)) { clearInterval(interval.intervalId); diff --git a/CommonServer/Services/IncomingRequestService.ts b/CommonServer/Services/IncomingRequestService.ts index 3c66daec14..d190de926a 100644 --- a/CommonServer/Services/IncomingRequestService.ts +++ b/CommonServer/Services/IncomingRequestService.ts @@ -1346,8 +1346,9 @@ export default class Service { for (const field of incidentCustomFields) { const filterCriteria: $TSFixMe = filter.filterCriteria, - filterCondition = filter.filterCondition, - filterText = filter.filterText; + filterCondition: $TSFixMe = + filter.filterCondition, + filterText: $TSFixMe = filter.filterText; if ( filterCriteria && @@ -1558,7 +1559,7 @@ export default class Service { subProjectIds.push(incomingRequest.projectId); const resolveResponse: $TSFixMe = [], - acknowledgeResponse = [], + acknowledgeResponse: $TSFixMe = [], resolvedIncidents: $TSFixMe = [], acknowledgedIncidents: $TSFixMe = []; diff --git a/CommonServer/Services/MonitorService.ts b/CommonServer/Services/MonitorService.ts index a91e598968..f79298ce25 100755 --- a/CommonServer/Services/MonitorService.ts +++ b/CommonServer/Services/MonitorService.ts @@ -1707,7 +1707,7 @@ export default class Service { } // checks if the monitor uptime stat is within the defined uptime on monitor sla - // then update the monitor => breachedMonitorSla + // then update the (monitor: $TSFixMe) => breachedMonitorSla public async updateMonitorSlaStat(query: Query): void { const currentDate: $TSFixMe = moment().format(); let startDate: $TSFixMe = moment(currentDate).subtract(30, 'days'); // default frequency diff --git a/CommonServer/Services/PerformanceTrackerMetricService.ts b/CommonServer/Services/PerformanceTrackerMetricService.ts index a1402535b1..a3e141b076 100644 --- a/CommonServer/Services/PerformanceTrackerMetricService.ts +++ b/CommonServer/Services/PerformanceTrackerMetricService.ts @@ -416,7 +416,7 @@ function calcAvgTime(metric: $TSFixMe): void { const length: $TSFixMe = metric.length; let avgTimeCount: $TSFixMe = 0, - avgMaxTimeCount = 0; + avgMaxTimeCount: $TSFixMe = 0; metric.forEach((data: $TSFixMe) => { avgTimeCount += data.metrics.avgTime; avgMaxTimeCount += data.metrics.maxTime; diff --git a/CommonServer/Services/ProbeService.ts b/CommonServer/Services/ProbeService.ts index f85ddbac1b..61bb5abc03 100755 --- a/CommonServer/Services/ProbeService.ts +++ b/CommonServer/Services/ProbeService.ts @@ -205,7 +205,7 @@ public async saveMonitorLog(data: $TSFixMe): void { select: '_id', }); - const incidentIds: $TSFixMe = incidents.map(incident: $TSFixMe => incident._id); + const incidentIds: $TSFixMe = incidents.map((incident: $TSFixMe) => incident._id); if (incidentIds && incidentIds.length) { log = await MonitorLogService.updateOneBy( diff --git a/CommonServer/Services/ProjectService.ts b/CommonServer/Services/ProjectService.ts index 50ebb05e89..1b5105529a 100755 --- a/CommonServer/Services/ProjectService.ts +++ b/CommonServer/Services/ProjectService.ts @@ -439,7 +439,7 @@ public async findsubProjectId(projectId: $TSFixMe): void { select: '_id', }); - const subProjectId: $TSFixMe = subProject.map(sub: $TSFixMe => String(sub._id)); + const subProjectId: $TSFixMe = subProject.map((sub: $TSFixMe) => String(sub._id)); const projectIdArr: $TSFixMe = [projectId, ...subProjectId]; return projectIdArr; } @@ -662,9 +662,9 @@ public async getUserProjects(userId, skip, limit): void { .map((project: $TSFixMe) => (project.parentProjectId ? project : null)) - .filter(subProject => subProject !== null); + .filter((subProject: $TSFixMe) => subProject !== null); parentProjectIds = subProjects.map( - subProject => + (subProject: $TSFixMe) => subProject.parentProjectId._id || subProject.parentProjectId ); const projects: $TSFixMe = userProjects diff --git a/CommonServer/Services/TeamService.ts b/CommonServer/Services/TeamService.ts index 48b8d0d000..57bba498ec 100755 --- a/CommonServer/Services/TeamService.ts +++ b/CommonServer/Services/TeamService.ts @@ -927,7 +927,7 @@ public async updateTeamMemberRole( const teams: $TSFixMe = response.map(res: $TSFixMe => res.team); const flatTeams: $TSFixMe = flatten(teams); const teamArr: $TSFixMe = flatTeams.filter( - team => String(team.userId) === String(teamMemberUserId) + (team: $TSFixMe) => String(team.userId) === String(teamMemberUserId) ); const checkCurrentViewer: $TSFixMe = teamArr.every( (data: $TSFixMe) => data.role === 'Viewer' diff --git a/Dashboard/src/Actions/security.ts b/Dashboard/src/Actions/security.ts index 751ed0e26b..384b9cd1e9 100644 --- a/Dashboard/src/Actions/security.ts +++ b/Dashboard/src/Actions/security.ts @@ -168,7 +168,7 @@ export const getContainerSecuritiesFailure: Function = ( export const getContainerSecurities: $TSFixMe = ({ projectId, componentId, - skip: number = 0 + skip = 0 limit = 0, fetchingPage = false, }: $TSFixMe) => { diff --git a/Dashboard/src/Actions/subProject.ts b/Dashboard/src/Actions/subProject.ts index 4f281d7b5f..e3f5c5feb1 100755 --- a/Dashboard/src/Actions/subProject.ts +++ b/Dashboard/src/Actions/subProject.ts @@ -35,7 +35,7 @@ export const resetSubProjects: Function = (): void => { export const getSubProjects: Function = ( projectId: ObjectID, skip: number = 0 - limit = 10 + limit: $TSFixMe = 10 ): void => { return function (dispatch: Dispatch): void { const promise: $TSFixMe = BackendAPI.get( diff --git a/Dashboard/src/Reducers/applicationLog.ts b/Dashboard/src/Reducers/applicationLog.ts index ed772bd9b6..9cd215863f 100644 --- a/Dashboard/src/Reducers/applicationLog.ts +++ b/Dashboard/src/Reducers/applicationLog.ts @@ -276,7 +276,7 @@ export default function applicationLog( }); case RESET_APPLICATION_LOG_KEY_SUCCESS: applicationLogs = state.applicationLogsList.applicationLogs.map( - applicationLog => { + (applicationLog: $TSFixMe) => { if (applicationLog._id === action.payload._id) { applicationLog = action.payload; } @@ -319,7 +319,7 @@ export default function applicationLog( }); case EDIT_APPLICATION_LOG_SWITCH: applicationLogs = state.applicationLogsList.applicationLogs.map( - applicationLog => { + (applicationLog: $TSFixMe) => { if (applicationLog._id === action.payload) { if (!applicationLog.editMode) { applicationLog.editMode = true; @@ -348,7 +348,7 @@ export default function applicationLog( }); case EDIT_APPLICATION_LOG_SUCCESS: applicationLogs = state.applicationLogsList.applicationLogs.map( - applicationLog => { + (applicationLog: $TSFixMe) => { if (applicationLog._id === action.payload._id) { applicationLog = action.payload; } diff --git a/Dashboard/src/Reducers/customField.ts b/Dashboard/src/Reducers/customField.ts index 93e1d06c30..bd681a820f 100644 --- a/Dashboard/src/Reducers/customField.ts +++ b/Dashboard/src/Reducers/customField.ts @@ -72,9 +72,9 @@ export default function customField( }; case types.DELETE_CUSTOM_FIELD_SUCCESS: { - const fields: $TSFixMe = state.customFields.fields.filter( - field => String(field._id) !== String(action.payload._id) - ); + const fields: $TSFixMe = state.customFields.fields.filter((field: $TSFixMe) => { + return String(field._id) !== String(action.payload._id); + }); return { ...state, customFields: { @@ -150,13 +150,15 @@ export default function customField( }; case types.UPDATE_CUSTOM_FIELD_SUCCESS: { - const fields: $TSFixMe = state.customFields.fields.map(field: $TSFixMe => { - if (String(field._id) === String(action.payload._id)) { - field = action.payload; - } + const fields: $TSFixMe = state.customFields.fields.map( + (field: $TSFixMe) => { + if (String(field._id) === String(action.payload._id)) { + field = action.payload; + } - return field; - }); + return field; + } + ); return { ...state, customFields: { diff --git a/Dashboard/src/Reducers/monitor.ts b/Dashboard/src/Reducers/monitor.ts index 848a44003d..4fdcbcd4df 100755 --- a/Dashboard/src/Reducers/monitor.ts +++ b/Dashboard/src/Reducers/monitor.ts @@ -155,7 +155,10 @@ const INITIAL_STATE: $TSFixMe = { configFileInputKey: null, }; -export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action): void { +export default function monitor( + state: $TSFixMe = INITIAL_STATE, + action: Action +): void { let monitors: $TSFixMe, monitorType: $TSFixMe, initialValue: $TSFixMe; switch (action.type) { case CREATE_MONITOR_FAILURE: @@ -240,29 +243,34 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) case CREATE_MONITOR_SUCCESS: case 'CREATE_MONITOR': { let monitorFound: $TSFixMe = false; - const monitors: $TSFixMe = state.monitorsList.monitors.map(monitorData: $TSFixMe => { - let output: $TSFixMe = { - ...monitorData, - monitors: monitorData.monitors.map((monitor: $TSFixMe) => { - if ( - String(monitor._id) === String(action.payload._id) - ) { - monitorFound = true; - return action.payload; - } - return monitor; - }), - }; - if (!monitorFound) { - output = { - ...output, - monitors: [action.payload, ...output.monitors], - count: output.count + 1, + const monitors: $TSFixMe = state.monitorsList.monitors.map( + (monitorData: $TSFixMe) => { + let output: $TSFixMe = { + ...monitorData, + monitors: monitorData.monitors.map( + (monitor: $TSFixMe) => { + if ( + String(monitor._id) === + String(action.payload._id) + ) { + monitorFound = true; + return action.payload; + } + return monitor; + } + ), }; - } + if (!monitorFound) { + output = { + ...output, + monitors: [action.payload, ...output.monitors], + count: output.count + 1, + }; + } - return output; - }); + return output; + } + ); return { ...state, @@ -357,80 +365,94 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: false, - monitors: state.monitorsList.monitors.map((project: $TSFixMe) => { - const subProject: $TSFixMe = Object.assign({}, project); - const subProjectMonitors: $TSFixMe = - subProject.monitors && subProject.monitors.slice(); - - const newMonitor: $TSFixMe = Object.assign({}, action.payload); - - const monitorIndex: $TSFixMe = - subProjectMonitors && - subProjectMonitors.findIndex( - (monitor: $TSFixMe) => - monitor._id === newMonitor._id + monitors: state.monitorsList.monitors.map( + (project: $TSFixMe) => { + const subProject: $TSFixMe = Object.assign( + {}, + project ); - const isSubProjectMonitor: $TSFixMe = monitorIndex > -1; + const subProjectMonitors: $TSFixMe = + subProject.monitors && + subProject.monitors.slice(); - if (subProject._id === newMonitor.projectId) { - if (isSubProjectMonitor) { - const oldMonitor: $TSFixMe = Object.assign( - {}, - subProjectMonitors[monitorIndex] + const newMonitor: $TSFixMe = Object.assign( + {}, + action.payload + ); + + const monitorIndex: $TSFixMe = + subProjectMonitors && + subProjectMonitors.findIndex( + (monitor: $TSFixMe) => { + return monitor._id === newMonitor._id; + } ); + const isSubProjectMonitor: $TSFixMe = + monitorIndex > -1; - if (!newMonitor.logs) { - newMonitor.logs = oldMonitor.logs; - } - if (!newMonitor.statuses) { - newMonitor.statuses = oldMonitor.statuses; - } - if (!newMonitor.currentLighthouseLog) { - newMonitor.currentLighthouseLog = - oldMonitor.currentLighthouseLog; - } - if (!newMonitor.lighthouseLogs) { - newMonitor.lighthouseLogs = - oldMonitor.lighthouseLogs; - } - if (!newMonitor.incidents) { - newMonitor.incidents = oldMonitor.incidents; - } - if (!newMonitor.subscribers) { - newMonitor.subscribers = - oldMonitor.subscribers; - } - if (!newMonitor.skip) { - newMonitor.skip = oldMonitor.skip; - } - if (!newMonitor.limit) { - newMonitor.limit = oldMonitor.limit; - } - if (!newMonitor.count) { - newMonitor.count = oldMonitor.count; - } + if (subProject._id === newMonitor.projectId) { + if (isSubProjectMonitor) { + const oldMonitor: $TSFixMe = Object.assign( + {}, + subProjectMonitors[monitorIndex] + ); - subProjectMonitors[monitorIndex] = newMonitor; + if (!newMonitor.logs) { + newMonitor.logs = oldMonitor.logs; + } + if (!newMonitor.statuses) { + newMonitor.statuses = + oldMonitor.statuses; + } + if (!newMonitor.currentLighthouseLog) { + newMonitor.currentLighthouseLog = + oldMonitor.currentLighthouseLog; + } + if (!newMonitor.lighthouseLogs) { + newMonitor.lighthouseLogs = + oldMonitor.lighthouseLogs; + } + if (!newMonitor.incidents) { + newMonitor.incidents = + oldMonitor.incidents; + } + if (!newMonitor.subscribers) { + newMonitor.subscribers = + oldMonitor.subscribers; + } + if (!newMonitor.skip) { + newMonitor.skip = oldMonitor.skip; + } + if (!newMonitor.limit) { + newMonitor.limit = oldMonitor.limit; + } + if (!newMonitor.count) { + newMonitor.count = oldMonitor.count; + } + + subProjectMonitors[monitorIndex] = + newMonitor; + } else { + newMonitor.skip = 0; + newMonitor.limit = 0; + newMonitor.count = 0; + + subProjectMonitors.unshift(newMonitor); + + subProject.count += 1; + } } else { - newMonitor.skip = 0; - newMonitor.limit = 0; - newMonitor.count = 0; + if (isSubProjectMonitor) { + subProjectMonitors.splice(monitorIndex, 1); - subProjectMonitors.unshift(newMonitor); - - subProject.count += 1; + subProject.count -= 1; + } } - } else { - if (isSubProjectMonitor) { - subProjectMonitors.splice(monitorIndex, 1); - subProject.count -= 1; - } + subProject.monitors = subProjectMonitors; + return subProject; } - - subProject.monitors = subProjectMonitors; - return subProject; - }), + ), }, editMonitor: { requesting: false, @@ -469,27 +491,29 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: false, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = monitor.monitors.map( - (monitor: $TSFixMe, i: $TSFixMe) => { - if ( - i === action.payload || - monitor._id === action.payload - ) { - if (!monitor.editMode) { - monitor.editMode = true; + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = monitor.monitors.map( + (monitor: $TSFixMe, i: $TSFixMe) => { + if ( + i === action.payload || + monitor._id === action.payload + ) { + if (!monitor.editMode) { + monitor.editMode = true; + } else { + monitor.editMode = false; + } + return monitor; } else { monitor.editMode = false; + return monitor; } - return monitor; - } else { - monitor.editMode = false; - return monitor; } - } - ); - return monitor; - }), + ); + return monitor; + } + ), }, editMonitor: { requesting: false, @@ -505,27 +529,34 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - if ( - monitor._id === - action.payload.monitorId - ) { - monitor.incidents = - action.payload.incidents.data; - monitor.skip = action.payload.skip; - monitor.limit = action.payload.limit; - monitor.count = action.payload.count; - return monitor; - } else { - return monitor; - } - }) - : monitor.monitors; - return monitor; - }), + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === action.payload.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + if ( + monitor._id === + action.payload.monitorId + ) { + monitor.incidents = + action.payload.incidents.data; + monitor.skip = + action.payload.skip; + monitor.limit = + action.payload.limit; + monitor.count = + action.payload.count; + return monitor; + } else { + return monitor; + } + } + ) + : monitor.monitors; + return monitor; + } + ), }, paginatedMonitorsList: { ...state.paginatedMonitorsList, @@ -533,7 +564,7 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) error: null, success: true, monitors: state.paginatedMonitorsList.monitors.map( - monitor => { + (monitor: $TSFixMe) => { monitor.monitors = monitor._id === action.payload.projectId ? monitor.monitors.map( @@ -593,30 +624,36 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - if ( - monitor._id === - action.payload.monitorId - ) { - monitor.subscribers = { - subscribers: - action.payload.subscribers - .data, - skip: action.payload.skip, - limit: action.payload.limit, - count: action.payload.count, - }; - return monitor; - } else { - return monitor; - } - }) - : monitor.monitors; - return monitor; - }), + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === action.payload.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + if ( + monitor._id === + action.payload.monitorId + ) { + monitor.subscribers = { + subscribers: + action.payload + .subscribers.data, + skip: action.payload.skip, + limit: action.payload + .limit, + count: action.payload + .count, + }; + return monitor; + } else { + return monitor; + } + } + ) + : monitor.monitors; + return monitor; + } + ), }, fetchMonitorsSubscriberRequest: false, }); @@ -652,24 +689,28 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - if ( - monitor._id === - action.payload.monitorId - ) { - monitor.logs = - action.payload.logs.data; - return monitor; - } else { - return monitor; - } - }) - : monitor.monitors; - return monitor; - }), + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === action.payload.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + if ( + monitor._id === + action.payload.monitorId + ) { + monitor.logs = + action.payload.logs.data; + return monitor; + } else { + return monitor; + } + } + ) + : monitor.monitors; + return monitor; + } + ), }, paginatedMonitorsList: { ...state.paginatedMonitorsList, @@ -677,7 +718,7 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) error: null, success: true, monitors: state.paginatedMonitorsList.monitors.map( - monitor => { + (monitor: $TSFixMe) => { monitor.monitors = monitor._id === action.payload.projectId ? monitor.monitors.map( @@ -735,24 +776,28 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - if ( - monitor._id === - action.payload.monitorId - ) { - monitor.statuses = - action.payload.statuses.data; - return monitor; - } else { - return monitor; - } - }) - : monitor.monitors; - return monitor; - }), + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === action.payload.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + if ( + monitor._id === + action.payload.monitorId + ) { + monitor.statuses = + action.payload.statuses.data; + return monitor; + } else { + return monitor; + } + } + ) + : monitor.monitors; + return monitor; + } + ), }, paginatedMonitorsList: { ...state.paginatedMonitorsList, @@ -760,7 +805,7 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) error: null, success: true, monitors: state.paginatedMonitorsList.monitors.map( - monitor => { + (monitor: $TSFixMe) => { monitor.monitors = monitor._id === action.payload.projectId ? monitor.monitors.map( @@ -813,50 +858,8 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - if ( - monitor._id === - action.payload.monitorId - ) { - const mainSiteUrlLogs: $TSFixMe = - action.payload.logs.data.filter( - (log: $TSFixMe) => - monitor.data && - monitor.data.url === - log.url - ); - if ( - mainSiteUrlLogs && - mainSiteUrlLogs.length > 0 - ) { - monitor.currentLighthouseLog = - mainSiteUrlLogs[0]; - } - monitor.lighthouseLogs = { - data: action.payload.logs.data, - skip: action.payload.skip, - limit: action.payload.limit, - count: action.payload.count, - }; - return monitor; - } else { - return monitor; - } - }) - : monitor.monitors; - return monitor; - }), - }, - paginatedMonitorsList: { - ...state.paginatedMonitorsList, - requesting: false, - error: null, - success: true, - monitors: state.paginatedMonitorsList.monitors.map( - monitor => { + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { monitor.monitors = monitor._id === action.payload.projectId ? monitor.monitors.map( @@ -867,11 +870,67 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) ) { const mainSiteUrlLogs: $TSFixMe = action.payload.logs.data.filter( - (log: $TSFixMe) => - monitor.data && - monitor.data - .url === - log.url + (log: $TSFixMe) => { + return ( + monitor.data && + monitor.data + .url === + log.url + ); + } + ); + if ( + mainSiteUrlLogs && + mainSiteUrlLogs.length > 0 + ) { + monitor.currentLighthouseLog = + mainSiteUrlLogs[0]; + } + monitor.lighthouseLogs = { + data: action.payload.logs + .data, + skip: action.payload.skip, + limit: action.payload + .limit, + count: action.payload + .count, + }; + return monitor; + } else { + return monitor; + } + } + ) + : monitor.monitors; + return monitor; + } + ), + }, + paginatedMonitorsList: { + ...state.paginatedMonitorsList, + requesting: false, + error: null, + success: true, + monitors: state.paginatedMonitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === action.payload.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + if ( + monitor._id === + action.payload.monitorId + ) { + const mainSiteUrlLogs: $TSFixMe = + action.payload.logs.data.filter( + (log: $TSFixMe) => { + return ( + monitor.data && + monitor.data + .url === + log.url + ); + } ); if ( mainSiteUrlLogs && @@ -992,221 +1051,250 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - if ( - monitor._id === - action.payload.monitorId - ) { - const data: $TSFixMe = Object.assign( - {}, - action.payload.data - ); - const intervalInDays: $TSFixMe = moment( - state.monitorsList.endDate - ).diff( - moment( - state.monitorsList.startDate - ), - 'days' - ); - const isNewMonitor: $TSFixMe = - moment( - state.monitorsList.endDate - ).diff( - moment(monitor.createdAt), - 'days' - ) < 2; - - let dateFormat: $TSFixMe, - outputFormat; - if ( - intervalInDays > 30 && - !isNewMonitor - ) { - dateFormat = 'weeks'; - outputFormat = - 'wo [week of] YYYY'; - } else if ( - intervalInDays > 2 && - !isNewMonitor - ) { - dateFormat = 'days'; - outputFormat = 'MMM Do YYYY'; - } else { + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === action.payload.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { if ( - moment( - state.monitorsList.endDate - ).diff( - moment(monitor.createdAt), - 'minutes' - ) > 60 + monitor._id === + action.payload.monitorId ) { - dateFormat = 'hours'; - outputFormat = - 'MMM Do YYYY, h A'; - } else { - dateFormat = 'minutes'; - outputFormat = - 'MMM Do YYYY, h:mm:ss A'; - } - } + const data: $TSFixMe = + Object.assign( + {}, + action.payload.data + ); + const intervalInDays: $TSFixMe = + moment( + state.monitorsList + .endDate + ).diff( + moment( + state.monitorsList + .startDate + ), + 'days' + ); + const isNewMonitor: $TSFixMe = + moment( + state.monitorsList + .endDate + ).diff( + moment( + monitor.createdAt + ), + 'days' + ) < 2; - const logData: $TSFixMe = { - ...data, - maxResponseTime: - data.responseTime, - maxCpuLoad: data.cpuLoad, - maxMemoryUsed: data.memoryUsed, - maxStorageUsed: data.storageUsed, - maxMainTemp: data.mainTemp, - intervalDate: moment( - data.createdAt - ).format(outputFormat), - }; + let dateFormat: $TSFixMe, + outputFormat; + if ( + intervalInDays > 30 && + !isNewMonitor + ) { + dateFormat = 'weeks'; + outputFormat = + 'wo [week of] YYYY'; + } else if ( + intervalInDays > 2 && + !isNewMonitor + ) { + dateFormat = 'days'; + outputFormat = + 'MMM Do YYYY'; + } else { + if ( + moment( + state.monitorsList + .endDate + ).diff( + moment( + monitor.createdAt + ), + 'minutes' + ) > 60 + ) { + dateFormat = 'hours'; + outputFormat = + 'MMM Do YYYY, h A'; + } else { + dateFormat = + 'minutes'; + outputFormat = + 'MMM Do YYYY, h:mm:ss A'; + } + } - monitor.logs = - monitor.logs && - monitor.logs.length > 0 - ? monitor.logs - .map( - (a: $TSFixMe) => - a._id - ) - .includes( - logData.probeId - ._id || - logData.probeId - ) || - !( - logData.probeId._id || - logData.probeId - ) - ? monitor.logs.map( - ( - probeLogs: $TSFixMe - ) => { - const probeId: $TSFixMe = - probeLogs._id; + const logData: $TSFixMe = { + ...data, + maxResponseTime: + data.responseTime, + maxCpuLoad: data.cpuLoad, + maxMemoryUsed: + data.memoryUsed, + maxStorageUsed: + data.storageUsed, + maxMainTemp: + data.mainTemp, + intervalDate: moment( + data.createdAt + ).format(outputFormat), + }; - if ( - probeId === - (logData - .probeId - ._id || - logData.probeId) || - (!probeId && - !( - logData - .probeId - ._id || - logData.probeId - )) - ) { - if ( - probeLogs.logs && - probeLogs - .logs - .length > - 0 && - moment( - probeLogs - .logs[0] - .createdAt - ).isSame( - moment( - logData.createdAt - ), - dateFormat - ) - ) { - const currentLog: $TSFixMe = - probeLogs - .logs[0]; - - logData.maxResponseTime = - data.responseTime > - currentLog.maxResponseTime - ? data.responseTime - : currentLog.maxResponseTime; - logData.maxCpuLoad = - data.cpuLoad > - currentLog.maxCpuLoad - ? data.cpuLoad - : currentLog.maxCpuLoad; - logData.maxMemoryUsed = - data.memoryUsed > - currentLog.maxMemoryUsed - ? data.memoryUsed - : currentLog.maxMemoryUsed; - logData.maxStorageUsed = - data.storageUsed > - currentLog.maxStorageUsed - ? data.storageUsed - : currentLog.maxStorageUsed; - logData.maxMainTemp = - data.mainTemp > - currentLog.maxMainTemp - ? data.mainTemp - : currentLog.maxMainTemp; - - return { - _id: probeId, - logs: [ - logData, - ...probeLogs.logs.slice( - 1 - ), - ], - }; - } else { - return { - _id: probeId, - logs: [ - logData, - ...probeLogs.logs, - ], - }; + monitor.logs = + monitor.logs && + monitor.logs.length > 0 + ? monitor.logs + .map( + ( + a: $TSFixMe + ) => { + return a._id; } - } else { - return probeLogs; - } - } - ) - : [ - ...monitor.logs, - { - _id: + ) + .includes( logData .probeId ._id || - logData.probeId || - null, - logs: [logData], - }, - ] - : [ - { - _id: + logData.probeId + ) || + !( logData.probeId ._id || - logData.probeId || - null, - logs: [logData], - }, - ]; + logData.probeId + ) + ? monitor.logs.map( + ( + probeLogs: $TSFixMe + ) => { + const probeId: $TSFixMe = + probeLogs._id; - return monitor; - } else { - return monitor; - } - }) - : monitor.monitors; + if ( + probeId === + (logData + .probeId + ._id || + logData.probeId) || + (!probeId && + !( + logData + .probeId + ._id || + logData.probeId + )) + ) { + if ( + probeLogs.logs && + probeLogs + .logs + .length > + 0 && + moment( + probeLogs + .logs[0] + .createdAt + ).isSame( + moment( + logData.createdAt + ), + dateFormat + ) + ) { + const currentLog: $TSFixMe = + probeLogs + .logs[0]; - return monitor; - }), + logData.maxResponseTime = + data.responseTime > + currentLog.maxResponseTime + ? data.responseTime + : currentLog.maxResponseTime; + logData.maxCpuLoad = + data.cpuLoad > + currentLog.maxCpuLoad + ? data.cpuLoad + : currentLog.maxCpuLoad; + logData.maxMemoryUsed = + data.memoryUsed > + currentLog.maxMemoryUsed + ? data.memoryUsed + : currentLog.maxMemoryUsed; + logData.maxStorageUsed = + data.storageUsed > + currentLog.maxStorageUsed + ? data.storageUsed + : currentLog.maxStorageUsed; + logData.maxMainTemp = + data.mainTemp > + currentLog.maxMainTemp + ? data.mainTemp + : currentLog.maxMainTemp; + + return { + _id: probeId, + logs: [ + logData, + ...probeLogs.logs.slice( + 1 + ), + ], + }; + } else { + return { + _id: probeId, + logs: [ + logData, + ...probeLogs.logs, + ], + }; + } + } else { + return probeLogs; + } + } + ) + : [ + ...monitor.logs, + { + _id: + logData + .probeId + ._id || + logData.probeId || + null, + logs: [ + logData, + ], + }, + ] + : [ + { + _id: + logData + .probeId + ._id || + logData.probeId || + null, + logs: [ + logData, + ], + }, + ]; + + return monitor; + } else { + return monitor; + } + } + ) + : monitor.monitors; + + return monitor; + } + ), }, fetchMonitorLogsRequest: false, }); @@ -1219,164 +1307,184 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((subProject: $TSFixMe) => { - subProject.monitors = - subProject._id === action.payload.status.projectId - ? subProject.monitors.map( - (monitor: $TSFixMe) => { - if ( - monitor._id === - action.payload.status.monitorId - ) { - const data: $TSFixMe = Object.assign( - {}, - action.payload.status.data - ); - const probes: $TSFixMe = - action.payload.probes; - const isValidProbe: $TSFixMe = - (monitor.type === 'url' || - monitor.type === 'api' || - monitor.type === 'ip') && - probes && - probes.length > 0; - + monitors: state.monitorsList.monitors.map( + (subProject: $TSFixMe) => { + subProject.monitors = + subProject._id === + action.payload.status.projectId + ? subProject.monitors.map( + (monitor: $TSFixMe) => { if ( - monitor.statuses && - monitor.statuses.length > 0 + monitor._id === + action.payload.status + .monitorId ) { - const monitorProbes: $TSFixMe = - monitor.statuses.map( - (a: $TSFixMe) => a._id + const data: $TSFixMe = + Object.assign( + {}, + action.payload.status + .data ); + const probes: $TSFixMe = + action.payload.probes; + const isValidProbe: $TSFixMe = + (monitor.type === 'url' || + monitor.type === + 'api' || + monitor.type === + 'ip') && + probes && + probes.length > 0; if ( - monitorProbes.includes( - data.probeId - ) || - !data.probeId + monitor.statuses && + monitor.statuses.length > + 0 ) { - monitor.statuses = + const monitorProbes: $TSFixMe = monitor.statuses.map( - ( - probeStatuses: $TSFixMe - ) => { - const probeId: $TSFixMe = - probeStatuses._id; - - if ( - probeId === - data.probeId || - !data.probeId - ) { - const previousStatus: $TSFixMe = - probeStatuses - .statuses[0]; - previousStatus.endTime = - new Date().toISOString(); - - return { - _id: probeId, - statuses: - [ - data, - previousStatus, - ...probeStatuses.statuses.slice( - 1 - ), - ], - }; - } else { - return probeStatuses; - } + (a: $TSFixMe) => { + return a._id; } ); if ( - isValidProbe && - !probes.every( - ( - probe: $TSFixMe - ) => - monitorProbes.includes( - probe._id - ) - ) + monitorProbes.includes( + data.probeId + ) || + !data.probeId ) { - // add manual status to all new probes - const newProbeStatuses: $TSFixMe = - []; + monitor.statuses = + monitor.statuses.map( + ( + probeStatuses: $TSFixMe + ) => { + const probeId: $TSFixMe = + probeStatuses._id; - probes.forEach( - ( - probe: $TSFixMe - ) => { - if ( - !monitorProbes.includes( - probe._id - ) - ) { - newProbeStatuses.push( - { - _id: probe._id, + if ( + probeId === + data.probeId || + !data.probeId + ) { + const previousStatus: $TSFixMe = + probeStatuses + .statuses[0]; + previousStatus.endTime = + new Date().toISOString(); + + return { + _id: probeId, statuses: [ data, + previousStatus, + ...probeStatuses.statuses.slice( + 1 + ), ], - } + }; + } else { + return probeStatuses; + } + } + ); + + if ( + isValidProbe && + !probes.every( + ( + probe: $TSFixMe + ) => { + return monitorProbes.includes( + probe._id ); } - } - ); + ) + ) { + // add manual status to all new probes + const newProbeStatuses: $TSFixMe = + []; + probes.forEach( + ( + probe: $TSFixMe + ) => { + if ( + !monitorProbes.includes( + probe._id + ) + ) { + newProbeStatuses.push( + { + _id: probe._id, + statuses: + [ + data, + ], + } + ); + } + } + ); + + monitor.statuses = + [ + ...monitor.statuses, + ...newProbeStatuses, + ]; + } + } else { monitor.statuses = [ ...monitor.statuses, - ...newProbeStatuses, - ]; - } - } else { - monitor.statuses = [ - ...monitor.statuses, - { - _id: - data.probeId || - null, - statuses: [data], - }, - ]; - } - } else { - if (isValidProbe) { - monitor.statuses = - probes.map( - ( - probe: $TSFixMe - ) => ({ - _id: probe._id, + { + _id: + data.probeId || + null, statuses: [ data, ], - }) - ); + }, + ]; + } } else { - monitor.statuses = [ - { - _id: - data.probeId || - null, - statuses: [data], - }, - ]; + if (isValidProbe) { + monitor.statuses = + probes.map( + ( + probe: $TSFixMe + ) => { + return { + _id: probe._id, + statuses: + [ + data, + ], + }; + } + ); + } else { + monitor.statuses = [ + { + _id: + data.probeId || + null, + statuses: [ + data, + ], + }, + ]; + } } } + return monitor; } - return monitor; - } - ) - : subProject.monitors; + ) + : subProject.monitors; - return subProject; - }), + return subProject; + } + ), }, fetchMonitorStatusesRequest: false, }); @@ -1388,57 +1496,74 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - if ( - monitor._id === - action.payload.monitorId - ) { - if ( - monitor.data && - monitor.data.url === - action.payload.data.url - ) { - monitor.currentLighthouseLog = - action.payload.data; - } - if ( - monitor.lighthouseLogs && - monitor.lighthouseLogs.data && - monitor.lighthouseLogs.data - .length > 0 - ) { - const logIndex: $TSFixMe = - monitor.lighthouseLogs.data.findIndex( - (log: $TSFixMe) => - log.url === + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === action.payload.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + if ( + monitor._id === + action.payload.monitorId + ) { + if ( + monitor.data && + monitor.data.url === action.payload.data .url - ); - if (logIndex > -1) { - monitor.lighthouseLogs.data[ - logIndex - ] = action.payload.data; - } - } else { - monitor.lighthouseLogs = { - data: [action.payload.data], - skip: 0, - limit: 1, - count: 1, - }; - } + ) { + monitor.currentLighthouseLog = + action.payload.data; + } + if ( + monitor.lighthouseLogs && + monitor.lighthouseLogs + .data && + monitor.lighthouseLogs + .data.length > 0 + ) { + const logIndex: $TSFixMe = + monitor.lighthouseLogs.data.findIndex( + ( + log: $TSFixMe + ) => { + return ( + log.url === + action + .payload + .data + .url + ); + } + ); + if (logIndex > -1) { + monitor.lighthouseLogs.data[ + logIndex + ] = + action.payload.data; + } + } else { + monitor.lighthouseLogs = { + data: [ + action.payload + .data, + ], + skip: 0, + limit: 1, + count: 1, + }; + } - return monitor; - } else { - return monitor; - } - }) - : monitor.monitors; - return monitor; - }), + return monitor; + } else { + return monitor; + } + } + ) + : monitor.monitors; + return monitor; + } + ), }, fetchLighthouseLogsRequest: false, }); @@ -1449,50 +1574,60 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - if ( - monitor.data && - action.payload.data.logs.lighthouseLogs.some( - (log: $TSFixMe) => - monitor.currentLighthouseLog && - log._id === - monitor - .currentLighthouseLog - ._id - ) - ) { - monitor.currentLighthouseLog = - action.payload.data.logs.lighthouseLogs.filter( - (log: $TSFixMe) => - monitor.currentLighthouseLog && - log._id === - monitor - .currentLighthouseLog - ._id - )[0]; - } - if ( - monitor._id === - action.payload.monitorId - ) { - monitor.lighthouseLogs = { - data: action.payload.data.logs - .lighthouseLogs, - skip: 0, - limit: 1, - count: 1, - }; - return monitor; - } else { - return monitor; - } - }) - : monitor.monitors; - return monitor; - }), + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === action.payload.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + if ( + monitor.data && + action.payload.data.logs.lighthouseLogs.some( + (log: $TSFixMe) => { + return ( + monitor.currentLighthouseLog && + log._id === + monitor + .currentLighthouseLog + ._id + ); + } + ) + ) { + monitor.currentLighthouseLog = + action.payload.data.logs.lighthouseLogs.filter( + (log: $TSFixMe) => { + return ( + monitor.currentLighthouseLog && + log._id === + monitor + .currentLighthouseLog + ._id + ); + } + )[0]; + } + if ( + monitor._id === + action.payload.monitorId + ) { + monitor.lighthouseLogs = { + data: action.payload.data + .logs.lighthouseLogs, + skip: 0, + limit: 1, + count: 1, + }; + return monitor; + } else { + return monitor; + } + } + ) + : monitor.monitors; + return monitor; + } + ), }, fetchLighthouseLogsRequest: false, }); @@ -1566,29 +1701,34 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors.find( - (targetMonitor: $TSFixMe, index: $TSFixMe) => { - if ( - targetMonitor._id === - action.payload.monitorId - ) { - monitor.monitors[ - index - ].subscribers.subscribers = monitor.monitors[ - index - ].subscribers.subscribers.filter( - (subscriber: $TSFixMe) => - subscriber._id !== - action.payload._id - ); - return true; + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors.find( + (targetMonitor: $TSFixMe, index: $TSFixMe) => { + if ( + targetMonitor._id === + action.payload.monitorId + ) { + monitor.monitors[ + index + ].subscribers.subscribers = monitor.monitors[ + index + ].subscribers.subscribers.filter( + (subscriber: $TSFixMe) => { + return ( + subscriber._id !== + action.payload._id + ); + } + ); + return true; + } + return false; } - return false; - } - ); - return monitor; - }), + ); + return monitor; + } + ), }, }); @@ -1600,11 +1740,15 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) error: null, success: false, monitors: state.monitorsList.monitors.map( - subProjectMonitor => { + (subProjectMonitor: $TSFixMe) => { subProjectMonitor.monitors = subProjectMonitor.monitors.filter( - ({ _id }: $TSFixMe) => - String(_id) !== String(action.payload) + ({ _id }: $TSFixMe) => { + return ( + String(_id) !== + String(action.payload) + ); + } ); subProjectMonitor.count = @@ -1647,7 +1791,7 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) error: null, success: false, monitors: state.monitorsList.monitors.map( - subProjectMonitor => { + (subProjectMonitor: $TSFixMe) => { subProjectMonitor.monitors = subProjectMonitor.monitors.map( (monitor: $TSFixMe) => { @@ -1701,7 +1845,7 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) error: null, success: true, monitors: state.monitorsList.monitors.map( - subProjectMonitor => { + (subProjectMonitor: $TSFixMe) => { subProjectMonitor.monitors = subProjectMonitor.monitors.map( (monitor: $TSFixMe) => { @@ -1752,9 +1896,9 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) case DELETE_PROJECT_MONITORS: monitors = Object.assign([], state.monitorsList.monitors); - monitors = monitors.filter( - monitor => action.payload !== monitor.projectId - ); + monitors = monitors.filter((monitor: $TSFixMe) => { + return action.payload !== monitor.projectId; + }); return Object.assign({}, state, { monitorsList: { @@ -1772,30 +1916,39 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.projectId._id || - action.payload.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - monitor.incidents = monitor.incidents - ? monitor.incidents.map( - (incident: $TSFixMe) => { - if ( - incident._id === - action.payload._id - ) { - return action.payload; - } else { - return incident; - } - } - ) - : [action.payload]; - return monitor; - }) - : monitor.monitors; - return monitor; - }), + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === action.payload.projectId._id || + action.payload.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + monitor.incidents = + monitor.incidents + ? monitor.incidents.map( + ( + incident: $TSFixMe + ) => { + if ( + incident._id === + action + .payload + ._id + ) { + return action.payload; + } else { + return incident; + } + } + ) + : [action.payload]; + return monitor; + } + ) + : monitor.monitors; + return monitor; + } + ), }, }); @@ -1806,30 +1959,39 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.projectId._id || - action.payload.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - monitor.incidents = monitor.incidents - ? monitor.incidents.map( - (incident: $TSFixMe) => { - if ( - incident._id === - action.payload._id - ) { - return action.payload; - } else { - return incident; - } - } - ) - : [action.payload]; - return monitor; - }) - : monitor.monitors; - return monitor; - }), + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === action.payload.projectId._id || + action.payload.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + monitor.incidents = + monitor.incidents + ? monitor.incidents.map( + ( + incident: $TSFixMe + ) => { + if ( + incident._id === + action + .payload + ._id + ) { + return action.payload; + } else { + return incident; + } + } + ) + : [action.payload]; + return monitor; + } + ) + : monitor.monitors; + return monitor; + } + ), }, }); @@ -1840,31 +2002,43 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.data.projectId._id || - action.payload.data.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - monitor.incidents = monitor.incidents - ? monitor.incidents.map( - (incident: $TSFixMe) => { - if ( - incident._id === - action.payload.data._id - ) { - return action.payload - .data; - } else { - return incident; - } - } - ) - : [action.payload.data]; - return monitor; - }) - : monitor.monitors; - return monitor; - }), + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === + action.payload.data.projectId._id || + action.payload.data.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + monitor.incidents = + monitor.incidents + ? monitor.incidents.map( + ( + incident: $TSFixMe + ) => { + if ( + incident._id === + action + .payload + .data + ._id + ) { + return action + .payload + .data; + } else { + return incident; + } + } + ) + : [action.payload.data]; + return monitor; + } + ) + : monitor.monitors; + return monitor; + } + ), }, }); @@ -1875,31 +2049,43 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) requesting: false, error: null, success: true, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === action.payload.data.projectId._id || - action.payload.data.projectId - ? monitor.monitors.map((monitor: $TSFixMe) => { - monitor.incidents = monitor.incidents - ? monitor.incidents.map( - (incident: $TSFixMe) => { - if ( - incident._id === - action.payload.data._id - ) { - return action.payload - .data; - } else { - return incident; - } - } - ) - : [action.payload.data]; - return monitor; - }) - : monitor.monitors; - return monitor; - }), + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === + action.payload.data.projectId._id || + action.payload.data.projectId + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + monitor.incidents = + monitor.incidents + ? monitor.incidents.map( + ( + incident: $TSFixMe + ) => { + if ( + incident._id === + action + .payload + .data + ._id + ) { + return action + .payload + .data; + } else { + return incident; + } + } + ) + : [action.payload.data]; + return monitor; + } + ) + : monitor.monitors; + return monitor; + } + ), }, }); @@ -1911,11 +2097,15 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) error: null, success: false, monitors: state.monitorsList.monitors.map( - subProjectMonitor => { + (subProjectMonitor: $TSFixMe) => { subProjectMonitor.monitors = subProjectMonitor.monitors.filter( - ({ _id }: $TSFixMe) => - String(_id) !== String(action.payload) + ({ _id }: $TSFixMe) => { + return ( + String(_id) !== + String(action.payload) + ); + } ); subProjectMonitor.count = @@ -1930,74 +2120,88 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) return Object.assign({}, state, { monitorsList: { ...state.monitorsList, - monitors: state.monitorsList.monitors.map((monitor: $TSFixMe) => { - monitor.monitors = - monitor._id === - (action.payload.projectId._id || - action.payload.projectId) - ? monitor.monitors.map((monitor: $TSFixMe) => { - const monitors: $TSFixMe = - action.payload.monitors.map( - (monitor: $TSFixMe) => - monitor.monitorId - ); - monitors.forEach( - (monitorObj: $TSFixMe) => { - if ( - monitor._id === monitorObj._id - ) { - let incidents: $TSFixMe = - monitor.incidents || []; - - if ( - incidents && - incidents.length - ) { + monitors: state.monitorsList.monitors.map( + (monitor: $TSFixMe) => { + monitor.monitors = + monitor._id === + (action.payload.projectId._id || + action.payload.projectId) + ? monitor.monitors.map( + (monitor: $TSFixMe) => { + const monitors: $TSFixMe = + action.payload.monitors.map( + (monitor: $TSFixMe) => { + return monitor.monitorId; + } + ); + monitors.forEach( + (monitorObj: $TSFixMe) => { if ( - incidents.length > 2 + monitor._id === + monitorObj._id ) { - incidents.splice( - -1, - 1 - ); - } - let found: $TSFixMe = false; - for (const incident of incidents) { + let incidents: $TSFixMe = + monitor.incidents || + []; + if ( - String( - incident._id - ) === - String( - action.payload - ._id - ) + incidents && + incidents.length ) { - found = true; - return; + if ( + incidents.length > + 2 + ) { + incidents.splice( + -1, + 1 + ); + } + let found: $TSFixMe = + false; + for (const incident of incidents) { + if ( + String( + incident._id + ) === + String( + action + .payload + ._id + ) + ) { + found = + true; + return; + } + } + !found && + incidents.unshift( + action.payload + ); + } else { + incidents = [ + action.payload, + ]; } + monitor = { + ...monitor, + incidents: + incidents, + count: + monitor.count + + 1, + }; } - !found && - incidents.unshift( - action.payload - ); - } else { - incidents = [ - action.payload, - ]; } - monitor = { - ...monitor, - incidents: incidents, - count: monitor.count + 1, - }; - } + ); + return monitor; } - ); - return monitor; - }) - : monitor.monitors; - return monitor; - }), + ) + : monitor.monitors; + return monitor; + } + ), }, }); @@ -2168,9 +2372,10 @@ export default function monitor(state: $TSFixMe = INITIAL_STATE, action: Action) }; case CLOSE_BREACHED_MONITOR_SLA_SUCCESS: { - const slaBreaches: $TSFixMe = state.monitorSlaBreaches.slaBreaches.filter( - monitor => String(monitor._id) !== String(action.payload._id) - ); + const slaBreaches: $TSFixMe = + state.monitorSlaBreaches.slaBreaches.filter((monitor: $TSFixMe) => { + return String(monitor._id) !== String(action.payload._id); + }); return { ...state, diff --git a/Dashboard/src/Reducers/monitorCustomField.ts b/Dashboard/src/Reducers/monitorCustomField.ts index 5a37bf2f73..a6786d91f3 100644 --- a/Dashboard/src/Reducers/monitorCustomField.ts +++ b/Dashboard/src/Reducers/monitorCustomField.ts @@ -71,7 +71,7 @@ export default function monitorCustomField( case types.DELETE_CUSTOM_FIELD_SUCCESS: { const fields: $TSFixMe = state.monitorCustomFields.fields.filter( - field => { + (field: $TSFixMe) => { return String(field._id) !== String(action.payload._id); } ); diff --git a/Dashboard/src/Reducers/monitorSla.ts b/Dashboard/src/Reducers/monitorSla.ts index ad7ede23d3..e27c573130 100644 --- a/Dashboard/src/Reducers/monitorSla.ts +++ b/Dashboard/src/Reducers/monitorSla.ts @@ -79,9 +79,11 @@ export default function monitorSla( }; case types.DELETE_MONITOR_SLA_SUCCESS: { - const slas: $TSFixMe = state.monitorSlas.slas.filter(sla => { - return String(sla._id) !== String(action.payload._id); - }); + const slas: $TSFixMe = state.monitorSlas.slas.filter( + (sla: $TSFixMe) => { + return String(sla._id) !== String(action.payload._id); + } + ); return { ...state, monitorSlas: { diff --git a/Dashboard/src/Reducers/statusPage.ts b/Dashboard/src/Reducers/statusPage.ts index 8dbec4bafe..a65c0cf12d 100755 --- a/Dashboard/src/Reducers/statusPage.ts +++ b/Dashboard/src/Reducers/statusPage.ts @@ -706,7 +706,7 @@ export default function statusPage( case CREATE_STATUSPAGE_SUCCESS: isExistingStatusPage = state.subProjectStatusPages.find( - statusPage => { + (statusPage: $TSFixMe) => { return ( statusPage._id === action.payload.projectId || statusPage._id === action.payload.projectId._id @@ -1529,7 +1529,7 @@ export default function statusPage( case FETCH_PROJECT_STATUSPAGE_SUCCESS: return Object.assign({}, state, { subProjectStatusPages: state.subProjectStatusPages.map( - statusPage => { + (statusPage: $TSFixMe) => { return statusPage._id === action.payload.projectId || statusPage._id === action.payload.projectId._id ? { @@ -1571,11 +1571,11 @@ export default function statusPage( success: true, error: null, }, - statusPages: state.statusPages.filter(({ _id }) => { + statusPages: state.statusPages.filter(({ _id }: $TSFixMe) => { return _id !== action.payload._id; }), subProjectStatusPages: state.subProjectStatusPages.map( - subProjectStatusPage => { + (subProjectStatusPage: $TSFixMe) => { subProjectStatusPage.statusPages = subProjectStatusPage.statusPages.filter( ({ _id }: $TSFixMe) => { diff --git a/Dashboard/src/Reducers/statusPageCategory.ts b/Dashboard/src/Reducers/statusPageCategory.ts index d20d2efbe6..6360365a0c 100644 --- a/Dashboard/src/Reducers/statusPageCategory.ts +++ b/Dashboard/src/Reducers/statusPageCategory.ts @@ -113,7 +113,7 @@ export default function resourceCategory( fetchStatusPageCategories: { ...state.fetchStatusPageCategories, categories: state.fetchStatusPageCategories.categories.map( - category => { + (category: $TSFixMe) => { if ( String(category._id) === String(action.payload._id) @@ -224,7 +224,7 @@ export default function resourceCategory( ...state.fetchStatusPageCategories, categories: state.fetchStatusPageCategories.categories.filter( - category => { + (category: $TSFixMe) => { return ( String(category._id) !== String(action.payload._id) diff --git a/Dashboard/src/Reducers/team.ts b/Dashboard/src/Reducers/team.ts index 9ce4774717..fef2ecc7fb 100755 --- a/Dashboard/src/Reducers/team.ts +++ b/Dashboard/src/Reducers/team.ts @@ -159,7 +159,7 @@ export default (state: $TSFixMe = initialState, action: Action): void => { }, // teamMembers: action.payload subProjectTeamMembers: state.subProjectTeamMembers.map( - subProject => { + (subProject: $TSFixMe) => { subProject.teamMembers = action.payload.find( (team: $TSFixMe) => { return team.projectId === subProject._id; @@ -213,7 +213,7 @@ export default (state: $TSFixMe = initialState, action: Action): void => { }, // teamMembers: action.payload.data, subProjectTeamMembers: state.subProjectTeamMembers.map( - subProject => { + (subProject: $TSFixMe) => { if (action.payload) { const projectObj: $TSFixMe = action.payload.find( (team: $TSFixMe) => { @@ -318,7 +318,7 @@ export default (state: $TSFixMe = initialState, action: Action): void => { }, // teamMembers: teamMembers, subProjectTeamMembers: state.subProjectTeamMembers.map( - subProject => { + (subProject: $TSFixMe) => { subProject.teamMembers = action.payload.find( (team: $TSFixMe) => { return team.projectId === subProject._id; diff --git a/Dashboard/src/Utils/joinNames.ts b/Dashboard/src/Utils/joinNames.ts index da335a2139..c196dce45e 100644 --- a/Dashboard/src/Utils/joinNames.ts +++ b/Dashboard/src/Utils/joinNames.ts @@ -4,7 +4,7 @@ * @returns a string */ -const joinNames: Function = (acc: $TSFixMe = [], arr: $TSFixMe): void => { +const joinNames: Function = (arr: $TSFixMe): void => { if (!Array.isArray(arr)) { return ''; } diff --git a/Dashboard/src/Utils/keybinding.ts b/Dashboard/src/Utils/keybinding.ts index 4bbce923b5..1c8b86a690 100644 --- a/Dashboard/src/Utils/keybinding.ts +++ b/Dashboard/src/Utils/keybinding.ts @@ -40,9 +40,6 @@ const keyBind: Function = ( export const navKeyBind: Function = (route: $TSFixMe, path: $TSFixMe): void => { let keys: $TSFixMe = []; - const resetKeys: Function = (): void => { - return (acc: $TSFixMe = []); - }; // reasons to use keydown // 1 --> gives the user impression that they can press and hold two keys simultaneously // 2 --> accommodate users that don't like pressing and holding two keys simultaneously (which is the actual behaviour, (^-^)) @@ -54,7 +51,7 @@ export const navKeyBind: Function = (route: $TSFixMe, path: $TSFixMe): void => { export const cleanBind: Function = (route: $TSFixMe, path: $TSFixMe): void => { let keys: $TSFixMe = []; const resetKeys: Function = (): void => { - return (acc: $TSFixMe = []); + return []; }; window.removeEventListener('keydown', (e: $TSFixMe) => { return keyBind(e, route, path, keys, resetKeys); diff --git a/DataIngestor/services/probeService.ts b/DataIngestor/services/probeService.ts index 6d0b00abd4..c7a329af2a 100755 --- a/DataIngestor/services/probeService.ts +++ b/DataIngestor/services/probeService.ts @@ -205,7 +205,7 @@ export default { }, }); - const incidentIds: $TSFixMe = incidents.map(incident: $TSFixMe => incident._id); + const incidentIds: $TSFixMe = incidents.map((incident: $TSFixMe) => incident._id); if (incidentIds && incidentIds.length) { log = await MonitorLogService.updateOneBy( diff --git a/DataIngestor/utils/api.ts b/DataIngestor/utils/api.ts index a309651f30..b415dbaffd 100755 --- a/DataIngestor/utils/api.ts +++ b/DataIngestor/utils/api.ts @@ -41,7 +41,7 @@ const _this: $TSFixMe = { }); }, - get: (url: URL, withBaseUrl = false) => { + get: (url: URL, withBaseUrl: $TSFixMe = false) => { const headers: $TSFixMe = this.getHeaders(); return new Promise((resolve: Function, reject: Function) => { axios({ diff --git a/HttpTestServer/types/HttpTestServerResponse.ts b/HttpTestServer/types/HttpTestServerResponse.ts index cee98b13ea..cea8d2fb7a 100644 --- a/HttpTestServer/types/HttpTestServerResponse.ts +++ b/HttpTestServer/types/HttpTestServerResponse.ts @@ -58,7 +58,7 @@ class HTTPTestServerResponse { this._htmlBody = v; } - toJSON(): JSONObject { + public toJSON(): JSONObject { return { statusCode: this.statusCode.toNumber(), responseType: { diff --git a/InitScript/util/encryptDecrypt.ts b/InitScript/util/encryptDecrypt.ts index ae8c8c410f..c2f072ae84 100755 --- a/InitScript/util/encryptDecrypt.ts +++ b/InitScript/util/encryptDecrypt.ts @@ -28,7 +28,7 @@ export default { return promise; }, - decrypt: (encText: $TSFixMe, iv = EncryptionKeys.iv) => { + decrypt: (encText: $TSFixMe, iv : $TSFixMe = EncryptionKeys.iv) => { const promise: Promise = new Promise( (resolve: Function, reject: Function): $TSFixMe => { try { diff --git a/InitScript/util/randomChar.ts b/InitScript/util/randomChar.ts index 78e07b1e42..37ad0072f3 100644 --- a/InitScript/util/randomChar.ts +++ b/InitScript/util/randomChar.ts @@ -4,7 +4,7 @@ * @returns { string } a string of random characters */ -export default (num = 15): void => { +export default (num: $TSFixMe = 15): void => { const input: $TSFixMe = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; let output: $TSFixMe = ''; diff --git a/JavaScriptSDK/src/cli/server-monitor/bin/index.ts b/JavaScriptSDK/src/cli/server-monitor/bin/index.ts index c6304dfa49..390f8f66f6 100644 --- a/JavaScriptSDK/src/cli/server-monitor/bin/index.ts +++ b/JavaScriptSDK/src/cli/server-monitor/bin/index.ts @@ -272,7 +272,7 @@ checkParams(questions).then((values: $TSFixMe) => { return `${monitor.componentId.name} / ${monitor.name} (${monitor._id})`; }); - prompt(question).then(({ monitorId }) => { + prompt(question).then(({ monitorId }: $TSFixMe) => { resolve( monitorId .replace(/\/|\(|\)$/gi, '') diff --git a/JavaScriptSDK/src/cli/server-monitor/lib/api.ts b/JavaScriptSDK/src/cli/server-monitor/lib/api.ts index bddf1a4cbf..773c0a7b73 100644 --- a/JavaScriptSDK/src/cli/server-monitor/lib/api.ts +++ b/JavaScriptSDK/src/cli/server-monitor/lib/api.ts @@ -124,9 +124,16 @@ const ping: Function = ( .map((partition: $TSFixMe) => { return partition.used; }) - .reduce((used, partitionUsed) => { - return used + partitionUsed; - }) + .reduce( + ( + used: $TSFixMe, + partitionUsed: $TSFixMe + ) => { + return ( + used + partitionUsed + ); + } + ) : storage.used, totalStorage: storage && storage.length > 0 @@ -138,7 +145,7 @@ const ping: Function = ( .map((partition: $TSFixMe) => { return partition.use; }) - .reduce((use, partitionUse) => { + .reduce((use: $TSFixMe, partitionUse: $TSFixMe) => { return use + partitionUse; }) : storage.use, @@ -189,7 +196,7 @@ export default function ( monitorId: $TSFixMe ): void { let pingServer: $TSFixMe, - projectId = config, + projectId: $TSFixMe = config, interval: $TSFixMe, timeout: $TSFixMe, simulate: $TSFixMe, @@ -212,7 +219,7 @@ export default function ( * @param {string} id - The monitor id of the server monitor. * @return {(Object | number)} The ping server cron job or the error code. */ - start: (id = monitorId) => { + start: (id: $TSFixMe = monitorId) => { const url: string = `monitor/${projectId}/monitor/${ id && typeof id === 'string' ? `${id}/` : '' }?type=server-monitor`; diff --git a/JavaScriptSDK/src/cli/server-monitor/lib/helpers.ts b/JavaScriptSDK/src/cli/server-monitor/lib/helpers.ts index bff1204ad5..754d0b518e 100644 --- a/JavaScriptSDK/src/cli/server-monitor/lib/helpers.ts +++ b/JavaScriptSDK/src/cli/server-monitor/lib/helpers.ts @@ -78,7 +78,7 @@ const post: Function = ( data: $TSFixMe, key: $TSFixMe, success: $TSFixMe, - error = defaultErrorHandler + error: $TSFixMe = defaultErrorHandler ): void => { headers['apiKey'] = key; diff --git a/JavaScriptSDK/src/cli/server-monitor/test/server-monitor.test.ts b/JavaScriptSDK/src/cli/server-monitor/test/server-monitor.test.ts index 0f323cd120..c6b471d4c5 100644 --- a/JavaScriptSDK/src/cli/server-monitor/test/server-monitor.test.ts +++ b/JavaScriptSDK/src/cli/server-monitor/test/server-monitor.test.ts @@ -21,7 +21,7 @@ const badProjectId: string = 'badProjectId', badApiKey: $TSFixMe = 'badApiKey'; const invalidProjectId: string = utils.generateRandomString(); const timeout: $TSFixMe = 5000, - monitor = { + monitor: $TSFixMe = { name: 'New Monitor', type: 'server-monitor', data: {}, diff --git a/JavaScriptSDK/src/listener.ts b/JavaScriptSDK/src/listener.ts index 52ca6fac4c..00f6e91c2a 100644 --- a/JavaScriptSDK/src/listener.ts +++ b/JavaScriptSDK/src/listener.ts @@ -166,7 +166,7 @@ class OneUptimeListener { (res: $TSFixMe) => { obj.status_code = res.status; }, - err => { + (err: $TSFixMe) => { obj.status_code = err.status; } ); diff --git a/JavaScriptSDK/src/listeners/mongoose.ts b/JavaScriptSDK/src/listeners/mongoose.ts index 733f03bd2d..f9bac3465e 100644 --- a/JavaScriptSDK/src/listeners/mongoose.ts +++ b/JavaScriptSDK/src/listeners/mongoose.ts @@ -9,7 +9,7 @@ class MongooseListener { this.end = end; } - wrapAsync(orig, name) { + public wrapAsync(orig: $TSFixMe, name: $TSFixMe) { return async function (): void { const uuid: $TSFixMe = uuidv4(); diff --git a/JavaScriptSDK/src/performanceTracker.ts b/JavaScriptSDK/src/performanceTracker.ts index 3f6d1ae8d1..a00c5d7a91 100644 --- a/JavaScriptSDK/src/performanceTracker.ts +++ b/JavaScriptSDK/src/performanceTracker.ts @@ -73,13 +73,13 @@ class PerformanceTracker { process.on('unhandledRejection', this._sendDataOnExit.bind(this)); process.on('uncaughtException', this._sendDataOnExit.bind(this)); } - async _sendDataOnExit(): void { + private async _sendDataOnExit(): void { await this.store.processDataOnExit(); } private _setUpOutgoingListener(): void { return new OutgoingListener(this.start, this.end, this.store); } - setUpDataBaseListener(): void { + public setUpDataBaseListener(): void { const load: $TSFixMe = Module._load; Module._load = function (request: $TSFixMe): void { diff --git a/JavaScriptSDK/src/util.ts b/JavaScriptSDK/src/util.ts index b114a69f14..f4fab4e17f 100644 --- a/JavaScriptSDK/src/util.ts +++ b/JavaScriptSDK/src/util.ts @@ -159,7 +159,7 @@ private _getUserDeviceDetails(): void { } private _readFileFromSource(fileName: $TSFixMe): void { return new Promise((resolve: $TSFixMe) => { - readFile(fileName, (err: $TSFixMe, data: $TSFixMe){ + readFile(fileName: $TSFixMe, (err: $TSFixMe, data: $TSFixMe)=> { const content: $TSFixMe = err ? null : data.toString(); CONTENT_CACHE.set(fileName, content); diff --git a/JavaScriptSDK/src/utils/perfTimer.ts b/JavaScriptSDK/src/utils/perfTimer.ts index 93d6e2ff6a..58ebbf6389 100644 --- a/JavaScriptSDK/src/utils/perfTimer.ts +++ b/JavaScriptSDK/src/utils/perfTimer.ts @@ -11,7 +11,7 @@ class PerfTimer { this.appId = appId; this.appKey = appKey; this.dataStore = new DataStore(this.apiUrl, this.appId, this.appKey); - this.obs = new PerformanceObserver((list: $TSFixMe) { + this.obs = new PerformanceObserver((list: $TSFixMe) =>{ const entry: $TSFixMe = list.getEntries()[0]; const id: $TSFixMe = entry.name.slice(entry.name.indexOf('-') + 1); const originalValue: $TSFixMe = this.dataStore.getValue(id); diff --git a/JavaScriptSDK/test/tracker.test.ts b/JavaScriptSDK/test/tracker.test.ts index 44ac893a5d..cfa71cfb15 100644 --- a/JavaScriptSDK/test/tracker.test.ts +++ b/JavaScriptSDK/test/tracker.test.ts @@ -28,7 +28,7 @@ describe('Tracker Timeline', function (): void { }); }; this.timeout(timeout + 1000); - let projectId: ObjectID, token: $TSFixMe, componentId; + let projectId: ObjectID, token: $TSFixMe, componentId: $TSFixMe; // create a new user const component: $TSFixMe = { name: 'Our Component' }; diff --git a/Mail/Services/MailService.ts b/Mail/Services/MailService.ts index a9e7c047b6..d322df7f9f 100755 --- a/Mail/Services/MailService.ts +++ b/Mail/Services/MailService.ts @@ -292,10 +292,7 @@ export default class MailService { mail.body = await this.compileEmailBody(mail.templateType, mail.vars); mail.subject = this.compileSubject(mail.subject, mail.vars); - try { - await this.transportMail(mail, mailServer); - } catch (error) { - throw error; - } + await this.transportMail(mail, mailServer); + } } diff --git a/ScriptRunner/utils/scriptSandbox.ts b/ScriptRunner/utils/scriptSandbox.ts index 1f6daf34e3..d0a1427974 100644 --- a/ScriptRunner/utils/scriptSandbox.ts +++ b/ScriptRunner/utils/scriptSandbox.ts @@ -150,8 +150,8 @@ const run: Function = async ( }); let totalRuntime: $TSFixMe = 0, - statementTimeExceeded = false, - scriptTimeExceeded = false; + statementTimeExceeded: $TSFixMe = false, + scriptTimeExceeded: $TSFixMe = false; const checker: $TSFixMe = setInterval( () => { diff --git a/StatusPage/src/Actions/status.ts b/StatusPage/src/Actions/status.ts index 93532d3cb7..b44242380c 100755 --- a/StatusPage/src/Actions/status.ts +++ b/StatusPage/src/Actions/status.ts @@ -1463,7 +1463,7 @@ export const getAnnouncementsFailure: Function = (data: $TSFixMe): void => { export function getAnnouncements( projectId: ObjectID, statusPageId: $TSFixMe, - skip: number = 0 + skip: number = 0, limit: PositiveNumber ) { return function (dispatch: Dispatch): void {