mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
fix: spaces structure in communities (#420)
This commit is contained in:
@ -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,
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user