* Query for multiple entities, using a Query from `@ptc-org/nestjs-query-core`. * * @example * ```ts * const todoItems = await this.service.query({ * filter: { title: { eq: 'Foo' } }, * paging: { limit: 10 }, * sorting: [{ field: "create", direction: SortDirection.DESC }],
(query: Query<Entity>)
| 140 | * @param query - The Query used to filter, page, and sort rows. |
| 141 | */ |
| 142 | async query(query: Query<Entity>): Promise<Entity[]> { |
| 143 | const entities = await this.Model.find( |
| 144 | this.buildExpression(query.filter || {}), |
| 145 | {}, |
| 146 | { |
| 147 | limit: query.paging?.limit, |
| 148 | skip: query.paging?.offset, |
| 149 | sort: (query.sorting || []).map((sort) => ({ |
| 150 | [this.getSchemaKey(sort.field.toString())]: sort.direction.toLowerCase(), |
| 151 | })), |
| 152 | }, |
| 153 | ).exec() |
| 154 | return entities.map((doc) => doc.toObject(this.documentToObjectOptions) as Entity) |
| 155 | } |
| 156 | |
| 157 | aggregate(filter: Filter<Entity>, aggregate: AggregateQuery<Entity>): Promise<AggregateResponse<Entity>[]> { |
| 158 | throw new Error('Not implemented yet') |
no test coverage detected