Add filtering to check count
This commit is contained in:
1 parent
d95fcb119d
commit
21ba8f087a
1 file changed
+9
-3
@@ -31,13 +31,20 @@ const createCheck = async (checkData) => {
|
|||||||
|
|
||||||
const getChecksCount = async (req) => {
|
const getChecksCount = async (req) => {
|
||||||
const monitorId = req.params.monitorId;
|
const monitorId = req.params.monitorId;
|
||||||
|
const dateRange = req.query.dateRange;
|
||||||
const filter = req.query.filter;
|
const filter = req.query.filter;
|
||||||
|
console.log(filter);
|
||||||
// Build query
|
// Build query
|
||||||
const checksQuery = { monitorId: monitorId };
|
const checksQuery = { monitorId: monitorId };
|
||||||
// Filter checks by "day", "week", or "month"
|
// Filter checks by "day", "week", or "month"
|
||||||
if (filter !== undefined) {
|
if (dateRange !== undefined) {
|
||||||
checksQuery.createdAt = { $gte: dateRangeLookup[filter] };
|
checksQuery.createdAt = { $gte: dateRangeLookup[dateRange] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filter !== undefined) {
|
||||||
|
checksQuery.status = false;
|
||||||
|
}
|
||||||
|
|
||||||
const count = await Check.countDocuments(checksQuery);
|
const count = await Check.countDocuments(checksQuery);
|
||||||
return count;
|
return count;
|
||||||
};
|
};
|
||||||
@@ -54,7 +61,6 @@ const getChecks = async (req) => {
|
|||||||
try {
|
try {
|
||||||
const { monitorId } = req.params;
|
const { monitorId } = req.params;
|
||||||
let { sortOrder, limit, dateRange, filter, page, rowsPerPage } = req.query;
|
let { sortOrder, limit, dateRange, filter, page, rowsPerPage } = req.query;
|
||||||
console.log(filter);
|
|
||||||
// Default limit to 0 if not provided
|
// Default limit to 0 if not provided
|
||||||
if (limit === undefined) limit = 0;
|
if (limit === undefined) limit = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user