conditionally add status to the match stage of the aggreagation pipeline

This commit is contained in:
Alex Holliday
2025-01-27 09:37:29 -08:00
parent c7c9835e9c
commit cb624f1f29
+3 -3
View File
@@ -70,13 +70,14 @@ const createCheck = async (checkData) => {
const getChecksByMonitor = async (req) => {
try {
const { monitorId } = req.params;
let { sortOrder, dateRange, filter, page, rowsPerPage } = req.query;
let { sortOrder, dateRange, filter, page, rowsPerPage, status } = req.query;
status = typeof status !== "undefined" ? false : undefined;
page = parseInt(page);
rowsPerPage = parseInt(rowsPerPage);
// Match
const matchStage = {
monitorId: ObjectId.createFromHexString(monitorId),
status: false,
...(typeof status !== "undefined" && { status }),
...(dateRangeLookup[dateRange] && {
createdAt: {
$gte: dateRangeLookup[dateRange],
@@ -111,7 +112,6 @@ const getChecksByMonitor = async (req) => {
if (page && rowsPerPage) {
skip = page * rowsPerPage;
}
const checks = await Check.aggregate([
{ $match: matchStage },
{ $sort: { createdAt: sortOrder } },