UNPKG

872 BTypeScriptView Raw
1import type { Query } from 'mongoose';
2import type { AnyParamConstructor, QueryHelperThis } from './types';
3/**
4 * Adds a query method to the Class which will then be added to the Schema.
5 * @param func The Query Method to add
6 * @example
7 * ```ts
8 * interface FindHelpers {
9 * findByTitle: AsQueryMethod<typeof findByTitle>;
10 * }
11 *
12 * function findByTitle(this: ReturnModelType<typeof Event, FindHelpers>, title: string) {
13 * return this.find({ title });
14 * }
15 *
16 * @queryMethod(findByTitle)
17 * class Event {
18 * @prop()
19 * public title: string;
20 * }
21 *
22 * const EventModel = getModelForClass<typeof Event, FindHelpers>(Event);
23 * ```
24 */
25export declare function queryMethod<QueryHelpers, U extends AnyParamConstructor<any>>(func: (this: QueryHelperThis<U, QueryHelpers>, ...params: any[]) => Query<any, any>): ClassDecorator;
26export { queryMethod as QueryMethod };