Skip to content

Commit

Permalink
fix: improve and fix some of the ApiResponse types
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-trajanovski committed Nov 6, 2024
1 parent 59d3d75 commit 329c5f7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import {
PartialUpdateDatasetDto,
UpdateDatasetDto,
} from "./dto/update-dataset.dto";
import { Logbook } from "src/logbooks/schemas/logbook.schema";

@ApiBearerAuth()
@ApiExtraModels(
Expand Down Expand Up @@ -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",
})
Expand Down
7 changes: 5 additions & 2 deletions src/logbooks/schemas/logbook.schema.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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[];
}
Expand Down
22 changes: 21 additions & 1 deletion src/published-data/interfaces/published-data.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiProperty } from "@nestjs/swagger";
import { FilterQuery } from "mongoose";
import { PublishedDataDocument } from "../schemas/published-data.schema";

Expand All @@ -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;
}

Expand Down
10 changes: 8 additions & 2 deletions src/published-data/published-data.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
} from "./schemas/published-data.schema";
import {
ICount,
IFormPopulateData,
FormPopulateData,
IPublishedDataFilters,
IRegister,
} from "./interfaces/published-data.interface";
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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")
Expand Down

0 comments on commit 329c5f7

Please sign in to comment.