mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 12:24:54 +00:00
Merge pull request #328 from SyncrowIOT:bugfix/search-space-name
updated the search for commuities
This commit is contained in:
@ -13,8 +13,9 @@ import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
|||||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
import { ORPHAN_COMMUNITY_NAME } from '@app/common/constants/orphan-constant';
|
import { ORPHAN_COMMUNITY_NAME } from '@app/common/constants/orphan-constant';
|
||||||
import { ILike, Not } from 'typeorm';
|
import { ILike, In, Not } from 'typeorm';
|
||||||
import { SpaceService } from 'src/space/services';
|
import { SpaceService } from 'src/space/services';
|
||||||
|
import { SpaceRepository } from '@app/common/modules/space';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CommunityService {
|
export class CommunityService {
|
||||||
@ -23,6 +24,7 @@ export class CommunityService {
|
|||||||
private readonly projectRepository: ProjectRepository,
|
private readonly projectRepository: ProjectRepository,
|
||||||
private readonly spaceService: SpaceService,
|
private readonly spaceService: SpaceService,
|
||||||
private readonly tuyaService: TuyaService,
|
private readonly tuyaService: TuyaService,
|
||||||
|
private readonly spaceRepository: SpaceRepository,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async createCommunity(
|
async createCommunity(
|
||||||
@ -96,7 +98,36 @@ export class CommunityService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (pageable.search) {
|
if (pageable.search) {
|
||||||
pageable.where = { name: ILike(`%${pageable.search}%`) };
|
const matchingCommunities = await this.communityRepository.find({
|
||||||
|
where: {
|
||||||
|
project: { uuid: param.projectUuid },
|
||||||
|
name: ILike(`%${pageable.search}%`),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const matchingSpaces = await this.spaceRepository.find({
|
||||||
|
where: {
|
||||||
|
spaceName: ILike(`%${pageable.search}%`),
|
||||||
|
community: { project: { uuid: param.projectUuid } },
|
||||||
|
},
|
||||||
|
relations: ['community'],
|
||||||
|
});
|
||||||
|
|
||||||
|
const spaceCommunityUuids = [
|
||||||
|
...new Set(matchingSpaces.map((space) => space.community.uuid)),
|
||||||
|
];
|
||||||
|
|
||||||
|
const allMatchedCommunityUuids = [
|
||||||
|
...new Set([
|
||||||
|
...matchingCommunities.map((c) => c.uuid),
|
||||||
|
...spaceCommunityUuids,
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
|
||||||
|
pageable.where = {
|
||||||
|
...pageable.where,
|
||||||
|
uuid: In(allMatchedCommunityUuids),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const customModel = TypeORMCustomModel(this.communityRepository);
|
const customModel = TypeORMCustomModel(this.communityRepository);
|
||||||
|
|
||||||
@ -114,7 +145,6 @@ export class CommunityService {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
onlyWithDevices: false,
|
onlyWithDevices: false,
|
||||||
search: pageable.search,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user