diff --git a/libs/common/src/constants/controller-route.ts b/libs/common/src/constants/controller-route.ts index 13a0dd3..be342a9 100644 --- a/libs/common/src/constants/controller-route.ts +++ b/libs/common/src/constants/controller-route.ts @@ -220,7 +220,7 @@ export class ControllerRoute { static SUBSPACE = class { public static readonly ROUTE = - '/communities/:communityUuid/spaces/:spaceUuid/subspaces'; + '/projects/:projectUuid/communities/:communityUuid/spaces/:spaceUuid/subspaces'; static ACTIONS = class { public static readonly CREATE_SUBSPACE_SUMMARY = 'Create Subspace'; public static readonly CREATE_SUBSPACE_DESCRIPTION = diff --git a/src/space/services/subspace/subspace.service.ts b/src/space/services/subspace/subspace.service.ts index 22c60ee..e99c928 100644 --- a/src/space/services/subspace/subspace.service.ts +++ b/src/space/services/subspace/subspace.service.ts @@ -13,6 +13,7 @@ import { } from '@app/common/models/typeOrmCustom.model'; import { PageResponse } from '@app/common/dto/pagination.response.dto'; import { SubspaceDto } from '@app/common/modules/space/dtos'; +import { SpaceService } from '../space.service'; @Injectable() export class SubSpaceService { @@ -20,16 +21,18 @@ export class SubSpaceService { private readonly spaceRepository: SpaceRepository, private readonly communityRepository: CommunityRepository, private readonly subspaceRepository: SubspaceRepository, + private readonly spaceService: SpaceService, ) {} async createSubspace( addSubspaceDto: AddSubspaceDto, params: GetSpaceParam, ): Promise { - const { communityUuid, spaceUuid } = params; - const space = await this.validateCommunityAndSpace( + const { communityUuid, spaceUuid, projectUuid } = params; + const space = await this.spaceService.validateCommunityAndSpace( communityUuid, spaceUuid, + projectUuid, ); try { @@ -54,8 +57,12 @@ export class SubSpaceService { params: GetSpaceParam, pageable: Partial, ): Promise { - const { communityUuid, spaceUuid } = params; - await this.validateCommunityAndSpace(communityUuid, spaceUuid); + const { communityUuid, spaceUuid, projectUuid } = params; + await this.spaceService.validateCommunityAndSpace( + communityUuid, + spaceUuid, + projectUuid, + ); try { pageable.modelName = 'subspace'; @@ -74,8 +81,12 @@ export class SubSpaceService { } async findOne(params: GetSubSpaceParam): Promise { - const { communityUuid, subSpaceUuid, spaceUuid } = params; - await this.validateCommunityAndSpace(communityUuid, spaceUuid); + const { communityUuid, subSpaceUuid, spaceUuid, projectUuid } = params; + await this.spaceService.validateCommunityAndSpace( + communityUuid, + spaceUuid, + projectUuid, + ); try { const subSpace = await this.subspaceRepository.findOne({ where: { @@ -110,8 +121,12 @@ export class SubSpaceService { params: GetSubSpaceParam, updateSubSpaceDto: AddSubspaceDto, ): Promise { - const { spaceUuid, communityUuid, subSpaceUuid } = params; - await this.validateCommunityAndSpace(communityUuid, spaceUuid); + const { spaceUuid, communityUuid, subSpaceUuid, projectUuid } = params; + await this.spaceService.validateCommunityAndSpace( + communityUuid, + spaceUuid, + projectUuid, + ); const subSpace = await this.subspaceRepository.findOne({ where: { uuid: subSpaceUuid }, @@ -146,8 +161,12 @@ export class SubSpaceService { } async delete(params: GetSubSpaceParam): Promise { - const { spaceUuid, communityUuid, subSpaceUuid } = params; - await this.validateCommunityAndSpace(communityUuid, spaceUuid); + const { spaceUuid, communityUuid, subSpaceUuid, projectUuid } = params; + await this.spaceService.validateCommunityAndSpace( + communityUuid, + spaceUuid, + projectUuid, + ); const subspace = await this.subspaceRepository.findOne({ where: { uuid: subSpaceUuid }, @@ -174,30 +193,4 @@ export class SubSpaceService { ); } } - - private async validateCommunityAndSpace( - communityUuid: string, - spaceUuid: string, - ) { - const community = await this.communityRepository.findOne({ - where: { uuid: communityUuid }, - }); - if (!community) { - throw new HttpException( - `Community with ID ${communityUuid} not found`, - HttpStatus.NOT_FOUND, - ); - } - - const space = await this.spaceRepository.findOne({ - where: { uuid: spaceUuid, community: { uuid: communityUuid } }, - }); - if (!space) { - throw new HttpException( - `Space with ID ${spaceUuid} not found`, - HttpStatus.NOT_FOUND, - ); - } - return space; - } }