Skip to content

Commit

Permalink
Merge pull request #228 from biomage-ltd/fix-project-ids-fetching
Browse files Browse the repository at this point in the history
Fix project ids fetching
  • Loading branch information
cosa65 authored Sep 15, 2021
2 parents 172387d + 802847d commit 5039f75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/api/route-services/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ class ProjectsService {

let response = await dynamodb.scan(params).promise();

if (!response.Items.length) {
return [];
}

const extractProjectIds = (resp) => resp.Items.map(
(entry) => convertToJsObject(entry).projectId,
).filter((id) => id);
Expand All @@ -118,21 +114,29 @@ class ProjectsService {
projectIds = projectIds.concat(newProjectIds);
}

return this.getProjectsFromIds(new Set(projectIds));
// Remove duplicates (when we support multi experiment projects
// we might have repeated projectId's)
projectIds = [...new Set(projectIds)];

return this.getProjectsFromIds(projectIds);
}

/**
* Returns information about a group of projects.
*
* @param {Set} projectIds A Set of projectId values that are to be queried.
* @param {Array} projectIds A Array of projectId values that are to be queried.
* @returns An object containing descriptions of projects.
*/
async getProjectsFromIds(projectIds) {
if (projectIds.length === 0) {
return [];
}

const dynamodb = createDynamoDbInstance();
const params = {
RequestItems: {
[this.tableName]: {
Keys: [...projectIds].map((projectUuid) => convertToDynamoDbRecord({ projectUuid })),
Keys: projectIds.map((projectUuid) => convertToDynamoDbRecord({ projectUuid })),
},
},
};
Expand All @@ -144,9 +148,8 @@ class ProjectsService {
return newData.projects.uuid;
}));


// Build up projects that do not exist in Dynamo yet.
const projects = [...projectIds]
const projects = projectIds
.filter((entry) => (
!existingProjectIds.has(entry)
))
Expand Down
2 changes: 1 addition & 1 deletion tests/api/route-services/projects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('tests for the projects service', () => {
FilterExpression: 'attribute_exists(projectId) and contains(#rbac_can_write, :userId)',
ProjectionExpression: '#pid',
});
expect(projectService.getProjectsFromIds).toHaveBeenCalledWith(new Set(projectIdsArr));
expect(projectService.getProjectsFromIds).toHaveBeenCalledWith(projectIdsArr);
})
.then(() => done());
});
Expand Down

0 comments on commit 5039f75

Please sign in to comment.