mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-09 22:57:24 +00:00
Compare commits
1 Commits
5cf45c30f4
...
fix/commun
Author | SHA1 | Date | |
---|---|---|---|
85d9a59848 |
@ -207,7 +207,8 @@ export class CommunityService {
|
||||
|
||||
if (search) {
|
||||
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 } =
|
||||
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>(
|
||||
baseResponseDto,
|
||||
paginationResponseDto,
|
||||
);
|
||||
} catch (error) {
|
||||
// Generic error handling
|
||||
if (error instanceof HttpException) {
|
||||
throw error;
|
||||
}
|
||||
throw new HttpException(
|
||||
error.message || 'An error occurred while fetching communities.',
|
||||
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>();
|
||||
|
||||
// Step 1: Create a map of spaces by UUID
|
||||
|
Reference in New Issue
Block a user