UNPKG

mongoose-query-toolkit

Version:

A toolkit for handling Mongoose queries with support for search, filtering, pagination, sorting, field selection, and population

39 lines (38 loc) 1.04 kB
import { Document, Model } from 'mongoose'; export interface QueryOptions { q?: string; page?: number; limit?: number; sort?: string; select?: string; populate?: string; [key: string]: any; } export interface PaginationResult<T> { docs: T[]; totalDocs: number; limit: number; page: number; totalPages: number; hasNextPage: boolean; hasPrevPage: boolean; } export declare class QueryToolkit<T extends Document> { private readonly model; private searchFields; private filterableFields; private selectableFields; private populatableFields; constructor(model: Model<T>, options?: { searchFields?: string[]; filterableFields?: string[]; selectableFields?: string[]; populatableFields?: string[]; }); private buildSearchQuery; private buildFilterQuery; private parseSortString; private buildSelectQuery; private buildPopulateFields; findWithOptions(options?: QueryOptions): Promise<PaginationResult<T>>; }