Moved normalization to BE
This commit is contained in:
1 parent
7928bd7822
commit
51058b6d2b
8 files changed
+28
-18
No files matched your search
@@ -3,6 +3,7 @@ const Check = require("../../../models/Check");
|
||||
const PageSpeedCheck = require("../../../models/PageSpeedCheck");
|
||||
const { errorMessages } = require("../../../utils/messages");
|
||||
const Notification = require("../../../models/Notification");
|
||||
const { NormalizeData } = require("../../../utils/dataUtils");
|
||||
|
||||
/**
|
||||
* Get all monitors
|
||||
@@ -32,7 +33,8 @@ const getAllMonitors = async (req, res) => {
|
||||
const getMonitorById = async (req, res) => {
|
||||
try {
|
||||
const { monitorId } = req.params;
|
||||
let { status, limit, sortOrder, filter, numToDisplay } = req.query;
|
||||
let { status, limit, sortOrder, filter, numToDisplay, normalize } =
|
||||
req.query;
|
||||
|
||||
const filterLookup = {
|
||||
day: new Date(new Date().setDate(new Date().getDate() - 1)),
|
||||
@@ -82,6 +84,11 @@ const getMonitorById = async (req, res) => {
|
||||
checks = checks.filter((_, index) => index % n === 0);
|
||||
}
|
||||
|
||||
// Normalize checks if requested
|
||||
if (normalize) {
|
||||
checks = NormalizeData(checks, 10, 100);
|
||||
}
|
||||
|
||||
const notifications = await Notification.find({ monitorId: monitor._id });
|
||||
const monitorWithChecks = { ...monitor.toObject(), checks, notifications };
|
||||
return monitorWithChecks;
|
||||
@@ -100,7 +107,7 @@ const getMonitorById = async (req, res) => {
|
||||
*/
|
||||
const getMonitorsByUserId = async (req, res) => {
|
||||
try {
|
||||
let { limit, type, status, sortOrder } = req.query;
|
||||
let { limit, type, status, sortOrder, normalize } = req.query;
|
||||
const monitorQuery = { userId: req.params.userId };
|
||||
|
||||
if (type !== undefined) {
|
||||
@@ -133,13 +140,18 @@ const getMonitorsByUserId = async (req, res) => {
|
||||
: PageSpeedCheck;
|
||||
|
||||
// Checks are order newest -> oldest
|
||||
const checks = await model
|
||||
let checks = await model
|
||||
.find(checksQuery)
|
||||
.sort({
|
||||
createdAt: sortOrder,
|
||||
})
|
||||
.limit(limit);
|
||||
|
||||
//Normalize checks if requested
|
||||
if (normalize === true) {
|
||||
checks = NormalizeData(checks, 10, 100);
|
||||
}
|
||||
|
||||
// Get notifications
|
||||
const notifications = await Notification.find({
|
||||
monitorId: monitor._id,
|
||||
|
||||
Reference in new issue
Block a user