From 58daadb773504045e116c26792d1e58df79876f0 Mon Sep 17 00:00:00 2001 From: Martin Trajanovski Date: Fri, 9 Jun 2023 14:53:34 +0200 Subject: [PATCH 1/2] feat: Make the published data work with filters and limits --- .../published-data.controller.ts | 25 ++++++++++++++++++- src/published-data/published-data.service.ts | 14 ++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/published-data/published-data.controller.ts b/src/published-data/published-data.controller.ts index c6dc28c50..c6a1d261f 100644 --- a/src/published-data/published-data.controller.ts +++ b/src/published-data/published-data.controller.ts @@ -91,10 +91,33 @@ export class PublishedDataController { description: "Database filters to apply when retrieve all published data", required: false, }) - async findAll(@Query("filter") filter?: string): Promise { + @ApiQuery({ + name: "limits", + description: "Database limits to apply when retrieve all published data", + required: false, + }) + async findAll( + @Query("filter") filter?: string, + @Query("limits") limits?: string, + @Query("fields") fields?: string, + ): Promise { const publishedDataFilters: IPublishedDataFilters = JSON.parse( filter ?? "{}", ); + const publishedDataLimits: { + skip: number; + limit: number; + order: string; + } = JSON.parse(limits ?? "{}"); + const publishedDataFields = JSON.parse(fields ?? "{}"); + + if (!publishedDataFilters.limits) { + publishedDataFilters.limits = publishedDataLimits; + } + if (!publishedDataFilters.fields) { + publishedDataFilters.fields = publishedDataFields; + } + return this.publishedDataService.findAll(publishedDataFilters); } diff --git a/src/published-data/published-data.service.ts b/src/published-data/published-data.service.ts index 3e057db35..7c68b2c5c 100644 --- a/src/published-data/published-data.service.ts +++ b/src/published-data/published-data.service.ts @@ -7,6 +7,7 @@ import { parseLimitFilters, addCreatedByFields, addUpdatedByField, + createFullqueryFilter, } from "src/common/utils"; import { CreatePublishedDataDto } from "./dto/create-published-data.dto"; import { UpdatePublishedDataDto } from "./dto/update-published-data.dto"; @@ -44,10 +45,21 @@ export class PublishedDataService { async findAll(filter: IPublishedDataFilters): Promise { const whereFilter: FilterQuery = filter.where ?? {}; + const fields = filter.fields ?? {}; + const filterQuery: FilterQuery = + createFullqueryFilter( + this.publishedDataModel, + "doi", + fields, + ); + const whereClause: FilterQuery = { + ...filterQuery, + ...whereFilter, + }; const { limit, skip, sort } = parseLimitFilters(filter.limits); return this.publishedDataModel - .find(whereFilter) + .find(whereClause) .limit(limit) .skip(skip) .sort(sort) From 7719fed611b0c4d77f821b63f68112b3a0ca43e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Jun 2023 15:57:46 +0000 Subject: [PATCH 2/2] build(deps-dev): bump @types/node from 20.2.5 to 20.3.0 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.2.5 to 20.3.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7e3b7b11e..a56b85450 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3725,9 +3725,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.2.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.2.5.tgz", - "integrity": "sha512-JJulVEQXmiY9Px5axXHeYGLSjhkZEnD+MDPDGbCbIAbMslkKwmygtZFy1X6s/075Yo94sf8GuSlFfPzysQrWZQ==" + "version": "20.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.0.tgz", + "integrity": "sha512-cumHmIAf6On83X7yP+LrsEyUOf/YlociZelmpRYaGFydoaPdxdt80MAbu6vWerQT2COCp2nPvHdsbD7tHn/YlQ==" }, "node_modules/@types/node-fetch": { "version": "2.6.4", @@ -17988,9 +17988,9 @@ "dev": true }, "@types/node": { - "version": "20.2.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.2.5.tgz", - "integrity": "sha512-JJulVEQXmiY9Px5axXHeYGLSjhkZEnD+MDPDGbCbIAbMslkKwmygtZFy1X6s/075Yo94sf8GuSlFfPzysQrWZQ==" + "version": "20.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.0.tgz", + "integrity": "sha512-cumHmIAf6On83X7yP+LrsEyUOf/YlociZelmpRYaGFydoaPdxdt80MAbu6vWerQT2COCp2nPvHdsbD7tHn/YlQ==" }, "@types/node-fetch": { "version": "2.6.4",