mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-04 15:39:35 -05:00
update queries to return consistent values
This commit is contained in:
@@ -123,8 +123,12 @@ const getChecksByMonitor = async (req) => {
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
checksCount: { $arrayElemAt: ["$summary.checksCount", 0] },
|
||||
checks: "$checks",
|
||||
checksCount: {
|
||||
$ifNull: [{ $arrayElemAt: ["$summary.checksCount", 0] }, 0],
|
||||
},
|
||||
checks: {
|
||||
$ifNull: ["$checks", []],
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -340,6 +340,7 @@ const getUptimeDetailsById = async (req) => {
|
||||
};
|
||||
|
||||
const dateString = formatLookup[dateRange];
|
||||
|
||||
const results = await Check.aggregate(
|
||||
buildUptimeDetailsPipeline(monitor, dates, dateString)
|
||||
);
|
||||
|
||||
@@ -218,18 +218,20 @@ const buildUptimeDetailsPipeline = (monitor, dates, dateString) => {
|
||||
{
|
||||
$project: {
|
||||
uptimeStreak: {
|
||||
$cond: [
|
||||
{ $eq: [{ $size: { $first: "$uptimeStreak.streak.checks" } }, 0] },
|
||||
0,
|
||||
{
|
||||
$subtract: [
|
||||
new Date(),
|
||||
$let: {
|
||||
vars: {
|
||||
checks: { $ifNull: [{ $first: "$uptimeStreak.streak.checks" }, []] },
|
||||
},
|
||||
in: {
|
||||
$cond: [
|
||||
{ $eq: [{ $size: "$$checks" }, 0] },
|
||||
0,
|
||||
{
|
||||
$last: { $first: "$uptimeStreak.streak.checks.createdAt" },
|
||||
$subtract: [new Date(), { $last: "$$checks.createdAt" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
avgResponseTime: {
|
||||
$arrayElemAt: ["$aggregateData.avgResponseTime", 0],
|
||||
|
||||
Reference in New Issue
Block a user