mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-20 08:28:48 -05:00
date limit
This commit is contained in:
@@ -334,10 +334,13 @@ class MongoChecksRepository implements IChecksRepository {
|
||||
return {};
|
||||
}
|
||||
const limitPerMonitor = options?.limitPerMonitor ?? 25;
|
||||
|
||||
const dateFilter = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
const results = await Promise.all(
|
||||
monitorIds.map(async (monitorId) => {
|
||||
const docs = await CheckModel.find({ "metadata.monitorId": new mongoose.Types.ObjectId(monitorId) })
|
||||
const docs = await CheckModel.find({
|
||||
"metadata.monitorId": new mongoose.Types.ObjectId(monitorId),
|
||||
createdAt: { $gte: dateFilter },
|
||||
})
|
||||
.sort({ createdAt: -1 })
|
||||
.limit(limitPerMonitor)
|
||||
.lean();
|
||||
@@ -345,10 +348,11 @@ class MongoChecksRepository implements IChecksRepository {
|
||||
})
|
||||
);
|
||||
|
||||
return results.reduce<LatestChecksMap>((acc, { monitorId, docs }) => {
|
||||
acc[monitorId] = docs.map((doc) => this.toEntity(doc as CheckDocument));
|
||||
const mapped = results.reduce<LatestChecksMap>((acc, { monitorId, docs }) => {
|
||||
acc[monitorId] = docs.map((doc: any) => this.toEntity(doc as CheckDocument));
|
||||
return acc;
|
||||
}, {});
|
||||
return mapped;
|
||||
};
|
||||
|
||||
findByDateRangeAndMonitorId = async (monitorId: string, startDate: Date, endDate: Date, dateString: string, options?: { type?: MonitorType }) => {
|
||||
|
||||
Reference in New Issue
Block a user