Merge pull request #978 from bluewave-labs/fix/be/prettier-baseline

Format all files on BE with perttier config
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-10-18 10:03:18 +08:00
commit df74aba6ca
27 files changed
+229 -237

No files matched your search

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