@aequum/mongoose
Version:
aequum mongoose tools for repository, pagination, CRUD/CRUDL, configs and utils
77 lines (76 loc) • 3.51 kB
TypeScript
import { RootFilterQuery } from 'mongoose';
import { BaseCRUDLService } from '@aequum/crudl';
import { MongooseRepository } from '../repositories';
/**
* Base CRUDL Mongoose Service for a Mongoose Schema Model, 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 CustomFilterType Custom filter type to filter the query
* @typeParam PrimaryKeyField Primary key field of the Mongoose Schema
* Model by default is `id` (Virtual ID)
*/
export declare abstract class BaseCRUDLMongooseService<SchemaModel extends {
[key in PrimaryKeyField]: any;
}, SchemaModelDto, SchemaModelCreateDto, SchemaModelUpdateDto, CustomFilterType = any, PrimaryKeyField extends string = 'id'> extends BaseCRUDLService implements BaseCRUDLService {
/** The primary key field, default is `_id` even if Virtual ID */
protected primaryKeyField: string;
/** Unique fields to check for duplicated entries */
static uniqueFields: string[];
/** Custom duplicated entry exception message */
static duplicatedEntryMessage?: string;
/** Default MongoDB filter to apply to all queries */
protected defaultMongoDBFilter: RootFilterQuery<SchemaModel>;
/**
* Method to get the default MongoDB filter to apply to all
* queries when an instance member is needed to create the
* default filter, by default returns the
* `defaultMongoDBFilter` property.
*
* If you don't need a local instance member to create the
* default filter, you just need to change the
* `defaultMongoDBFilter` property.
*
* @protected
*/
protected getDefaultMongoDBFilter(): RootFilterQuery<SchemaModel>;
/** @ignore */
static duplicateEntryExceptionMessage(): string;
/**
* Convert a custom query filter to a MongoDB filter, the
* default convert transform the `id` (Virtual ID) field to the
* MongoDB `_id` field. using `virtualIDFilterTransform` method.
*
* @param filter Custom query filter, the fifth type argument
* @returns MongoDB filter
*/
queryFilterToMongoDBFilter(filter: CustomFilterType): RootFilterQuery<SchemaModel>;
/**
* Checks if model have virtual ID field and if it has
* transforms the `id` field to `_id` field.
*
* @param filter
*/
virtualIDFilterTransform(filter: any): void;
/** Mongoose Repository to interact with the Mongoose Model */
protected readonly repository: MongooseRepository<SchemaModel>;
/** @inheritdoc */
create(data: SchemaModelCreateDto): Promise<SchemaModelDto>;
/** @inheritdoc */
retrieve(id: SchemaModel[PrimaryKeyField]): Promise<SchemaModelDto>;
/** @inheritdoc */
retrieveBy(filter: CustomFilterType): Promise<SchemaModelDto>;
/** @inheritdoc */
update(id: SchemaModel[PrimaryKeyField], data: SchemaModelUpdateDto): Promise<SchemaModelDto>;
/** @inheritdoc */
updateBy(filter: CustomFilterType, data: SchemaModelUpdateDto): Promise<SchemaModelDto>;
/** @inheritdoc */
delete(id: SchemaModel[PrimaryKeyField]): Promise<void>;
/** @inheritdoc */
deleteBy(filter: CustomFilterType): Promise<void>;
/** @inheritdoc */
list(filter?: any): Promise<SchemaModelDto[]>;
}