diff --git a/libs/common/src/constants/controller-route.ts b/libs/common/src/constants/controller-route.ts index be342a9..bd37317 100644 --- a/libs/common/src/constants/controller-route.ts +++ b/libs/common/src/constants/controller-route.ts @@ -246,7 +246,7 @@ export class ControllerRoute { static SUBSPACE_DEVICE = class { public static readonly ROUTE = - '/communities/:communityUuid/spaces/:spaceUuid/subspaces/:subSpaceUuid/devices'; + '/projects/:projectUuid/communities/:communityUuid/spaces/:spaceUuid/subspaces/:subSpaceUuid/devices'; static ACTIONS = class { public static readonly LIST_SUBSPACE_DEVICE_SUMMARY = diff --git a/src/space/services/subspace/subspace-device.service.ts b/src/space/services/subspace/subspace-device.service.ts index 74f6610..e773ea4 100644 --- a/src/space/services/subspace/subspace-device.service.ts +++ b/src/space/services/subspace/subspace-device.service.ts @@ -12,6 +12,7 @@ import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter'; import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service'; import { ProductRepository } from '@app/common/modules/product/repositories'; import { GetDeviceDetailsInterface } from '../../../device/interfaces/get.device.interface'; +import { SpaceService } from '../space.service'; @Injectable() export class SubspaceDeviceService { @@ -22,14 +23,19 @@ export class SubspaceDeviceService { private readonly deviceRepository: DeviceRepository, private readonly tuyaService: TuyaService, private readonly productRepository: ProductRepository, + private readonly spaceService: SpaceService, ) {} async listDevicesInSubspace( params: GetSubSpaceParam, ): Promise { - const { subSpaceUuid, spaceUuid, communityUuid } = params; + const { subSpaceUuid, spaceUuid, communityUuid, projectUuid } = params; - await this.validateCommunityAndSpace(communityUuid, spaceUuid); + await this.spaceService.validateCommunityAndSpace( + communityUuid, + spaceUuid, + projectUuid, + ); const subspace = await this.findSubspaceWithDevices(subSpaceUuid); @@ -67,9 +73,14 @@ export class SubspaceDeviceService { async associateDeviceToSubspace( params: DeviceSubSpaceParam, ): Promise { - const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid } = params; + const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid, projectUuid } = + params; try { - await this.validateCommunityAndSpace(communityUuid, spaceUuid); + await this.spaceService.validateCommunityAndSpace( + communityUuid, + spaceUuid, + projectUuid, + ); const subspace = await this.findSubspace(subSpaceUuid); const device = await this.findDevice(deviceUuid); @@ -97,9 +108,14 @@ export class SubspaceDeviceService { async disassociateDeviceFromSubspace( params: DeviceSubSpaceParam, ): Promise { - const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid } = params; + const { subSpaceUuid, deviceUuid, spaceUuid, communityUuid, projectUuid } = + params; try { - await this.validateCommunityAndSpace(communityUuid, spaceUuid); + await this.spaceService.validateCommunityAndSpace( + communityUuid, + spaceUuid, + projectUuid, + ); const subspace = await this.findSubspace(subSpaceUuid); const device = await this.findDevice(deviceUuid); @@ -129,26 +145,6 @@ export class SubspaceDeviceService { } } } - // Helper method to validate community and space - private async validateCommunityAndSpace( - communityUuid: string, - spaceUuid: string, - ) { - const community = await this.communityRepository.findOne({ - where: { uuid: communityUuid }, - }); - if (!community) { - this.throwNotFound('Community', communityUuid); - } - - const space = await this.spaceRepository.findOne({ - where: { uuid: spaceUuid, community: { uuid: communityUuid } }, - }); - if (!space) { - this.throwNotFound('Space', spaceUuid); - } - return space; - } // Helper method to find subspace with devices relation private async findSubspaceWithDevices(subSpaceUuid: string) { diff --git a/src/space/services/subspace/subspace.service.ts b/src/space/services/subspace/subspace.service.ts index e99c928..34f23d7 100644 --- a/src/space/services/subspace/subspace.service.ts +++ b/src/space/services/subspace/subspace.service.ts @@ -18,8 +18,6 @@ import { SpaceService } from '../space.service'; @Injectable() export class SubSpaceService { constructor( - private readonly spaceRepository: SpaceRepository, - private readonly communityRepository: CommunityRepository, private readonly subspaceRepository: SubspaceRepository, private readonly spaceService: SpaceService, ) {}