add tags to monitors repo
This commit is contained in:
1 parent
9b84b98391
commit
a7abbd60bd
2 files changed
+11
-2
No files matched your search
@@ -3,6 +3,7 @@ import { type MonitorType, type Monitor, type MonitorsSummary, CheckSnapshot } f
|
|||||||
export interface TeamQueryConfig {
|
export interface TeamQueryConfig {
|
||||||
limit?: number;
|
limit?: number;
|
||||||
type?: MonitorType | MonitorType[];
|
type?: MonitorType | MonitorType[];
|
||||||
|
tags?: string | string[];
|
||||||
page?: number;
|
page?: number;
|
||||||
rowsPerPage?: number;
|
rowsPerPage?: number;
|
||||||
filter?: string;
|
filter?: string;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
};
|
};
|
||||||
|
|
||||||
findByTeamId = async (teamId: string, config: TeamQueryConfig): Promise<Monitor[] | null> => {
|
findByTeamId = async (teamId: string, config: TeamQueryConfig): Promise<Monitor[] | null> => {
|
||||||
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<string, unknown> = {
|
const query: Record<string, unknown> = {
|
||||||
teamId: new mongoose.Types.ObjectId(teamId),
|
teamId: new mongoose.Types.ObjectId(teamId),
|
||||||
@@ -54,6 +54,10 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
query.type = Array.isArray(type) ? { $in: type } : type;
|
query.type = Array.isArray(type) ? { $in: type } : type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tags !== undefined) {
|
||||||
|
query.tags = Array.isArray(tags) ? { $in: tags } : tags;
|
||||||
|
}
|
||||||
|
|
||||||
if (filter !== undefined) {
|
if (filter !== undefined) {
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case "name":
|
case "name":
|
||||||
@@ -152,7 +156,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
};
|
};
|
||||||
|
|
||||||
findMonitorCountByTeamIdAndType = async (teamId: string, config?: TeamQueryConfig): Promise<number> => {
|
findMonitorCountByTeamIdAndType = async (teamId: string, config?: TeamQueryConfig): Promise<number> => {
|
||||||
const { type } = config ?? {};
|
const { type, tags } = config ?? {};
|
||||||
|
|
||||||
const query: FilterQuery<MonitorDocument> = {
|
const query: FilterQuery<MonitorDocument> = {
|
||||||
teamId: new mongoose.Types.ObjectId(teamId),
|
teamId: new mongoose.Types.ObjectId(teamId),
|
||||||
@@ -162,6 +166,10 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
query.type = Array.isArray(type) ? { $in: type } : type;
|
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);
|
const count = await MonitorModel.countDocuments(query);
|
||||||
return count;
|
return count;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user