conitnent based query
This commit is contained in:
1 parent
c3e4b5b95f
commit
64fdd04cc7
6 files changed
+51
-6
No files matched your search
@@ -1,9 +1,16 @@
|
||||
import type { GeoCheck, GroupedGeoCheck } from "@/types/geoCheck.js";
|
||||
import type { GeoContinent } from "@/types/geoCheck.js";
|
||||
|
||||
export interface IGeoChecksRepository {
|
||||
createGeoChecks(geoChecks: Omit<GeoCheck, "id" | "__v" | "createdAt" | "updatedAt">[]): Promise<GeoCheck[]>;
|
||||
findByMonitorIdAndDateRange(monitorId: string, startDate: Date, endDate: Date): Promise<GeoCheck[]>;
|
||||
findGroupedByMonitorIdAndDateRange(monitorId: string, startDate: Date, endDate: Date, dateFormat: string): Promise<GroupedGeoCheck[]>;
|
||||
findGroupedByMonitorIdAndDateRange(
|
||||
monitorId: string,
|
||||
startDate: Date,
|
||||
endDate: Date,
|
||||
dateFormat: string,
|
||||
continent?: GeoContinent
|
||||
): Promise<GroupedGeoCheck[]>;
|
||||
deleteByMonitorId(monitorId: string): Promise<number>;
|
||||
deleteByTeamId(teamId: string): Promise<number>;
|
||||
}
|
||||
@@ -117,7 +117,13 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
}
|
||||
};
|
||||
|
||||
findGroupedByMonitorIdAndDateRange = async (monitorId: string, startDate: Date, endDate: Date, dateFormat: string): Promise<GroupedGeoCheck[]> => {
|
||||
findGroupedByMonitorIdAndDateRange = async (
|
||||
monitorId: string,
|
||||
startDate: Date,
|
||||
endDate: Date,
|
||||
dateFormat: string,
|
||||
continent?: string
|
||||
): Promise<GroupedGeoCheck[]> => {
|
||||
try {
|
||||
const pipeline: any[] = [
|
||||
// Match geo checks for this monitor in date range
|
||||
@@ -134,6 +140,16 @@ class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||
{
|
||||
$unwind: "$results",
|
||||
},
|
||||
// Filter by continent if specified
|
||||
...(continent
|
||||
? [
|
||||
{
|
||||
$match: {
|
||||
"results.location.continent": continent,
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
// Group by date bucket and continent
|
||||
{
|
||||
$group: {
|
||||
|
||||
Reference in new issue
Block a user