import { InjectableOptions } from '@nestjs/common/decorators/core/injectable.decorator'; import { Class, DeepPartial } from '../common'; import { AggregateOptions, AggregateQuery, AggregateResponse, CountOptions, DeleteManyOptions, DeleteManyResponse, DeleteOneOptions, Filter, FindByIdOptions, FindRelationOptions, GetByIdOptions, ModifyRelationOptions, Query, QueryOptions, QueryRelationsOptions, UpdateManyResponse, UpdateOneOptions } from '../interfaces'; /** * Base interface for all QueryServices. * * @typeparam T - The record type that the query service will operate on. */ export interface QueryService, U = DeepPartial> { /** * Query for multiple records of type `T`. * @param query - the query used to filer, page or sort records. * @param selectRelations - additional relation to select and fetch in the same query. * @returns a promise with an array of records that match the query. */ query(query: Query, opts?: QueryOptions): Promise; /** * Perform an aggregate query * @param filter * @param aggregate */ aggregate(filter: Filter, aggregate: AggregateQuery, opts?: AggregateOptions): Promise[]>; /** * Count the number of records that match the filter. * @param filter - the filter * @returns a promise with the total number of records. */ count(filter: Filter, opts?: CountOptions): Promise; /** * Finds a record by `id`. * @param id - the id of the record to find. * @param opts - Additional options to apply when finding by id. * @returns the found record or undefined. */ findById(id: string | number, opts?: FindByIdOptions): Promise; /** * Query for an array of relations. * * @param RelationClass - The class to serialize the Relations into * @param dto - The dto to query relations for. * @param relationName - The name of relation to query for. * @param query - A query to filter, page or sort relations. */ queryRelations(RelationClass: Class, relationName: string, dto: DTO, query: Query, opts?: QueryRelationsOptions): Promise; queryRelations(RelationClass: Class, relationName: string, dtos: DTO[], query: Query, opts?: QueryRelationsOptions): Promise>; /** * Aggregate relations for a DTO. * * @param RelationClass - The class to serialize the Relations into * @param dto - The DTO to query relations for. * @param relationName - The name of relation to query for. * @param filter - A filter to apply to relations. * @param aggregate - The aggregate query */ aggregateRelations(RelationClass: Class, relationName: string, dto: DTO, filter: Filter, aggregate: AggregateQuery): Promise[]>; aggregateRelations(RelationClass: Class, relationName: string, dtos: DTO[], filter: Filter, aggregate: AggregateQuery): Promise[]>>; /** * Count the number of relations * @param filter - Filter to create a where clause. */ countRelations(RelationClass: Class, relationName: string, dto: DTO, filter: Filter, opts?: QueryRelationsOptions): Promise; countRelations(RelationClass: Class, relationName: string, dto: DTO[], filter: Filter, opts?: QueryRelationsOptions): Promise>; /** * Finds a single relation. * @param RelationClass - The class to serialize the Relation into * @param dto - The dto to find the relation on. * @param relationName - The name of the relation to query for. * @param opts - Additional options. */ findRelation(RelationClass: Class, relationName: string, dto: DTO, opts?: FindRelationOptions): Promise; /** * Finds a single relation for each DTO passed in. * * @param RelationClass - The class to serialize the Relation into* * @param relationName - The name of the relation to query for. * @param dtos - The dto to find the relation on. * @param opts - Additional options. */ findRelation(RelationClass: Class, relationName: string, dtos: DTO[], opts?: FindRelationOptions): Promise>; /** * Adds multiple relations. * @param relationName - The name of the relation to query for. * @param id - The id of the dto to add the relation to. * @param relationIds - The ids of the relations to add. * @param opts - Additional options. */ addRelations(relationName: string, id: string | number, relationIds: (string | number)[], opts?: ModifyRelationOptions): Promise; /** * Set the relations on the dto. * * @param relationName - The name of the relation to query for. * @param id - The id of the dto to set the relation on. * @param relationIds - The ids of the relation to set on the dto. If the array is empty the relations will be * removed. * @param opts - Additional options. */ setRelations(relationName: string, id: string | number, relationIds: (string | number)[], opts?: ModifyRelationOptions): Promise; /** * Set the relation on the dto. * * @param relationName - The name of the relation to query for. * @param id - The id of the dto to set the relation on. * @param relationId - The id of the relation to set on the dto. * @param opts - Additional options. */ setRelation(relationName: string, id: string | number, relationId: string | number, opts?: ModifyRelationOptions): Promise; /** * Removes multiple relations. * @param relationName - The name of the relation to query for. * @param id - The id of the dto to add the relation to. * @param relationIds - The ids of the relations to add. * @param opts - Additional options. */ removeRelations(relationName: string, id: string | number, relationIds: (string | number)[], opts?: ModifyRelationOptions): Promise; /** * Remove the relation on the dto. * * @param relationName - The name of the relation to query for. * @param id - The id of the dto to set the relation on. * @param relationId - The id of the relation to set on the dto. * @param opts - Additional options. */ removeRelation(relationName: string, id: string | number, relationId: string | number, opts?: ModifyRelationOptions): Promise; /** * Gets a record by `id`. * * **NOTE** This method will return a rejected Promise if the record is not found. * * @param id - the id of the record. * @param opts - Additional options to apply when getting by id. * @returns the found record or a rejected promise. */ getById(id: string | number, opts?: GetByIdOptions): Promise; /** * Create a single record. * * @param item - the record to create. * @returns the created record. */ createOne(item: C): Promise; /** * Creates a multiple record. * * @param items - the records to create. * @returns a created records. */ createMany(items: C[]): Promise; /** * Update one record. * @param id - the id of the record to update * @param update - The update to apply. * @param opts - Additional opts to apply when updating one entity. * @returns the updated record. */ updateOne(id: string | number, update: U, opts?: UpdateOneOptions): Promise; /** * Updates multiple records using a filter. * @param update - the update to apply. * @param filter - the filter used to specify records to update */ updateMany(update: U, filter: Filter): Promise; /** * Delete a single record by id. * @param id - the id of the record to delete. * @param opts - additional opts to apply when deleting by id. */ deleteOne(id: number | string, opts?: DeleteOneOptions): Promise; /** * Delete multiple records using a filter. * * @param filter - the filter to find records to delete. * @param opts - additional opts to apply when deleting by id. */ deleteMany(filter: Filter, opts?: DeleteManyOptions): Promise; } /** * QueryService decorator to register with nestjs-query * @param DTOClass - the DTO class that the QueryService is used for. * @param options - InjectableOptions */ export declare function QueryService, U = DeepPartial>(DTOClass: Class, options?: InjectableOptions): >>(cls: Cls) => Cls | void;