Skip to content

Commit

Permalink
filter out orphans for contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinyanakiev committed Aug 7, 2024
1 parent 4266f52 commit 0f5270d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alkemio-server",
"version": "0.86.0",
"version": "0.86.1",
"description": "Alkemio server, responsible for managing the shared Alkemio platform",
"author": "Alkemio Foundation",
"private": false,
Expand Down
38 changes: 25 additions & 13 deletions src/services/api/me/me.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
import { sortSpacesByActivity } from '@domain/space/space/sort.spaces.by.activity';
import { CommunityInvitationResult } from './dto/me.invitation.result';
import { CommunityResolverService } from '@services/infrastructure/entity-resolver/community.resolver.service';
import {
EntityNotFoundException,
RelationshipNotFoundException,
} from '@common/exceptions';
import { EntityNotFoundException } from '@common/exceptions';
import { CommunityApplicationResult } from './dto/me.application.result';
import { ContributorService } from '@domain/community/contributor/contributor.service';
import { UserService } from '@domain/community/user/user.service';
Expand Down Expand Up @@ -101,25 +98,40 @@ export class MeService {
const spaceIds = Array.from(credentialMap.get('spaces')?.keys() ?? []);

const allSpaces = await this.spaceService.getSpacesInList(spaceIds);
const validSpaces = this.filterValidSpaces(allSpaces);
const spaceMembershipCollaborationInfo =
this.getSpaceMembershipCollaborationInfo(validSpaces);
const latestActivitiesPerSpace =
await this.activityService.getLatestActivitiesPerSpaceMembership(
agentInfo.userID,
spaceMembershipCollaborationInfo
);
return sortSpacesByActivity(validSpaces, latestActivitiesPerSpace);
}

/**
* Function that returns all spaces that are valid (L1 and L2 spaces have parents)
* @param allSpaces all spaces to be filtered out
* @returns spaces that are valid (L1 and L2 spaces have parents).
* Orphaned spaces are logged as warnings and filtered out, also spaces without collaboration are filtered out.
*/
private filterValidSpaces(allSpaces: ISpace[]) {
const validSpaces = [];

for (const space of allSpaces) {
if (
(space.level !== SpaceLevel.SPACE && !space.parentSpace) ||
!space.collaboration
) {
throw new RelationshipNotFoundException(
this.logger.warn(
`Space ${space.id} is missing parent space or collaboration`,
LogContext.COMMUNITY
);
} else {
validSpaces.push(space);
}
}
const spaceMembershipCollaborationInfo =
this.getSpaceMembershipCollaborationInfo(allSpaces);
const latestActivitiesPerSpace =
await this.activityService.getLatestActivitiesPerSpaceMembership(
agentInfo.userID,
spaceMembershipCollaborationInfo
);
return sortSpacesByActivity(allSpaces, latestActivitiesPerSpace);
return validSpaces;
}

public async getSpaceMembershipsFlat(
Expand Down

0 comments on commit 0f5270d

Please sign in to comment.