pagination and filter fix
This commit is contained in:
1 parent
cdbaad5bd9
commit
93c24d2f5c
6 files changed
+5
-45
No files matched your search
@@ -23,7 +23,7 @@ import {
|
||||
|
||||
export type LatestChecksMap = Record<string, Check[]>;
|
||||
|
||||
class MongoChecksRepistory implements IChecksRepository {
|
||||
class MongoChecksRepository implements IChecksRepository {
|
||||
private toEntity = (doc: CheckDocument): Check => {
|
||||
const toStringId = (value: mongoose.Types.ObjectId | string | undefined | null): string => {
|
||||
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> => {
|
||||
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> = {
|
||||
teamId: new mongoose.Types.ObjectId(teamId),
|
||||
@@ -75,9 +75,8 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
|
||||
const sort = { [field]: order === "asc" ? 1 : -1 } as const;
|
||||
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);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user