Skip to content

Commit

Permalink
fix: handle obsolete where filter fields mapping to current schema (#…
Browse files Browse the repository at this point in the history
…1521)

* fix: handle obsolete where filter fields mapping to current schema

* Update datasets.controller.ts

* remove unused ENV variable from the example file
  • Loading branch information
Junjiequan authored Nov 28, 2024
1 parent 3970708 commit 071d759
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ OIDC_USERQUERY_OPERATOR=<"or"|"and">
OIDC_USERQUERY_FILTER="username:username, email:email"

ELASTICSEARCH_ENABLED=<"yes"|"no">
APP_PORT=3003
STACK_VERSION="8.8.2"
CLUSTER_NAME="es-cluster"
MEM_LIMIT="4G"
Expand Down
32 changes: 29 additions & 3 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ export class DatasetsController {
DatasetClass,
);

if (!mergedFilters.where) {
mergedFilters.where = {};
}

if (!canViewAny) {
if (!mergedFilters.where) {
mergedFilters.where = {};
}
if (canViewAccess) {
mergedFilters.where["$or"] = [
{ ownerGroup: { $in: user.currentGroups } },
Expand All @@ -196,6 +197,10 @@ export class DatasetsController {
}
}

mergedFilters.where = this.convertObsoleteWhereFilterToCurrentSchema(
mergedFilters.where,
);

return mergedFilters;
}

Expand Down Expand Up @@ -396,6 +401,27 @@ export class DatasetsController {
return dataset;
}

convertObsoleteWhereFilterToCurrentSchema(
whereFilter: Record<string, unknown>,
): IFilters<DatasetDocument, IDatasetFields> {
if ("proposalId" in whereFilter) {
whereFilter.proposalIds = whereFilter.proposalId;
delete whereFilter.proposalId;
}
if ("sampleId" in whereFilter) {
whereFilter.sampleIds = whereFilter.sampleId;
delete whereFilter.sampleId;
}
if ("instrumentId" in whereFilter) {
whereFilter.instrumentIds = whereFilter.instrumentId;
delete whereFilter.instrumentId;
}
if ("principalInvestigator" in whereFilter) {
whereFilter.investigator = whereFilter.principalInvestigator;
delete whereFilter.principalInvestigator;
}
return whereFilter;
}
convertObsoleteToCurrentSchema(
inputObsoleteDataset:
| CreateRawDatasetObsoleteDto
Expand Down

0 comments on commit 071d759

Please sign in to comment.