Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: patch dataset #1461

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ export class DatasetsController {
@Req() request: Request,
@Param("pid") pid: string,
@Body()
updateDatasetDto:
updateDatasetObsoleteDto:
| PartialUpdateRawDatasetObsoleteDto
| PartialUpdateDerivedDatasetObsoleteDto,
): Promise<OutputDatasetObsoleteDto | null> {
Expand All @@ -1234,7 +1234,7 @@ export class DatasetsController {

// NOTE: Default validation pipe does not validate union types. So we need custom validation.
await this.validateDatasetObsolete(
updateDatasetDto,
updateDatasetObsoleteDto,
foundDataset.type === "raw"
? PartialUpdateRawDatasetObsoleteDto
: PartialUpdateDerivedDatasetObsoleteDto,
Expand All @@ -1256,6 +1256,10 @@ export class DatasetsController {
throw new ForbiddenException("Unauthorized to update this dataset");
}

const updateDatasetDto = this.convertObsoleteToCurrentSchema(
updateDatasetObsoleteDto,
) as UpdateDatasetDto;

return this.convertCurrentToObsoleteSchema(
await this.datasetsService.findByIdAndUpdate(pid, updateDatasetDto),
);
Expand Down
16 changes: 16 additions & 0 deletions test/RawDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ describe("1900: RawDataset: Raw Datasets", () => {
);
});

it("0125: should update proposal of the dataset", async () => {
return request(appUrl)
.patch("/api/v3/datasets/" + pid)
.send(TestData.PatchProposal1)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
.expect(TestData.SuccessfulPatchStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("proposalId").and.be.string;
res.body.should.have
.property("proposalId")
.and.be.equal(TestData.PatchProposal1["proposal"]);
});
});

it("0130: should update comment of the dataset", async () => {
return request(appUrl)
.patch("/api/v3/datasets/" + pid)
Expand Down
4 changes: 4 additions & 0 deletions test/TestData.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,10 @@ const TestData = {
name: "ESS-wrong",
},

PatchProposal1: {
proposalId: "10.540.16635/20240124",
},

PatchComment: {
comment: "test",
},
Expand Down
Loading