ommit checks from query if limit is null
This commit is contained in:
1 parent
e8aecb4041
commit
ef23648941
1 file changed
+55
-40
@@ -508,7 +508,6 @@ const getMonitorById = async (monitorId) => {
|
|||||||
const getMonitorsByTeamId = async (req) => {
|
const getMonitorsByTeamId = async (req) => {
|
||||||
let { limit, type, page, rowsPerPage, filter, field, order } = req.query;
|
let { limit, type, page, rowsPerPage, filter, field, order } = req.query;
|
||||||
|
|
||||||
// Parse ints
|
|
||||||
limit = parseInt(limit);
|
limit = parseInt(limit);
|
||||||
page = parseInt(page);
|
page = parseInt(page);
|
||||||
rowsPerPage = parseInt(rowsPerPage);
|
rowsPerPage = parseInt(rowsPerPage);
|
||||||
@@ -571,54 +570,67 @@ const getMonitorsByTeamId = async (req) => {
|
|||||||
{ $sort: sort },
|
{ $sort: sort },
|
||||||
{ $skip: skip },
|
{ $skip: skip },
|
||||||
...(rowsPerPage ? [{ $limit: rowsPerPage }] : []),
|
...(rowsPerPage ? [{ $limit: rowsPerPage }] : []),
|
||||||
{
|
...(limit
|
||||||
$lookup: {
|
? [
|
||||||
from: "checks",
|
|
||||||
let: { monitorId: "$_id" },
|
|
||||||
pipeline: [
|
|
||||||
{
|
{
|
||||||
$match: {
|
$lookup: {
|
||||||
$expr: { $eq: ["$monitorId", "$$monitorId"] },
|
from: "checks",
|
||||||
|
let: { monitorId: "$_id" },
|
||||||
|
pipeline: [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
$expr: { $eq: ["$monitorId", "$$monitorId"] },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ $sort: { createdAt: -1 } },
|
||||||
|
...(limit ? [{ $limit: limit }] : []),
|
||||||
|
],
|
||||||
|
as: "standardchecks",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ $sort: { createdAt: -1 } },
|
]
|
||||||
...(limit ? [{ $limit: limit }] : []),
|
: []),
|
||||||
],
|
...(limit
|
||||||
as: "standardchecks",
|
? [
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: "pagespeedchecks",
|
|
||||||
let: { monitorId: "$_id" },
|
|
||||||
pipeline: [
|
|
||||||
{
|
{
|
||||||
$match: {
|
$lookup: {
|
||||||
$expr: { $eq: ["$monitorId", "$$monitorId"] },
|
from: "pagespeedchecks",
|
||||||
|
let: { monitorId: "$_id" },
|
||||||
|
pipeline: [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
$expr: { $eq: ["$monitorId", "$$monitorId"] },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ $sort: { createdAt: -1 } },
|
||||||
|
...(limit ? [{ $limit: limit }] : []),
|
||||||
|
],
|
||||||
|
as: "pagespeedchecks",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ $sort: { createdAt: -1 } },
|
]
|
||||||
...(limit ? [{ $limit: limit }] : []),
|
: []),
|
||||||
],
|
...(limit
|
||||||
as: "pagespeedchecks",
|
? [
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: "hardwarechecks",
|
|
||||||
let: { monitorId: "$_id" },
|
|
||||||
pipeline: [
|
|
||||||
{
|
{
|
||||||
$match: {
|
$lookup: {
|
||||||
$expr: { $eq: ["$monitorId", "$$monitorId"] },
|
from: "hardwarechecks",
|
||||||
|
let: { monitorId: "$_id" },
|
||||||
|
pipeline: [
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
$expr: { $eq: ["$monitorId", "$$monitorId"] },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ $sort: { createdAt: -1 } },
|
||||||
|
...(limit ? [{ $limit: limit }] : []),
|
||||||
|
],
|
||||||
|
as: "hardwarechecks",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ $sort: { createdAt: -1 } },
|
]
|
||||||
...(limit ? [{ $limit: limit }] : []),
|
: []),
|
||||||
],
|
|
||||||
as: "hardwarechecks",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
$addFields: {
|
$addFields: {
|
||||||
checks: {
|
checks: {
|
||||||
@@ -662,6 +674,9 @@ const getMonitorsByTeamId = async (req) => {
|
|||||||
|
|
||||||
let { monitors, summary } = results[0];
|
let { monitors, summary } = results[0];
|
||||||
monitors = monitors.map((monitor) => {
|
monitors = monitors.map((monitor) => {
|
||||||
|
if (!monitor.checks) {
|
||||||
|
return monitor;
|
||||||
|
}
|
||||||
monitor.checks = NormalizeData(monitor.checks, 10, 100);
|
monitor.checks = NormalizeData(monitor.checks, 10, 100);
|
||||||
return monitor;
|
return monitor;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user