Skip to content

Commit

Permalink
Merge pull request #468 from SciCatProject/SWAP-3157-scicat-fe-be-fe-…
Browse files Browse the repository at this point in the history
…report-successful-sharing-of-a-da

fix: fixed sharing dataset 500 error
  • Loading branch information
nitrosx authored Apr 28, 2023
2 parents 4eeb79e + 7089d0b commit aaaf4a8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -924,12 +924,13 @@ export class DatasetsController {
description: "Id of the dataset to be modified",
type: String,
})
@ApiParam({
@ApiQuery({
name: "fieldName",
description: "Name of the field to be updated",
type: String,
})
@ApiBody({
@ApiQuery({
name: "data",
description: "Json object with the fields to be updated and their values",
required: true,
type: Array,
Expand All @@ -942,13 +943,16 @@ export class DatasetsController {
async appendToArrayField(
@Param("pid") id: string,
@Query("fieldName") fieldName: string,
@Body() data: unknown[],
@Query("data") data: string,
): Promise<DatasetClass | null> {
// $addToSet is necessary to append to the field and not overwrite
// $each is necessary as data is an array of values

const parsedData = JSON.parse(data);

const updateQuery: UpdateQuery<DatasetDocument> = {
$addToSet: {
[fieldName]: { $each: data },
[fieldName]: { $each: parsedData },
},
};

Expand Down

0 comments on commit aaaf4a8

Please sign in to comment.