Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/actions/setup-py…
Browse files Browse the repository at this point in the history
…thon-5
  • Loading branch information
nitrosx authored Sep 30, 2024
2 parents d1420aa + 2c55165 commit 84e48a9
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const configuration = () => {

const config = {
versions: {
api: "v3",
api: "3",
},
swaggerPath: process.env.SWAGGER_PATH || "explorer",
loggerConfigs: jsonConfigMap.loggers || [defaultLogger],
Expand Down
35 changes: 18 additions & 17 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,22 +409,22 @@ 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,
];
}
if ("instrumentIds" in inputObsoleteDataset) {
if ("instrumentId" in inputObsoleteDataset) {
propertiesModifier.instrumentIds = [
(inputObsoleteDataset as CreateRawDatasetObsoleteDto).instrumentId,
];
Expand Down Expand Up @@ -476,15 +476,15 @@ export class DatasetsController {
const propertiesModifier: Record<string, unknown> = {};
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;
}
Expand All @@ -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),
Expand Down Expand Up @@ -557,7 +557,6 @@ export class DatasetsController {
obsoleteDatasetDto,
) as CreateDatasetDto;
const createdDataset = await this.datasetsService.create(datasetDto);

const outputObsoleteDatasetDto =
this.convertCurrentToObsoleteSchema(createdDataset);

Expand Down Expand Up @@ -740,13 +739,15 @@ export class DatasetsController {
) as IFilters<DatasetDocument, IDatasetFields>;

// 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) => {
outputDatasets.map(async (dataset) => {
if (includeFilters) {
await Promise.all(
includeFilters.map(async ({ relation }) => {
Expand Down Expand Up @@ -781,7 +782,7 @@ export class DatasetsController {
}),
);
}
return datasets;
return outputDatasets;
}

// GET /datasets/fullquery
Expand Down
9 changes: 0 additions & 9 deletions src/datasets/dto/output-dataset-obsolete.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/datasets/dto/update-dataset-obsolete.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 9 additions & 9 deletions src/datasets/dto/update-raw-dataset-obsolete.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -77,7 +77,7 @@ export class UpdateRawDatasetObsoleteDto extends UpdateDatasetObsoleteDto {
})
@IsOptional()
@IsString()
readonly instrumentId: string;
readonly instrumentId?: string;

@IsOptional()
investigator?: string;
Expand Down
15 changes: 12 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

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

Expand Down
3 changes: 3 additions & 0 deletions test/DerivedDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
});
});
Expand Down
1 change: 0 additions & 1 deletion test/OrigDatablockForRawDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions test/RawDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
});
});
Expand Down
5 changes: 5 additions & 0 deletions test/TestData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
},
Expand Down Expand Up @@ -451,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: {
Expand Down

0 comments on commit 84e48a9

Please sign in to comment.