From a7abbd60bd91762f8df3c2872db10ec47003a634 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 19 May 2026 14:44:18 -0700 Subject: [PATCH] add tags to monitors repo --- .../src/repositories/monitors/IMonitorsRepository.ts | 1 + .../repositories/monitors/MongoMonitorsRepository.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/server/src/repositories/monitors/IMonitorsRepository.ts b/server/src/repositories/monitors/IMonitorsRepository.ts index ea75e11f6..6103132f8 100644 --- a/server/src/repositories/monitors/IMonitorsRepository.ts +++ b/server/src/repositories/monitors/IMonitorsRepository.ts @@ -3,6 +3,7 @@ import { type MonitorType, type Monitor, type MonitorsSummary, CheckSnapshot } f export interface TeamQueryConfig { limit?: number; type?: MonitorType | MonitorType[]; + tags?: string | string[]; page?: number; rowsPerPage?: number; filter?: string; diff --git a/server/src/repositories/monitors/MongoMonitorsRepository.ts b/server/src/repositories/monitors/MongoMonitorsRepository.ts index 9e493e740..24a3cb7d8 100644 --- a/server/src/repositories/monitors/MongoMonitorsRepository.ts +++ b/server/src/repositories/monitors/MongoMonitorsRepository.ts @@ -44,7 +44,7 @@ class MongoMonitorsRepository implements IMonitorsRepository { }; findByTeamId = async (teamId: string, config: TeamQueryConfig): Promise => { - const { page = 0, rowsPerPage = 0, filter, field = "createdAt", order = "desc", type } = config ?? {}; + const { page = 0, rowsPerPage = 0, filter, field = "createdAt", order = "desc", type, tags } = config ?? {}; const query: Record = { teamId: new mongoose.Types.ObjectId(teamId), @@ -54,6 +54,10 @@ class MongoMonitorsRepository implements IMonitorsRepository { query.type = Array.isArray(type) ? { $in: type } : type; } + if (tags !== undefined) { + query.tags = Array.isArray(tags) ? { $in: tags } : tags; + } + if (filter !== undefined) { switch (field) { case "name": @@ -152,7 +156,7 @@ class MongoMonitorsRepository implements IMonitorsRepository { }; findMonitorCountByTeamIdAndType = async (teamId: string, config?: TeamQueryConfig): Promise => { - const { type } = config ?? {}; + const { type, tags } = config ?? {}; const query: FilterQuery = { teamId: new mongoose.Types.ObjectId(teamId), @@ -162,6 +166,10 @@ class MongoMonitorsRepository implements IMonitorsRepository { query.type = Array.isArray(type) ? { $in: type } : type; } + if (tags !== undefined) { + query.tags = Array.isArray(tags) ? { $in: tags } : tags; + } + const count = await MonitorModel.countDocuments(query); return count; };