UNPKG

@aequum/mongoose

Version:

aequum mongoose tools for repository, pagination, CRUD/CRUDL, configs and utils

42 lines (41 loc) 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseCRUDLMongoosePaginatedService = void 0; require("mongoose-paginate-v2"); const paginate_common_1 = require("@aequum/paginate-common"); const __1 = require(".."); /** * Base CRUD/CRUDL Mongoose Service for a Mongoose Schema Model, with * paginated list output, by default assumes that the primary key * field as `id` provided by Virtual ID * * @typeParam SchemaModel Mongoose Schema Model * @typeParam SchemaModelDto DTO of the Mongoose Schema Model * @typeParam SchemaModelCreateDto DTO to create a new Mongoose Schema Model * @typeParam SchemaModelUpdateDto DTO to update a Mongoose Schema Model * @typeParam PaginatedSchemaModelDto Paginated DTO of the Mongoose Schema Model * @typeParam CustomFilterType Custom filter type to filter the query * @typeParam PrimaryKeyField Primary key field of the Mongoose Schema * Model by default is `id` (Virtual ID) */ class BaseCRUDLMongoosePaginatedService extends __1.BaseCRUDLMongooseService { /** * List all data entries paginated * * @param filter - Filter to apply to the query * @param page - Page number * @param size - Page size * @param sort - Sort options * @param projection - MongoDB projection * @param options - `mongoose-paginate-v2` options * @returns Paginated result * * @see [Options for `mongoose-paginate-v2`](https://github.com/aravindnc/mongoose-paginate-v2?tab=readme-ov-file#modelpaginatequery-options-callback) */ async paginatedList(filter, page, size, sort, projection, options) { if (typeof sort === 'string') sort = (0, paginate_common_1.sortStringToPaginateSortBy)(sort); return this.repository.paginatedFind(this.queryFilterToMongoDBFilter(filter), page, size, sort, projection, options); } } exports.BaseCRUDLMongoosePaginatedService = BaseCRUDLMongoosePaginatedService;