Skip to content

Commit

Permalink
Merge pull request #1432 from SciCatProject/fix_dataset_output_dto
Browse files Browse the repository at this point in the history
fix: fix dataset output dto
  • Loading branch information
nitrosx authored Sep 27, 2024
2 parents 5b3b305 + dc99292 commit 16aca1b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 33 deletions.
32 changes: 17 additions & 15 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 @@ -739,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 @@ -780,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
16 changes: 8 additions & 8 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 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 16aca1b

Please sign in to comment.