From 9ab8db2ef3f0988ad570ba399ee520bee13ebf83 Mon Sep 17 00:00:00 2001 From: junjiequan Date: Mon, 23 Sep 2024 14:21:37 +0200 Subject: [PATCH 1/7] fix: renamed instrumentIds key to instrumentId key in convertObsoleteToCurrentSchema function --- src/datasets/datasets.controller.ts | 4 ++-- src/datasets/dto/update-raw-dataset-obsolete.dto.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index bfc9dd843..920ba0aee 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -424,7 +424,7 @@ export class DatasetsController { (inputObsoleteDataset as CreateRawDatasetObsoleteDto).sampleId, ]; } - if ("instrumentIds" in inputObsoleteDataset) { + if ("instrumentId" in inputObsoleteDataset) { propertiesModifier.instrumentIds = [ (inputObsoleteDataset as CreateRawDatasetObsoleteDto).instrumentId, ]; @@ -557,7 +557,7 @@ export class DatasetsController { obsoleteDatasetDto, ) as CreateDatasetDto; const createdDataset = await this.datasetsService.create(datasetDto); - + console.log("====createdDataset====", createdDataset); const outputObsoleteDatasetDto = this.convertCurrentToObsoleteSchema(createdDataset); diff --git a/src/datasets/dto/update-raw-dataset-obsolete.dto.ts b/src/datasets/dto/update-raw-dataset-obsolete.dto.ts index 020cbcf70..50096b914 100644 --- a/src/datasets/dto/update-raw-dataset-obsolete.dto.ts +++ b/src/datasets/dto/update-raw-dataset-obsolete.dto.ts @@ -77,7 +77,7 @@ export class UpdateRawDatasetObsoleteDto extends UpdateDatasetObsoleteDto { }) @IsOptional() @IsString() - readonly instrumentId: string; + readonly instrumentId?: string; @IsOptional() investigator?: string; From bdde868767e546ab13b792ab38714298fbf1a6bb Mon Sep 17 00:00:00 2001 From: junjiequan Date: Mon, 23 Sep 2024 14:24:48 +0200 Subject: [PATCH 2/7] remove consolel.log --- src/datasets/datasets.controller.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 920ba0aee..f0ee5977c 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -557,7 +557,6 @@ export class DatasetsController { obsoleteDatasetDto, ) as CreateDatasetDto; const createdDataset = await this.datasetsService.create(datasetDto); - console.log("====createdDataset====", createdDataset); const outputObsoleteDatasetDto = this.convertCurrentToObsoleteSchema(createdDataset); From 1d381be302c36df93877e962e6b9abc1f151723a Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Tue, 24 Sep 2024 14:40:13 +0200 Subject: [PATCH 3/7] fixing the dataset output dto --- src/datasets/datasets.controller.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index f0ee5977c..ba6faa208 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -746,7 +746,8 @@ export class DatasetsController { const includeFilters = mergedFilters.include ?? []; await Promise.all( datasets.map(async (dataset) => { - if (includeFilters) { + dataset = this.convertCurrentToObsoleteSchema(dataset); + if (includeFilters) { await Promise.all( includeFilters.map(async ({ relation }) => { switch (relation) { @@ -1169,7 +1170,7 @@ export class DatasetsController { await this.checkPermissionsForDatasetObsolete(request, id), ); - return dataset as OutputDatasetObsoleteDto; + return this.convertCurrentToObsoleteSchema(dataset) as OutputDatasetObsoleteDto; } // PATCH /datasets/:id From 441374fd0bfc52e321011b814172773057fb5319 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Tue, 24 Sep 2024 14:48:32 +0200 Subject: [PATCH 4/7] updated raw datasets to include instrument and sample id --- test/RawDataset.js | 3 +++ test/TestData.js | 2 ++ 2 files changed, 5 insertions(+) diff --git a/test/RawDataset.js b/test/RawDataset.js index c150faa40..6e9fcd748 100644 --- a/test/RawDataset.js +++ b/test/RawDataset.js @@ -93,6 +93,9 @@ describe("1900: RawDataset: Raw Datasets", () => { res.body.should.have.property("owner").and.be.string; res.body.should.have.property("type").and.equal("raw"); res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("instrumentId").and.be.string; + res.body.should.have.property("proposalId").and.be.string; + res.body.should.have.property("sampleId").and.be.string; pid = encodeURIComponent(res.body["pid"]); }); }); diff --git a/test/TestData.js b/test/TestData.js index 84a7090cb..09c806577 100644 --- a/test/TestData.js +++ b/test/TestData.js @@ -232,6 +232,8 @@ const TestData = { ownerGroup: "p13388", accessGroups: [], proposalId: "10.540.16635/20110123", + instrumentId: "1f016ec4-7a73-11ef-ae3e-439013069377", + sampleId: "20c32b4e-7a73-11ef-9aec-5b9688aa3791i", type: "raw", keywords: ["sls", "protein"], }, From 6ac5cc6ac0bd74e56bd2e471c49957500a8a33fb Mon Sep 17 00:00:00 2001 From: junjiequan Date: Wed, 25 Sep 2024 13:20:56 +0200 Subject: [PATCH 5/7] refactor: enable versioing for routes --- src/config/configuration.ts | 2 +- src/main.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/config/configuration.ts b/src/config/configuration.ts index 96e9e9bbd..94a190d89 100644 --- a/src/config/configuration.ts +++ b/src/config/configuration.ts @@ -59,7 +59,7 @@ const configuration = () => { const config = { versions: { - api: "v3", + api: "3", }, swaggerPath: process.env.SWAGGER_PATH || "explorer", loggerConfigs: jsonConfigMap.loggers || [defaultLogger], diff --git a/src/main.ts b/src/main.ts index 980dc66a8..3af41b802 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ import { SwaggerModule, } from "@nestjs/swagger"; import { AppModule } from "./app.module"; -import { Logger, ValidationPipe } from "@nestjs/common"; +import { Logger, ValidationPipe, VersioningType } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import { AllExceptionsFilter, ScicatLogger } from "./loggers/logger.service"; @@ -29,11 +29,20 @@ async function bootstrap() { app.enableCors(); - app.setGlobalPrefix(`api/${apiVersion}`); + app.setGlobalPrefix("api"); + + // NOTE: This is a workaround to enable versioning for individual routes + // Version decorator can be used to specify the version for a route + // Read more on https://docs.nestjs.com/techniques/versioning + app.enableVersioning({ + type: VersioningType.URI, + defaultVersion: apiVersion, + }); + const config = new DocumentBuilder() .setTitle("SciCat backend API") .setDescription("This is the API for the SciCat Backend") - .setVersion(`api/${apiVersion}`) + .setVersion(`api/v${apiVersion}`) .addBearerAuth() .build(); From 2e9763b4a6fccfef9c24a32f1ddea161327f2d67 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 25 Sep 2024 16:34:40 +0200 Subject: [PATCH 6/7] fixed obsolete dataset dtos --- src/datasets/datasets.controller.ts | 37 ++++++++++--------- .../dto/output-dataset-obsolete.dto.ts | 16 ++++---- .../dto/update-dataset-obsolete.dto.ts | 9 +++++ .../dto/update-raw-dataset-obsolete.dto.ts | 16 ++++---- test/DerivedDataset.js | 3 ++ test/OrigDatablockForRawDataset.js | 1 - test/TestData.js | 3 ++ 7 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index ba6faa208..2f9491244 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -409,16 +409,16 @@ export class DatasetsController { version: "v3", }; + if ("proposalId" in inputObsoleteDataset) { + propertiesModifier.proposalIds = [ + (inputObsoleteDataset as CreateRawDatasetObsoleteDto).proposalId, + ]; + } if ( inputObsoleteDataset instanceof CreateRawDatasetObsoleteDto || inputObsoleteDataset instanceof UpdateRawDatasetObsoleteDto || inputObsoleteDataset instanceof PartialUpdateRawDatasetObsoleteDto ) { - if ("proposalId" in inputObsoleteDataset) { - propertiesModifier.proposalIds = [ - (inputObsoleteDataset as CreateRawDatasetObsoleteDto).proposalId, - ]; - } if ("sampleId" in inputObsoleteDataset) { propertiesModifier.sampleIds = [ (inputObsoleteDataset as CreateRawDatasetObsoleteDto).sampleId, @@ -476,15 +476,15 @@ export class DatasetsController { const propertiesModifier: Record = {}; if (inputDataset) { if ("proposalIds" in inputDataset) { - propertiesModifier.proposalIds = inputDataset.proposalIds![0]; + propertiesModifier.proposalId = inputDataset.proposalIds![0]; } if ("sampleIds" in inputDataset) { - propertiesModifier.sampleIds = inputDataset.sampleIds![0]; + propertiesModifier.sampleId = inputDataset.sampleIds![0]; } if ("instrumentIds" in inputDataset) { - propertiesModifier.instrumentIds = inputDataset.instrumentIds![0]; + propertiesModifier.instrumentId = inputDataset.instrumentIds![0]; } - if (inputDataset.type == "raw") { + if (inputDataset.type == "derived") { if ("investigator" in inputDataset) { propertiesModifier.investigator = inputDataset.principalInvestigator; } @@ -499,7 +499,7 @@ export class DatasetsController { return outputDataset; } - // POST /datasets + // POST https://scicat.ess.eu/api/v3/datasets @UseGuards(PoliciesGuard) @CheckPolicies("datasets", (ability: AppAbility) => ability.can(Action.DatasetCreate, DatasetClass), @@ -739,15 +739,16 @@ export class DatasetsController { ) as IFilters; // this should be implemented at database level - const datasets = (await this.datasetsService.findAll( - mergedFilters, - )) as OutputDatasetObsoleteDto[]; + const datasets = await this.datasetsService.findAll(mergedFilters); + let outputDatasets: OutputDatasetObsoleteDto[] = []; if (datasets && datasets.length > 0) { const includeFilters = mergedFilters.include ?? []; + outputDatasets = datasets.map((dataset) => + this.convertCurrentToObsoleteSchema(dataset), + ); await Promise.all( - datasets.map(async (dataset) => { - dataset = this.convertCurrentToObsoleteSchema(dataset); - if (includeFilters) { + outputDatasets.map(async (dataset) => { + if (includeFilters) { await Promise.all( includeFilters.map(async ({ relation }) => { switch (relation) { @@ -781,7 +782,7 @@ export class DatasetsController { }), ); } - return datasets; + return outputDatasets; } // GET /datasets/fullquery @@ -1170,7 +1171,7 @@ export class DatasetsController { await this.checkPermissionsForDatasetObsolete(request, id), ); - return this.convertCurrentToObsoleteSchema(dataset) as OutputDatasetObsoleteDto; + return dataset as OutputDatasetObsoleteDto; } // PATCH /datasets/:id diff --git a/src/datasets/dto/output-dataset-obsolete.dto.ts b/src/datasets/dto/output-dataset-obsolete.dto.ts index dced6bc31..bb511edcd 100644 --- a/src/datasets/dto/output-dataset-obsolete.dto.ts +++ b/src/datasets/dto/output-dataset-obsolete.dto.ts @@ -92,14 +92,14 @@ export class OutputDatasetObsoleteDto extends UpdateDatasetObsoleteDto { @IsString() readonly dataFormat?: string; - @ApiProperty({ - type: String, - required: false, - description: "The ID of the proposal to which the dataset belongs.", - }) - @IsOptional() - @IsString() - readonly proposalId?: string; + // @ApiProperty({ + // type: String, + // required: false, + // description: "The ID of the proposal to which the dataset belongs.", + // }) + // @IsOptional() + // @IsString() + // readonly proposalId?: string; @ApiProperty({ type: String, diff --git a/src/datasets/dto/update-dataset-obsolete.dto.ts b/src/datasets/dto/update-dataset-obsolete.dto.ts index ac0e996c8..73f4b34bd 100644 --- a/src/datasets/dto/update-dataset-obsolete.dto.ts +++ b/src/datasets/dto/update-dataset-obsolete.dto.ts @@ -288,6 +288,15 @@ export class UpdateDatasetObsoleteDto extends OwnableDto { @IsOptional() @IsNumber() readonly dataQualityMetrics?: number; + + @ApiProperty({ + type: String, + required: false, + description: "The ID of the proposal to which the dataset belongs.", + }) + @IsOptional() + @IsString() + readonly proposalId?: string; } export class PartialUpdateDatasetObsoleteDto extends PartialType( diff --git a/src/datasets/dto/update-raw-dataset-obsolete.dto.ts b/src/datasets/dto/update-raw-dataset-obsolete.dto.ts index 50096b914..075406908 100644 --- a/src/datasets/dto/update-raw-dataset-obsolete.dto.ts +++ b/src/datasets/dto/update-raw-dataset-obsolete.dto.ts @@ -52,14 +52,14 @@ export class UpdateRawDatasetObsoleteDto extends UpdateDatasetObsoleteDto { @IsString() readonly dataFormat?: string; - @ApiProperty({ - type: String, - required: false, - description: "The ID of the proposal to which the dataset belongs.", - }) - @IsOptional() - @IsString() - readonly proposalId?: string; + // @ApiProperty({ + // type: String, + // required: false, + // description: "The ID of the proposal to which the dataset belongs.", + // }) + // @IsOptional() + // @IsString() + // readonly proposalId?: string; @ApiProperty({ type: String, diff --git a/test/DerivedDataset.js b/test/DerivedDataset.js index 1ccadc9ce..7e4c2e6ce 100644 --- a/test/DerivedDataset.js +++ b/test/DerivedDataset.js @@ -99,6 +99,9 @@ describe("0700: DerivedDataset: Derived Datasets", () => { .and.be.equal(TestData.DerivedCorrect.owner); res.body.should.have.property("type").and.be.equal("derived"); res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("proposalId").and.be.string; + //res.body.should.have.property("sampleId").and.be.string; + //res.body.should.have.property("instrumentId").and.be.string; pid = res.body["pid"]; }); }); diff --git a/test/OrigDatablockForRawDataset.js b/test/OrigDatablockForRawDataset.js index 859b49333..d329d5867 100644 --- a/test/OrigDatablockForRawDataset.js +++ b/test/OrigDatablockForRawDataset.js @@ -304,7 +304,6 @@ describe("1200: OrigDatablockForRawDataset: Test OrigDatablocks and their relati .expect(TestData.SuccessfulGetStatusCode) .expect("Content-Type", /json/) .then((res) => { - console.log(res.body); res.body["pid"].should.be.equal(decodeURIComponent(datasetPid1)); res.body.origdatablocks.should.be .instanceof(Array) diff --git a/test/TestData.js b/test/TestData.js index 09c806577..801a45768 100644 --- a/test/TestData.js +++ b/test/TestData.js @@ -453,6 +453,9 @@ const TestData = { ownerGroup: "p34123", accessGroups: [], type: "derived", + proposalId: "10.540.16635/20110123", + //instrumentId: "1f016ec4-7a73-11ef-ae3e-439013069377", + //sampleId: "20c32b4e-7a73-11ef-9aec-5b9688aa3791i", }, DerivedWrong: { From dc9929248db2f56d62f5c56773ac19cd2ff0d662 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Fri, 27 Sep 2024 11:51:31 +0200 Subject: [PATCH 7/7] removed commented field from dataset dto --- src/datasets/dto/output-dataset-obsolete.dto.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/datasets/dto/output-dataset-obsolete.dto.ts b/src/datasets/dto/output-dataset-obsolete.dto.ts index bb511edcd..f99a7fe94 100644 --- a/src/datasets/dto/output-dataset-obsolete.dto.ts +++ b/src/datasets/dto/output-dataset-obsolete.dto.ts @@ -92,15 +92,6 @@ export class OutputDatasetObsoleteDto extends UpdateDatasetObsoleteDto { @IsString() readonly dataFormat?: string; - // @ApiProperty({ - // type: String, - // required: false, - // description: "The ID of the proposal to which the dataset belongs.", - // }) - // @IsOptional() - // @IsString() - // readonly proposalId?: string; - @ApiProperty({ type: String, required: false,