From 329c5f7dcec4f6e913f6f6bb9a8bf9ef5c583f77 Mon Sep 17 00:00:00 2001 From: martintrajanovski Date: Wed, 6 Nov 2024 16:20:55 +0100 Subject: [PATCH] fix: improve and fix some of the ApiResponse types --- package.json | 5 ++--- src/datasets/datasets.controller.ts | 3 ++- src/logbooks/schemas/logbook.schema.ts | 7 ++++-- .../interfaces/published-data.interface.ts | 22 ++++++++++++++++++- .../published-data.controller.ts | 10 +++++++-- test/Policy.js | 4 ++-- 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 249cec106..0b2d76beb 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,8 @@ "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:api": "npm run test:api:jest --maxWorkers=50% && concurrently -k -s first \"wait-on http://localhost:3000/explorer/ && npm run test:api:mocha\" \"npm run start\"", "test:api:jest": "jest --config ./test/config/jest-e2e.json --maxWorkers=50%", - "test:api:mocha": "mocha --config ./test/config/.mocharc.json -r chai/register-should.js", - "prepare:local": "docker-compose -f CI/E2E/docker-compose-local.yaml --env-file CI/E2E/.env.elastic-search up -d && cp functionalAccounts.json.test functionalAccounts.json", - "generate:sdk:local": "rimraf sdk && docker run --rm -v \"%cd%:/local\" openapitools/openapi-generator-cli:v7.9.0 generate -i http://host.docker.internal:3000/explorer-json -g typescript-angular -o local/sdk/typescript-angular --additional-properties=ngVersion=18.0.0,npmName=restClient,supportsES6=true,npmVersion=10.8.2,withInterfaces=true" + "test:api:mocha": "mocha --config ./test/config/.mocharc.json -r chai/register-should.js --grep \"1300: Policy\"", + "prepare:local": "docker-compose -f CI/E2E/docker-compose-local.yaml --env-file CI/E2E/.env.elastic-search up -d && cp functionalAccounts.json.test functionalAccounts.json" }, "dependencies": { "@casl/ability": "^6.3.2", diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 2f9491244..fe827ea4d 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -104,6 +104,7 @@ import { PartialUpdateDatasetDto, UpdateDatasetDto, } from "./dto/update-dataset.dto"; +import { Logbook } from "src/logbooks/schemas/logbook.schema"; @ApiBearerAuth() @ApiExtraModels( @@ -2230,7 +2231,7 @@ export class DatasetsController { }) @ApiResponse({ status: 200, - // type: Logbook, + type: Logbook, isArray: false, description: "It returns all messages from specificied Logbook room", }) diff --git a/src/logbooks/schemas/logbook.schema.ts b/src/logbooks/schemas/logbook.schema.ts index a25ba3ab1..7c94b5e4a 100644 --- a/src/logbooks/schemas/logbook.schema.ts +++ b/src/logbooks/schemas/logbook.schema.ts @@ -1,5 +1,5 @@ import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; -import { ApiProperty, getSchemaPath } from "@nestjs/swagger"; +import { ApiProperty } from "@nestjs/swagger"; import { Document } from "mongoose"; import { Message, MessageSchema } from "./message.schema"; @@ -15,7 +15,10 @@ export class Logbook { @Prop() roomId: string; - @ApiProperty({ type: "array", items: { $ref: getSchemaPath(Message) } }) + @ApiProperty({ + isArray: true, + type: Message, + }) @Prop([MessageSchema]) messages: Message[]; } diff --git a/src/published-data/interfaces/published-data.interface.ts b/src/published-data/interfaces/published-data.interface.ts index 96c71e4d9..e1a85ef42 100644 --- a/src/published-data/interfaces/published-data.interface.ts +++ b/src/published-data/interfaces/published-data.interface.ts @@ -1,3 +1,4 @@ +import { ApiProperty } from "@nestjs/swagger"; import { FilterQuery } from "mongoose"; import { PublishedDataDocument } from "../schemas/published-data.schema"; @@ -18,11 +19,30 @@ export interface ICount { count: number; } -export interface IFormPopulateData { +export class FormPopulateData { + @ApiProperty({ + type: String, + }) resourceType?: string; + + @ApiProperty({ + type: String, + }) description?: string; + + @ApiProperty({ + type: String, + }) title?: string; + + @ApiProperty({ + type: String, + }) abstract?: string; + + @ApiProperty({ + type: String, + }) thumbnail?: string; } diff --git a/src/published-data/published-data.controller.ts b/src/published-data/published-data.controller.ts index 12dd71a5c..fde55b832 100644 --- a/src/published-data/published-data.controller.ts +++ b/src/published-data/published-data.controller.ts @@ -39,7 +39,7 @@ import { } from "./schemas/published-data.schema"; import { ICount, - IFormPopulateData, + FormPopulateData, IPublishedDataFilters, IRegister, } from "./interfaces/published-data.interface"; @@ -162,8 +162,14 @@ export class PublishedDataController { description: "Dataset pid used to fetch form data.", required: true, }) + @ApiResponse({ + status: HttpStatus.OK, + type: FormPopulateData, + isArray: false, + description: "Return form populate data", + }) async formPopulate(@Query("pid") pid: string) { - const formData: IFormPopulateData = {}; + const formData: FormPopulateData = {}; const dataset = (await this.datasetsService.findOne({ where: { pid }, })) as unknown as DatasetClass; diff --git a/test/Policy.js b/test/Policy.js index 7339542fb..a665245c4 100644 --- a/test/Policy.js +++ b/test/Policy.js @@ -25,7 +25,7 @@ describe("1300: Policy: Simple Policy tests", () => { before(() => { db.collection("Policy").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], @@ -36,7 +36,7 @@ describe("1300: Policy: Simple Policy tests", () => { password: TestData.Accounts["archiveManager"]["password"], }); }); - + it("0010: adds a new policy", async () => { return request(appUrl) .post("/api/v3/Policies")