Skip to content

Commit a641c03

Browse files
authored
Merge pull request #1672 from bluewave-labs/fix/be/consistent-returns
update queries to return consistent values
2 parents abd0006 + 22b2040 commit a641c03

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Server/db/mongo/modules/checkModule.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ const getChecksByMonitor = async (req) => {
123123
},
124124
{
125125
$project: {
126-
checksCount: { $arrayElemAt: ["$summary.checksCount", 0] },
127-
checks: "$checks",
126+
checksCount: {
127+
$ifNull: [{ $arrayElemAt: ["$summary.checksCount", 0] }, 0],
128+
},
129+
checks: {
130+
$ifNull: ["$checks", []],
131+
},
128132
},
129133
},
130134
]);

Server/db/mongo/modules/monitorModule.js

+1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ const getUptimeDetailsById = async (req) => {
340340
};
341341

342342
const dateString = formatLookup[dateRange];
343+
343344
const results = await Check.aggregate(
344345
buildUptimeDetailsPipeline(monitor, dates, dateString)
345346
);

Server/db/mongo/modules/monitorModuleQueries.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,20 @@ const buildUptimeDetailsPipeline = (monitor, dates, dateString) => {
218218
{
219219
$project: {
220220
uptimeStreak: {
221-
$cond: [
222-
{ $eq: [{ $size: { $first: "$uptimeStreak.streak.checks" } }, 0] },
223-
0,
224-
{
225-
$subtract: [
226-
new Date(),
221+
$let: {
222+
vars: {
223+
checks: { $ifNull: [{ $first: "$uptimeStreak.streak.checks" }, []] },
224+
},
225+
in: {
226+
$cond: [
227+
{ $eq: [{ $size: "$$checks" }, 0] },
228+
0,
227229
{
228-
$last: { $first: "$uptimeStreak.streak.checks.createdAt" },
230+
$subtract: [new Date(), { $last: "$$checks.createdAt" }],
229231
},
230232
],
231233
},
232-
],
234+
},
233235
},
234236
avgResponseTime: {
235237
$arrayElemAt: ["$aggregateData.avgResponseTime", 0],

0 commit comments

Comments
 (0)