Format all files on BE with perttier config

This commit is contained in:
Alex Holliday committed 2024-10-17 12:07:30 +08:00
1 parent d8e2b06eca
commit fd2d16cf78
28 files changed
+230 -240

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@
"bracketSameLine": false,
"singleAttributePerLine": true,
"semi": true,
"jsx-single-quote": false,
"jsxSingleQuote": false,
"quoteProps": "as-needed",
"arrowParens": "always",
"trailingComma": "es5",
+2 -6
View File
@@ -59,9 +59,7 @@ const issueInvitation = async (req, res, next) => {
});
});
return res
.status(200)
.json({ success: true, msg: "Invite sent", data: inviteToken });
return res.status(200).json({ success: true, msg: "Invite sent", data: inviteToken });
} catch (error) {
next(handleError(error, SERVICE_NAME, "inviteController"));
}
@@ -77,9 +75,7 @@ const inviteVerifyController = async (req, res, next) => {
try {
const invite = await req.db.getInviteToken(req.body.token);
res
.status(200)
.json({ status: "success", msg: "Invite verified", data: invite });
res.status(200).json({ status: "success", msg: "Invite verified", data: invite });
} catch (error) {
next(handleError(error, SERVICE_NAME, "inviteVerifyController"));
}
@@ -55,9 +55,7 @@ const getMaintenanceWindowById = async (req, res, next) => {
return;
}
try {
const maintenanceWindow = await req.db.getMaintenanceWindowById(
req.params.id
);
const maintenanceWindow = await req.db.getMaintenanceWindowById(req.params.id);
return res.status(200).json({
success: true,
msg: successMessages.MAINTENANCE_WINDOW_GET_BY_ID,
@@ -97,9 +95,7 @@ const getMaintenanceWindowsByTeamId = async (req, res, next) => {
const getMaintenanceWindowsByMonitorId = async (req, res, next) => {
try {
await getMaintenanceWindowsByMonitorIdParamValidation.validateAsync(
req.params
);
await getMaintenanceWindowsByMonitorIdParamValidation.validateAsync(req.params);
} catch (error) {
next(handleValidationError(error, SERVICE_NAME));
return;
+1 -3
View File
@@ -47,9 +47,7 @@ const addJob = async (req, res, next) => {
const obliterateQueue = async (req, res, next) => {
try {
await req.jobQueue.obliterate();
return res
.status(200)
.json({ success: true, msg: successMessages.QUEUE_OBLITERATE });
return res.status(200).json({ success: true, msg: successMessages.QUEUE_OBLITERATE });
} catch (error) {
next(handleError(error, SERVICE_NAME, "obliterateQueue"));
return;
@@ -201,10 +201,7 @@ const deleteMaintenanceWindowByUserId = async (userId) => {
}
};
const editMaintenanceWindowById = async (
maintenanceWindowId,
maintenanceWindowData
) => {
const editMaintenanceWindowById = async (maintenanceWindowId, maintenanceWindowData) => {
console.log(maintenanceWindowData);
try {
const editedMaintenanceWindow = MaintenanceWindow.findByIdAndUpdate(
+8 -19
View File
@@ -11,10 +11,7 @@ import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const demoMonitorsPath = path.resolve(
__dirname,
"../../../utils/demoMonitors.json"
);
const demoMonitorsPath = path.resolve(__dirname, "../../../utils/demoMonitors.json");
const demoMonitors = JSON.parse(fs.readFileSync(demoMonitorsPath, "utf8"));
const SERVICE_NAME = "monitorModule";
@@ -167,9 +164,7 @@ const getMonitorStatsById = async (req) => {
sortOrder = sortOrder === "asc" ? 1 : -1;
let model =
monitor.type === "http" || monitor.type === "ping"
? Check
: PageSpeedCheck;
monitor.type === "http" || monitor.type === "ping" ? Check : PageSpeedCheck;
const monitorStats = {
...monitor.toObject(),
@@ -197,8 +192,7 @@ const getMonitorStatsById = async (req) => {
if (monitor.type === "http" || monitor.type === "ping") {
// HTTP/PING Specific stats
monitorStats.periodAvgResponseTime =
getAverageResponseTime(checksForDateRange);
monitorStats.periodAvgResponseTime = getAverageResponseTime(checksForDateRange);
monitorStats.periodUptime = getUptimePercentage(checksForDateRange);
// Aggregate data
@@ -233,8 +227,7 @@ const getMonitorStatsById = async (req) => {
(check) => check.status === false
).length;
const avgResponseTime =
group.checks.reduce((sum, check) => sum + check.responseTime, 0) /
totalChecks;
group.checks.reduce((sum, check) => sum + check.responseTime, 0) / totalChecks;
return {
time: group.time,
@@ -431,9 +424,7 @@ const getMonitorsByTeamId = async (req, res) => {
}
let model =
monitor.type === "http" || monitor.type === "ping"
? Check
: PageSpeedCheck;
monitor.type === "http" || monitor.type === "ping" ? Check : PageSpeedCheck;
// Checks are order newest -> oldest
let checks = await model
@@ -549,11 +540,9 @@ const editMonitor = async (candidateId, candidateMonitor) => {
candidateMonitor.notifications = undefined;
try {
const editedMonitor = await Monitor.findByIdAndUpdate(
candidateId,
candidateMonitor,
{ new: true }
);
const editedMonitor = await Monitor.findByIdAndUpdate(candidateId, candidateMonitor, {
new: true,
});
return editedMonitor;
} catch (error) {
error.service = SERVICE_NAME;
@@ -63,8 +63,4 @@ const deletePageSpeedChecksByMonitorId = async (monitorId) => {
}
};
export {
createPageSpeedCheck,
getPageSpeedChecks,
deletePageSpeedChecksByMonitorId,
};
export { createPageSpeedCheck, getPageSpeedChecks, deletePageSpeedChecksByMonitorId };
+2 -6
View File
@@ -69,9 +69,7 @@ const getUserByEmail = async (email) => {
try {
// Need the password to be able to compare, removed .select()
// We can strip the hash before returing the user
const user = await UserModel.findOne({ email: email }).select(
"-profileImage"
);
const user = await UserModel.findOne({ email: email }).select("-profileImage");
if (user) {
return user;
} else {
@@ -186,9 +184,7 @@ const deleteAllOtherUsers = async () => {
const getAllUsers = async (req, res) => {
try {
const users = await UserModel.find()
.select("-password")
.select("-profileImage");
const users = await UserModel.find().select("-password").select("-profileImage");
return users;
} catch (error) {
error.service = SERVICE_NAME;
+1 -3
View File
@@ -49,9 +49,7 @@ const verifySuperAdmin = (req, res, next) => {
logger.error(errorMessages.INVALID_AUTH_TOKEN, {
service: SERVICE_NAME,
});
return res
.status(401)
.json({ success: false, msg: errorMessages.UNAUTHORIZED });
return res.status(401).json({ success: false, msg: errorMessages.UNAUTHORIZED });
}
next();
});
+2 -15
View File
@@ -2113,14 +2113,7 @@
},
"UserUpdateRequest": {
"type": "object",
"required": [
"firstName",
"lastName",
"email",
"password",
"role",
"teamId"
],
"required": ["firstName", "lastName", "email", "password", "role", "teamId"],
"properties": {
"firstName": {
"type": "string"
@@ -2212,13 +2205,7 @@
},
"CreateCheckBody": {
"type": "object",
"required": [
"monitorId",
"status",
"responseTime",
"statusCode",
"message"
],
"required": ["monitorId", "status", "responseTime", "statusCode", "message"],
"properties": {
"monitorId": {
"type": "string"
+2 -10
View File
@@ -15,19 +15,11 @@ const router = Router();
router.get("/:monitorId", getChecks);
router.post("/:monitorId", verifyOwnership(Monitor, "monitorId"), createCheck);
router.delete(
"/:monitorId",
verifyOwnership(Monitor, "monitorId"),
deleteChecks
);
router.delete("/:monitorId", verifyOwnership(Monitor, "monitorId"), deleteChecks);
router.get("/team/:teamId", getTeamChecks);
router.delete(
"/team/:teamId",
isAllowed(["admin", "superadmin"]),
deleteChecksByTeamId
);
router.delete("/team/:teamId", isAllowed(["admin", "superadmin"]), deleteChecksByTeamId);
router.put("/team/ttl", isAllowed(["admin", "superadmin"]), updateChecksTTL);
+1 -6
View File
@@ -8,12 +8,7 @@ import {
const router = Router();
router.post(
"/",
isAllowed(["admin", "superadmin"]),
verifyJWT,
issueInvitation
);
router.post("/", isAllowed(["admin", "superadmin"]), verifyJWT, issueInvitation);
router.post("/verify", issueInvitation);
export default router;
+1 -4
View File
@@ -1,8 +1,5 @@
import { Router } from "express";
import {
getAppSettings,
updateAppSettings,
} from "../controllers/settingsController.js";
import { getAppSettings, updateAppSettings } from "../controllers/settingsController.js";
import { isAllowed } from "../middleware/isAllowed.js";
const router = Router();
+4 -15
View File
@@ -28,10 +28,7 @@ class EmailService {
*/
this.loadTemplate = (templateName) => {
try {
const templatePath = path.join(
__dirname,
`../templates/${templateName}.mjml`
);
const templatePath = path.join(__dirname, `../templates/${templateName}.mjml`);
const templateContent = fs.readFileSync(templatePath, "utf8");
return compile(templateContent);
} catch (error) {
@@ -61,12 +58,8 @@ class EmailService {
* @type {Object}
*/
const {
systemEmailHost,
systemEmailPort,
systemEmailAddress,
systemEmailPassword,
} = this.settingsService.getSettings();
const { systemEmailHost, systemEmailPort, systemEmailAddress, systemEmailPassword } =
this.settingsService.getSettings();
const emailConfig = {
host: systemEmailHost,
@@ -121,11 +114,7 @@ class EmailService {
};
try {
const info = await sendEmail(
to,
subject,
await buildHtml(template, context)
);
const info = await sendEmail(to, subject, await buildHtml(template, context));
return info.messageId;
} catch (error) {
error.service = SERVICE_NAME;
+3 -7
View File
@@ -78,8 +78,7 @@ class JobQueue {
const maintenanceWindows =
await this.db.getMaintenanceWindowsByMonitorId(monitorId);
// Check for active maintenance window:
const maintenanceWindowActive = maintenanceWindows.reduce(
(acc, window) => {
const maintenanceWindowActive = maintenanceWindows.reduce((acc, window) => {
if (window.active) {
const start = new Date(window.start);
const end = new Date(window.end);
@@ -96,9 +95,7 @@ class JobQueue {
}
}
return acc;
},
false
);
}, false);
if (!maintenanceWindowActive) {
const res = await this.networkService.getStatus(job);
@@ -175,8 +172,7 @@ class JobQueue {
if (workerStats.load > JOBS_PER_WORKER) {
// Find out how many more jobs we have than current workers can handle
const excessJobs =
workerStats.jobs.length - this.workers.length * JOBS_PER_WORKER;
const excessJobs = workerStats.jobs.length - this.workers.length * JOBS_PER_WORKER;
// Divide by jobs/worker to find out how many workers to add
const workersToAdd = Math.ceil(excessJobs / JOBS_PER_WORKER);
+5 -12
View File
@@ -24,13 +24,10 @@ class NetworkService {
async handleNotification(monitor, isAlive) {
try {
let template =
isAlive === true ? "serverIsUpTemplate" : "serverIsDownTemplate";
let template = isAlive === true ? "serverIsUpTemplate" : "serverIsDownTemplate";
let status = isAlive === true ? "up" : "down";
const notifications = await this.db.getNotificationsByMonitorId(
monitor._id
);
const notifications = await this.db.getNotificationsByMonitorId(monitor._id);
for (const notification of notifications) {
if (notification.type === "email") {
await this.emailService.buildAndSendEmail(
@@ -104,9 +101,7 @@ class NetworkService {
const endTime = Date.now();
error.responseTime = endTime - startTime;
error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined
? (error.method = "measureResponseTime")
: null;
error.method === undefined ? (error.method = "measureResponseTime") : null;
throw error;
}
}
@@ -125,8 +120,7 @@ class NetworkService {
let isAlive;
try {
const { responseTime, response } =
await this.measureResponseTime(operation);
const { responseTime, response } = await this.measureResponseTime(operation);
isAlive = response.alive;
const checkData = {
monitorId: job.data._id,
@@ -167,8 +161,7 @@ class NetworkService {
// attempt connection
try {
const { responseTime, response } =
await this.measureResponseTime(operation);
const { responseTime, response } = await this.measureResponseTime(operation);
// check if response is in the 200 range, if so, service is up
isAlive = response.status >= 200 && response.status < 300;
+23 -6
View File
@@ -1,31 +1,48 @@
<!-- name, link -->
<mjml>
<mj-head>
<mj-font name="Roboto" href="https://fonts.googleapis.com/css?family=Roboto:300,500"></mj-font>
<mj-font
name="Roboto"
href="https://fonts.googleapis.com/css?family=Roboto:300,500"
></mj-font>
<mj-attributes>
<mj-all font-family="Roboto, Helvetica, sans-serif"></mj-all>
<mj-text font-weight="300" font-size="16px" color="#616161" line-height="24px"></mj-text>
<mj-text
font-weight="300"
font-size="16px"
color="#616161"
line-height="24px"
></mj-text>
<mj-section padding="0px"></mj-section>
</mj-attributes>
</mj-head>
<mj-body>
<mj-section padding="20px 0">
<mj-column width="100%">
<mj-text align="left" font-size="10px">Message from BlueWave Uptime Service</mj-text>
<mj-text
align="left"
font-size="10px"
>Message from BlueWave Uptime Service</mj-text
>
</mj-column>
</mj-section>
<mj-section>
<mj-column width="100%">
<mj-text>
<p>Hello {{name}}!</p>
<p>One of the admins created an account for you on the BlueWave Uptime server.</p>
<p>
One of the admins created an account for you on the BlueWave Uptime server.
</p>
<p>You can go ahead and create your account using this link.</p>
<p><a href={{link}}>{{link}}</a></p>
<p><a href="{{link}}">{{link}}</a></p>
<p>Thank you.</p>
</mj-text>
</mj-column>
<mj-column width="100%">
<mj-divider border-width="1px" border-color="#E0E0E0"></mj-divider>
<mj-divider
border-width="1px"
border-color="#E0E0E0"
></mj-divider>
<mj-text font-size="12px">
<p>This email was sent by BlueWave Uptime.</p>
</mj-text>
+35 -7
View File
@@ -1,20 +1,45 @@
<mjml>
<mj-head>
<mj-font name="Roboto" href="https://fonts.googleapis.com/css?family=Roboto:300,500"></mj-font>
<mj-font
name="Roboto"
href="https://fonts.googleapis.com/css?family=Roboto:300,500"
></mj-font>
<mj-attributes>
<mj-all font-family="Roboto, Helvetica, sans-serif"></mj-all>
<mj-text font-weight="300" font-size="16px" color="#616161" line-height="24px"></mj-text>
<mj-text
font-weight="300"
font-size="16px"
color="#616161"
line-height="24px"
></mj-text>
<mj-section padding="0px"></mj-section>
</mj-attributes>
</mj-head>
<mj-body>
<mj-section padding="20px 0">
<mj-column width="100%">
<mj-text align="left" font-size="10px">Message from BlueWave Uptime Service</mj-text>
<mj-text
align="left"
font-size="10px"
>Message from BlueWave Uptime Service</mj-text
>
</mj-column>
<mj-column width="45%" padding-top="20px">
<mj-text align="center" font-weight="500" padding="0px" font-size="18px" color="green">No incidents this week!</mj-text>
<mj-divider border-width="2px" border-color="#616161"></mj-divider>
<mj-column
width="45%"
padding-top="20px"
>
<mj-text
align="center"
font-weight="500"
padding="0px"
font-size="18px"
color="green"
>No incidents this week!</mj-text
>
<mj-divider
border-width="2px"
border-color="#616161"
></mj-divider>
</mj-column>
</mj-section>
<mj-section>
@@ -28,7 +53,10 @@
</mj-text>
</mj-column>
<mj-column width="100%">
<mj-divider border-width="1px" border-color="#E0E0E0"></mj-divider>
<mj-divider
border-width="1px"
border-color="#E0E0E0"
></mj-divider>
<mj-text font-size="12px">
<p>This email was sent by BlueWave Uptime.</p>
</mj-text>
+20 -7
View File
@@ -2,17 +2,28 @@
<mjml>
<mj-head>
<mj-font name="Roboto" href="https://fonts.googleapis.com/css?family=Roboto:300,500"></mj-font>
<mj-font
name="Roboto"
href="https://fonts.googleapis.com/css?family=Roboto:300,500"
></mj-font>
<mj-attributes>
<mj-all font-family="Roboto, Helvetica, sans-serif"></mj-all>
<mj-text font-weight="300" font-size="16px" color="#616161" line-height="24px"></mj-text>
<mj-text
font-weight="300"
font-size="16px"
color="#616161"
line-height="24px"
></mj-text>
<mj-section padding="0px"></mj-section>
</mj-attributes>
</mj-head>
<mj-body>
<mj-section padding="20px 0">
<mj-column width="100%">
<mj-text align="left" font-size="10px">
<mj-text
align="left"
font-size="10px"
>
Message from BlueWave Uptime Service
</mj-text>
</mj-column>
@@ -22,9 +33,8 @@
<mj-text>
<p>Hello {{name}}!</p>
<p>
You are receiving this email because a password reset request
has been made for {{email}}. Please use the
link below on the site to reset your password.
You are receiving this email because a password reset request has been made
for {{email}}. Please use the link below on the site to reset your password.
</p>
<a href="{{url}}">Reset Password</a>
<p>If you didn't request this, please ignore this email.</p>
@@ -33,7 +43,10 @@
</mj-text>
</mj-column>
<mj-column width="100%">
<mj-divider border-width="1px" border-color="#E0E0E0"></mj-divider>
<mj-divider
border-width="1px"
border-color="#E0E0E0"
></mj-divider>
<mj-text font-size="12px">
<p>This email was sent by BlueWave Uptime.</p>
</mj-text>
+40 -24
View File
@@ -1,24 +1,47 @@
<mjml>
<mj-head>
<mj-font name="Roboto" href="https://fonts.googleapis.com/css?family=Roboto:300,500"></mj-font>
<mj-font
name="Roboto"
href="https://fonts.googleapis.com/css?family=Roboto:300,500"
></mj-font>
<mj-attributes>
<mj-all font-family="Roboto, Helvetica, sans-serif"></mj-all>
<mj-text font-weight="300" font-size="16px" color="#616161" line-height="24px"></mj-text>
<mj-text
font-weight="300"
font-size="16px"
color="#616161"
line-height="24px"
></mj-text>
<mj-section padding="0px"></mj-section>
</mj-attributes>
</mj-head>
<mj-body>
<mj-section padding="20px 0">
<mj-column width="100%">
<mj-text align="left" font-size="10px">
<mj-text
align="left"
font-size="10px"
>
Message from BlueWave Uptime Service
</mj-text>
</mj-column>
<mj-column width="45%" padding-top="20px">
<mj-text align="center" font-weight="500" padding="0px" font-size="18px" color="red">
<mj-column
width="45%"
padding-top="20px"
>
<mj-text
align="center"
font-weight="500"
padding="0px"
font-size="18px"
color="red"
>
Google.com is down
</mj-text>
<mj-divider border-width="2px" border-color="#616161"></mj-divider>
<mj-divider
border-width="2px"
border-color="#616161"
></mj-divider>
</mj-column>
</mj-section>
<mj-section>
@@ -26,28 +49,21 @@
<mj-text>
<p>Hello {{name}}!</p>
<p>
We detected an incident on one of your monitors. Your service is
currently down. We'll send a message to you once it is up again.
</p>
<p>
<b>Monitor name:</b> {{monitor}}
</p>
<p>
<b>URL:</b> {{url}}
</p>
<p>
<b>Problem:</b> {{problem}}
</p>
<p>
<b>Start date:</b> {{startDate}}
We detected an incident on one of your monitors. Your service is currently
down. We'll send a message to you once it is up again.
</p>
<p><b>Monitor name:</b> {{monitor}}</p>
<p><b>URL:</b> {{url}}</p>
<p><b>Problem:</b> {{problem}}</p>
<p><b>Start date:</b> {{startDate}}</p>
</mj-text>
</mj-column>
<mj-column width="100%">
<mj-divider border-width="1px" border-color="#E0E0E0"></mj-divider>
<mj-button background-color="#1570EF">
View incident details
</mj-button>
<mj-divider
border-width="1px"
border-color="#E0E0E0"
></mj-divider>
<mj-button background-color="#1570EF"> View incident details </mj-button>
<mj-text font-size="12px">
<p>This email was sent by BlueWave Uptime.</p>
</mj-text>
+41 -32
View File
@@ -1,59 +1,68 @@
<mjml>
<mj-head>
<mj-font name="Roboto" href="https://fonts.googleapis.com/css?family=Roboto:300,500"></mj-font>
<mj-font
name="Roboto"
href="https://fonts.googleapis.com/css?family=Roboto:300,500"
></mj-font>
<mj-attributes>
<mj-all font-family="Roboto, Helvetica, sans-serif"></mj-all>
<mj-text font-weight="300" font-size="16px" color="#616161" line-height="24px"></mj-text>
<mj-text
font-weight="300"
font-size="16px"
color="#616161"
line-height="24px"
></mj-text>
<mj-section padding="0px"></mj-section>
</mj-attributes>
</mj-head>
<mj-body>
<mj-section padding="20px 0">
<mj-column width="100%">
<mj-text align="left" font-size="10px">
<mj-text
align="left"
font-size="10px"
>
Message from BlueWave Uptime Service
</mj-text>
</mj-column>
<mj-column width="45%" padding-top="20px">
<mj-text align="center" font-weight="500" padding="0px" font-size="18px" color="green">
<mj-column
width="45%"
padding-top="20px"
>
<mj-text
align="center"
font-weight="500"
padding="0px"
font-size="18px"
color="green"
>
{{monitor}} is up
</mj-text>
<mj-divider border-width="2px" border-color="#616161"></mj-divider>
<mj-divider
border-width="2px"
border-color="#616161"
></mj-divider>
</mj-column>
</mj-section>
<mj-section>
<mj-column width="100%">
<mj-text>
<p>Hello {{name}}!</p>
<p>
Your latest incident is resolved and your monitored service is
up again.
</p>
<p>
<b>Monitor name:</b> {{monitor}}
</p>
<p>
<b>URL:</b> {{url}}
</p>
<p>
<b>Problem:</b> {{problem}}
</p>
<p>
<b>Start date:</b> {{startDate}}
</p>
<p>
<b>Resolved date:</b> {{resolvedDate}}
</p>
<p>
<b>Duration:</b>{{duration}}
</p>
<p>Your latest incident is resolved and your monitored service is up again.</p>
<p><b>Monitor name:</b> {{monitor}}</p>
<p><b>URL:</b> {{url}}</p>
<p><b>Problem:</b> {{problem}}</p>
<p><b>Start date:</b> {{startDate}}</p>
<p><b>Resolved date:</b> {{resolvedDate}}</p>
<p><b>Duration:</b>{{duration}}</p>
</mj-text>
</mj-column>
<mj-column width="100%">
<mj-divider border-width="1px" border-color="#E0E0E0"></mj-divider>
<mj-button background-color="#1570EF">
View incident details
</mj-button>
<mj-divider
border-width="1px"
border-color="#E0E0E0"
></mj-divider>
<mj-button background-color="#1570EF"> View incident details </mj-button>
<mj-text font-size="12px">
<p>This email was sent by BlueWave Uptime.</p>
</mj-text>
+22 -9
View File
@@ -1,17 +1,28 @@
<!-- name -->
<mjml>
<mj-head>
<mj-font name="Roboto" href="https://fonts.googleapis.com/css?family=Roboto:300,500"></mj-font>
<mj-font
name="Roboto"
href="https://fonts.googleapis.com/css?family=Roboto:300,500"
></mj-font>
<mj-attributes>
<mj-all font-family="Roboto, Helvetica, sans-serif"></mj-all>
<mj-text font-weight="300" font-size="16px" color="#616161" line-height="24px"></mj-text>
<mj-text
font-weight="300"
font-size="16px"
color="#616161"
line-height="24px"
></mj-text>
<mj-section padding="0px"></mj-section>
</mj-attributes>
</mj-head>
<mj-body>
<mj-section padding="20px 0">
<mj-column width="100%">
<mj-text align="left" font-size="10px">
<mj-text
align="left"
font-size="10px"
>
Message from BlueWave Uptime Service
</mj-text>
</mj-column>
@@ -21,20 +32,22 @@
<mj-text>
<p>Hello {{name}}!</p>
<p>
Thank you for trying out BlueWave Uptime! We developed it with
great care to meet our own needs, and we're excited to share it
with you.
Thank you for trying out BlueWave Uptime! We developed it with great care to
meet our own needs, and we're excited to share it with you.
</p>
<p>
BlueWave Uptime is an automated way of checking whether a
service such as a website or an application is available or not.
BlueWave Uptime is an automated way of checking whether a service such as a
website or an application is available or not.
</p>
<p>We hope you find our service as valuable as we do.</p>
<p>Thank you.</p>
</mj-text>
</mj-column>
<mj-column width="100%">
<mj-divider border-width="1px" border-color="#E0E0E0"></mj-divider>
<mj-divider
border-width="1px"
border-color="#E0E0E0"
></mj-divider>
<mj-text font-size="12px">
<p>This email was sent by BlueWave Uptime.</p>
</mj-text>
@@ -280,8 +280,7 @@ describe("Check Controller - deleteChecksByTeamId", () => {
req.params = { teamId: "1" };
req.db.deleteChecksByTeamId.rejects(new Error("Deletion Error"));
await deleteChecksByTeamId(req, res, next);
expect(req.db.deleteChecksByTeamId.calledOnceWith(req.params.teamId)).to.be
.true;
expect(req.db.deleteChecksByTeamId.calledOnceWith(req.params.teamId)).to.be.true;
expect(next.firstCall.args[0]).to.be.an("error");
expect(res.status.notCalled).to.be.true;
expect(res.json.notCalled).to.be.true;
@@ -291,8 +290,7 @@ describe("Check Controller - deleteChecksByTeamId", () => {
req.params = { teamId: "123" };
req.db.deleteChecksByTeamId.resolves(1);
await deleteChecksByTeamId(req, res, next);
expect(req.db.deleteChecksByTeamId.calledOnceWith(req.params.teamId)).to.be
.true;
expect(req.db.deleteChecksByTeamId.calledOnceWith(req.params.teamId)).to.be.true;
expect(res.status.calledOnceWith(200)).to.be.true;
expect(
res.json.calledOnceWith({
@@ -270,11 +270,7 @@ describe("maintenanceWindowController - getMaintenanceWindowsByMonitorId", () =>
const data = [{ monitorId: "123" }];
req.db.getMaintenanceWindowsByMonitorId.returns(data);
await getMaintenanceWindowsByMonitorId(req, res, next);
expect(
req.db.getMaintenanceWindowsByMonitorId.calledOnceWith(
req.params.monitorId
)
);
expect(req.db.getMaintenanceWindowsByMonitorId.calledOnceWith(req.params.monitorId));
expect(res.status.firstCall.args[0]).to.equal(200);
expect(
res.json.calledOnceWith({
@@ -401,9 +397,7 @@ describe("maintenanceWindowController - editMaintenanceWindow", () => {
req.db.editMaintenanceWindowById.returns(data);
await editMaintenanceWindow(req, res, next);
expect(
req.db.editMaintenanceWindowById.calledOnceWith(req.params.id, req.body)
);
expect(req.db.editMaintenanceWindowById.calledOnceWith(req.params.id, req.body));
expect(res.status.firstCall.args[0]).to.equal(200);
expect(
res.json.calledOnceWith({
@@ -84,9 +84,7 @@ describe("Settings Controller - updateAppSettings", () => {
expect(next.firstCall.args[0].message).to.equal("updateAppSettings error");
});
it("should reject with an error if reloadSettings throws an error", async () => {
req.settingsService.reloadSettings.throws(
new Error("reloadSettings error")
);
req.settingsService.reloadSettings.throws(new Error("reloadSettings error"));
await updateAppSettings(req, res, next);
expect(next.firstCall.args[0]).to.be.an("error");
expect(next.firstCall.args[0].message).to.equal("reloadSettings error");
+2 -6
View File
@@ -5,10 +5,7 @@ const calculatePercentile = (arr, percentile) => {
const upper = lower + 1;
const weight = index % 1;
if (upper >= sorted.length) return sorted[lower].responseTime;
return (
sorted[lower].responseTime * (1 - weight) +
sorted[upper].responseTime * weight
);
return sorted[lower].responseTime * (1 - weight) + sorted[upper].responseTime * weight;
};
const NormalizeData = (checks, rangeMin, rangeMax) => {
@@ -21,8 +18,7 @@ const NormalizeData = (checks, rangeMin, rangeMax) => {
const originalResponseTime = check.responseTime;
// Normalize the response time between 1 and 100
let normalizedResponseTime =
rangeMin +
((check.responseTime - min) * (rangeMax - rangeMin)) / (max - min);
rangeMin + ((check.responseTime - min) * (rangeMax - rangeMin)) / (max - min);
// Put a floor on the response times so we don't have extreme outliers
// Better visuals
+1 -4
View File
@@ -13,10 +13,7 @@ import winston from "winston";
*/
const logger = winston.createLogger({
level: "info",
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: "app.log" }),
+4 -8
View File
@@ -25,12 +25,9 @@ const errorMessages = {
DB_USER_EXISTS: "User already exists",
DB_USER_NOT_FOUND: "User not found",
DB_TOKEN_NOT_FOUND: "Token not found",
DB_RESET_PASSWORD_BAD_MATCH:
"New password must be different from old password",
DB_FIND_MONITOR_BY_ID: (monitorId) =>
`Monitor with id ${monitorId} not found`,
DB_DELETE_CHECKS: (monitorId) =>
`No checks found for monitor with id ${monitorId}`,
DB_RESET_PASSWORD_BAD_MATCH: "New password must be different from old password",
DB_FIND_MONITOR_BY_ID: (monitorId) => `Monitor with id ${monitorId} not found`,
DB_DELETE_CHECKS: (monitorId) => `No checks found for monitor with id ${monitorId}`,
//Auth errors
AUTH_INCORRECT_PASSWORD: "Incorrect password",
@@ -101,8 +98,7 @@ const successMessages = {
//Maintenance Window Controller
MAINTENANCE_WINDOW_GET_BY_ID: "Got Maintenance Window by Id successfully",
MAINTENANCE_WINDOW_CREATE: "Maintenance Window created successfully",
MAINTENANCE_WINDOW_GET_BY_TEAM:
"Got Maintenance Windows by Team successfully",
MAINTENANCE_WINDOW_GET_BY_TEAM: "Got Maintenance Windows by Team successfully",
MAINTENANCE_WINDOW_DELETE: "Maintenance Window deleted successfully",
MAINTENANCE_WINDOW_EDIT: "Maintenance Window edited successfully",