fix: spaces structure in communities (#420)

This commit is contained in:
ZaydSkaff
2025-06-23 10:21:55 +03:00
committed by GitHub
parent 110ed4157a
commit 3160773c2a
2 changed files with 13 additions and 2 deletions

View File

@ -207,7 +207,8 @@ export class CommunityService {
if (search) { if (search) {
qb.andWhere( qb.andWhere(
`c.name ILIKE '%${search}%' ${includeSpaces ? "OR space.space_name ILIKE '%" + search + "%'" : ''}`, `c.name ILIKE :search ${includeSpaces ? 'OR space.space_name ILIKE :search' : ''}`,
{ search: `%${search}%` },
); );
} }
@ -215,12 +216,22 @@ export class CommunityService {
const { baseResponseDto, paginationResponseDto } = const { baseResponseDto, paginationResponseDto } =
await customModel.findAll({ ...pageable, modelName: 'community' }, qb); await customModel.findAll({ ...pageable, modelName: 'community' }, qb);
if (includeSpaces) {
baseResponseDto.data = baseResponseDto.data.map((community) => ({
...community,
spaces: this.spaceService.buildSpaceHierarchy(community.spaces || []),
}));
}
return new PageResponse<CommunityDto>( return new PageResponse<CommunityDto>(
baseResponseDto, baseResponseDto,
paginationResponseDto, paginationResponseDto,
); );
} catch (error) { } catch (error) {
// Generic error handling // Generic error handling
if (error instanceof HttpException) {
throw error;
}
throw new HttpException( throw new HttpException(
error.message || 'An error occurred while fetching communities.', error.message || 'An error occurred while fetching communities.',
HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,

View File

@ -681,7 +681,7 @@ export class SpaceService {
} }
} }
private buildSpaceHierarchy(spaces: SpaceEntity[]): SpaceEntity[] { buildSpaceHierarchy(spaces: SpaceEntity[]): SpaceEntity[] {
const map = new Map<string, SpaceEntity>(); const map = new Map<string, SpaceEntity>();
// Step 1: Create a map of spaces by UUID // Step 1: Create a map of spaces by UUID