mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-18 07:28:31 -05:00
Merge branch 'develop' into 1067-fe-hardware-monitoring-create-hardware-monitor
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Monitor from "../../models/Monitor.js";
|
||||
import Check from "../../models/Check.js";
|
||||
import PageSpeedCheck from "../../models/PageSpeedCheck.js";
|
||||
import HardwareCheck from "../../models/HardwareCheck.js";
|
||||
import { errorMessages } from "../../../utils/messages.js";
|
||||
import Notification from "../../models/Notification.js";
|
||||
import { NormalizeData } from "../../../utils/dataUtils.js";
|
||||
@@ -16,6 +17,13 @@ const demoMonitors = JSON.parse(fs.readFileSync(demoMonitorsPath, "utf8"));
|
||||
|
||||
const SERVICE_NAME = "monitorModule";
|
||||
|
||||
const CHECK_MODEL_LOOKUP = {
|
||||
http: Check,
|
||||
ping: Check,
|
||||
pageSpeed: PageSpeedCheck,
|
||||
hardware: HardwareCheck,
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all monitors
|
||||
* @async
|
||||
@@ -163,8 +171,7 @@ const getMonitorStatsById = async (req) => {
|
||||
// Default sort order is newest -> oldest
|
||||
sortOrder = sortOrder === "asc" ? 1 : -1;
|
||||
|
||||
let model =
|
||||
monitor.type === "http" || monitor.type === "ping" ? Check : PageSpeedCheck;
|
||||
let model = CHECK_MODEL_LOOKUP[monitor.type];
|
||||
|
||||
const monitorStats = {
|
||||
...monitor.toObject(),
|
||||
@@ -325,13 +332,9 @@ const getMonitorsAndSummaryByTeamId = async (teamId, type) => {
|
||||
(acc, monitor) => {
|
||||
if (monitor.status === true) {
|
||||
acc.up += 1;
|
||||
}
|
||||
|
||||
if (monitor.status === false) {
|
||||
} else if (monitor.status === false) {
|
||||
acc.down += 1;
|
||||
}
|
||||
|
||||
if (monitor.isActive === false) {
|
||||
} else if (monitor.isActive === false) {
|
||||
acc.paused += 1;
|
||||
}
|
||||
return acc;
|
||||
@@ -397,8 +400,6 @@ const getMonitorsByTeamId = async (req, res) => {
|
||||
// Default sort order is newest -> oldest
|
||||
if (checkOrder === "asc") {
|
||||
checkOrder = 1;
|
||||
} else if (checkOrder === "desc") {
|
||||
checkOrder = -1;
|
||||
} else checkOrder = -1;
|
||||
|
||||
// Sort order for monitors
|
||||
@@ -428,8 +429,7 @@ const getMonitorsByTeamId = async (req, res) => {
|
||||
checksQuery.status = status;
|
||||
}
|
||||
|
||||
let model =
|
||||
monitor.type === "http" || monitor.type === "ping" ? Check : PageSpeedCheck;
|
||||
let model = CHECK_MODEL_LOOKUP[monitor.type];
|
||||
|
||||
// Checks are order newest -> oldest
|
||||
let checks = await model
|
||||
|
||||
@@ -56,25 +56,25 @@ const resetPassword = async (req, res) => {
|
||||
const recoveryToken = await validateRecoveryToken(req, res);
|
||||
const user = await UserModel.findOne({ email: recoveryToken.email });
|
||||
|
||||
if (user === null) {
|
||||
throw new Error(errorMessages.DB_USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
const match = await user.comparePassword(newPassword);
|
||||
if (match === true) {
|
||||
throw new Error(errorMessages.DB_RESET_PASSWORD_BAD_MATCH);
|
||||
}
|
||||
|
||||
if (user !== null) {
|
||||
user.password = newPassword;
|
||||
await user.save();
|
||||
await RecoveryToken.deleteMany({ email: recoveryToken.email });
|
||||
// Fetch the user again without the password
|
||||
const userWithoutPassword = await UserModel.findOne({
|
||||
email: recoveryToken.email,
|
||||
})
|
||||
.select("-password")
|
||||
.select("-profileImage");
|
||||
return userWithoutPassword;
|
||||
} else {
|
||||
throw new Error(errorMessages.DB_USER_NOT_FOUND);
|
||||
}
|
||||
user.password = newPassword;
|
||||
await user.save();
|
||||
await RecoveryToken.deleteMany({ email: recoveryToken.email });
|
||||
// Fetch the user again without the password
|
||||
const userWithoutPassword = await UserModel.findOne({
|
||||
email: recoveryToken.email,
|
||||
})
|
||||
.select("-password")
|
||||
.select("-profileImage");
|
||||
return userWithoutPassword;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "resetPassword";
|
||||
|
||||
@@ -70,11 +70,10 @@ const getUserByEmail = async (email) => {
|
||||
// Need the password to be able to compare, removed .select()
|
||||
// We can strip the hash before returning the user
|
||||
const user = await UserModel.findOne({ email: email }).select("-profileImage");
|
||||
if (user) {
|
||||
return user;
|
||||
} else {
|
||||
if (!user) {
|
||||
throw new Error(errorMessages.DB_USER_NOT_FOUND);
|
||||
}
|
||||
return user;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getUserByEmail";
|
||||
|
||||
Generated
+9
-8
@@ -12,7 +12,7 @@
|
||||
"@sendgrid/mail": "^8.1.3",
|
||||
"axios": "^1.7.2",
|
||||
"bcrypt": "^5.1.1",
|
||||
"bullmq": "5.23.0",
|
||||
"bullmq": "5.25.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.19.2",
|
||||
@@ -1164,14 +1164,14 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/bullmq": {
|
||||
"version": "5.23.0",
|
||||
"resolved": "https://registry.npmjs.org/bullmq/-/bullmq-5.23.0.tgz",
|
||||
"integrity": "sha512-VILKTIOwo9AopMyVqvDhQ1qyLrOtBSfu+G2bntgauQfxYzT7ETj+h2HeUe7a9i9AU/+OXJGYYm49NHJedEz7VQ==",
|
||||
"version": "5.25.0",
|
||||
"resolved": "https://registry.npmjs.org/bullmq/-/bullmq-5.25.0.tgz",
|
||||
"integrity": "sha512-QBbtabDUgdztalbYbrCc5NFwrRUKOZyiAkVFPhdrBGFsdraPq5SrXx6WP7U1stKj3hYYp1IuW+n3wuksYGITvw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cron-parser": "^4.6.0",
|
||||
"ioredis": "^5.4.1",
|
||||
"msgpackr": "^1.10.1",
|
||||
"msgpackr": "^1.11.2",
|
||||
"node-abort-controller": "^3.1.1",
|
||||
"semver": "^7.5.4",
|
||||
"tslib": "^2.0.0",
|
||||
@@ -4443,9 +4443,10 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/msgpackr": {
|
||||
"version": "1.10.2",
|
||||
"resolved": "https://registry.npmjs.org/msgpackr/-/msgpackr-1.10.2.tgz",
|
||||
"integrity": "sha512-L60rsPynBvNE+8BWipKKZ9jHcSGbtyJYIwjRq0VrIvQ08cRjntGXJYW/tmciZ2IHWIY8WEW32Qa2xbh5+SKBZA==",
|
||||
"version": "1.11.2",
|
||||
"resolved": "https://registry.npmjs.org/msgpackr/-/msgpackr-1.11.2.tgz",
|
||||
"integrity": "sha512-F9UngXRlPyWCDEASDpTf6c9uNhGPTqnTeLVt7bN+bU1eajoR/8V9ys2BRaV5C/e5ihE6sJ9uPIKaYt6bFuO32g==",
|
||||
"license": "MIT",
|
||||
"optionalDependencies": {
|
||||
"msgpackr-extract": "^3.0.2"
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
"@sendgrid/mail": "^8.1.3",
|
||||
"axios": "^1.7.2",
|
||||
"bcrypt": "^5.1.1",
|
||||
"bullmq": "5.23.0",
|
||||
"bullmq": "5.25.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.19.2",
|
||||
|
||||
Reference in New Issue
Block a user