pagination and filter fix
This commit is contained in:
1 parent
cdbaad5bd9
commit
93c24d2f5c
6 files changed
+5
-45
No files matched your search
@@ -114,7 +114,7 @@ const UptimeMonitors = () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const activeFilter = [...filterLookup].find(([key]) => key !== undefined);
|
const activeFilter = [...filterLookup].find(([key]) => key !== undefined);
|
||||||
const field = activeFilter?.[1] || sort?.field;
|
const field = activeFilter?.[1] || (search ? "name" : sort?.field);
|
||||||
const filter = activeFilter?.[0] || search;
|
const filter = activeFilter?.[0] || search;
|
||||||
|
|
||||||
const effectiveTypes = selectedTypes?.length ? selectedTypes : TYPES;
|
const effectiveTypes = selectedTypes?.length ? selectedTypes : TYPES;
|
||||||
|
|||||||
@@ -339,26 +339,6 @@ class MonitorController {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getMonitorsAndSummaryByTeamId = async (req: Request, res: Response, next: NextFunction) => {
|
|
||||||
try {
|
|
||||||
await getMonitorsByTeamIdParamValidation.validateAsync(req.params);
|
|
||||||
await getMonitorsByTeamIdQueryValidation.validateAsync(req.query);
|
|
||||||
|
|
||||||
const explain = optionalBoolean(req?.query?.explain, "explain");
|
|
||||||
const type = parseMonitorTypeFilter(req?.query?.type);
|
|
||||||
const teamId = requireTeamId(req?.user?.teamId);
|
|
||||||
|
|
||||||
const result = await this.monitorService.getMonitorsAndSummaryByTeamId({ teamId, type, explain });
|
|
||||||
|
|
||||||
return res.status(200).json({
|
|
||||||
msg: "Monitors and summary retrieved successfully",
|
|
||||||
data: result,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
getMonitorsWithChecksByTeamId = async (req: Request, res: Response, next: NextFunction) => {
|
getMonitorsWithChecksByTeamId = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
await getMonitorsByTeamIdParamValidation.validateAsync(req.params);
|
await getMonitorsByTeamIdParamValidation.validateAsync(req.params);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import {
|
|||||||
|
|
||||||
export type LatestChecksMap = Record<string, Check[]>;
|
export type LatestChecksMap = Record<string, Check[]>;
|
||||||
|
|
||||||
class MongoChecksRepistory implements IChecksRepository {
|
class MongoChecksRepository implements IChecksRepository {
|
||||||
private toEntity = (doc: CheckDocument): Check => {
|
private toEntity = (doc: CheckDocument): Check => {
|
||||||
const toStringId = (value: mongoose.Types.ObjectId | string | undefined | null): string => {
|
const toStringId = (value: mongoose.Types.ObjectId | string | undefined | null): string => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@@ -392,4 +392,4 @@ class MongoChecksRepistory implements IChecksRepository {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MongoChecksRepistory;
|
export default MongoChecksRepository;
|
||||||
@@ -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 = 25, filter, field = "createdAt", order = "desc", type, limit } = config ?? {};
|
const { page = 0, rowsPerPage = 5, filter, field = "createdAt", order = "desc", type, limit } = config ?? {};
|
||||||
|
|
||||||
const query: Record<string, unknown> = {
|
const query: Record<string, unknown> = {
|
||||||
teamId: new mongoose.Types.ObjectId(teamId),
|
teamId: new mongoose.Types.ObjectId(teamId),
|
||||||
@@ -75,9 +75,8 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
|
|
||||||
const sort = { [field]: order === "asc" ? 1 : -1 } as const;
|
const sort = { [field]: order === "asc" ? 1 : -1 } as const;
|
||||||
const skip = Math.max(page, 0) * rowsPerPage;
|
const skip = Math.max(page, 0) * rowsPerPage;
|
||||||
const limitValue = limit ?? rowsPerPage;
|
|
||||||
|
|
||||||
const documents = await MonitorModel.find(query).sort(sort).skip(skip).limit(limitValue).exec();
|
const documents = await MonitorModel.find(query).sort(sort).skip(skip).limit(rowsPerPage);
|
||||||
|
|
||||||
return this.mapDocuments(documents);
|
return this.mapDocuments(documents);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ class MonitorRoutes {
|
|||||||
// Team routes
|
// Team routes
|
||||||
this.router.get("/team", this.monitorController.getMonitorsByTeamId);
|
this.router.get("/team", this.monitorController.getMonitorsByTeamId);
|
||||||
this.router.get("/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId);
|
this.router.get("/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId);
|
||||||
this.router.get("/team/summary", this.monitorController.getMonitorsAndSummaryByTeamId);
|
|
||||||
this.router.get("/team/groups", this.monitorController.getGroupsByTeamId);
|
this.router.get("/team/groups", this.monitorController.getGroupsByTeamId);
|
||||||
|
|
||||||
// Uptime routes
|
// Uptime routes
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ export interface IMonitorService {
|
|||||||
field?: string;
|
field?: string;
|
||||||
order?: "asc" | "desc";
|
order?: "asc" | "desc";
|
||||||
}): Promise<any>;
|
}): Promise<any>;
|
||||||
getMonitorsAndSummaryByTeamId(args: { teamId: string; type?: string | string[]; explain?: boolean }): Promise<any>;
|
|
||||||
getMonitorsWithChecksByTeamId(args: {
|
getMonitorsWithChecksByTeamId(args: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
@@ -362,23 +361,6 @@ export class MonitorService implements IMonitorService {
|
|||||||
return monitors;
|
return monitors;
|
||||||
};
|
};
|
||||||
|
|
||||||
getMonitorsAndSummaryByTeamId = async ({
|
|
||||||
teamId,
|
|
||||||
type,
|
|
||||||
explain,
|
|
||||||
}: {
|
|
||||||
teamId: string;
|
|
||||||
type?: string | string[];
|
|
||||||
explain?: boolean;
|
|
||||||
}): Promise<any> => {
|
|
||||||
const result = await this.db.monitorModule.getMonitorsAndSummaryByTeamId({
|
|
||||||
type,
|
|
||||||
explain,
|
|
||||||
teamId,
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
getMonitorsWithChecksByTeamId = async ({
|
getMonitorsWithChecksByTeamId = async ({
|
||||||
teamId,
|
teamId,
|
||||||
limit,
|
limit,
|
||||||
|
|||||||
Reference in new issue
Block a user