updated endpoint of subspaces

This commit is contained in:
hannathkadher
2024-12-09 17:52:15 +04:00
parent dc9c67b6c0
commit 30c2294224
2 changed files with 30 additions and 37 deletions

View File

@ -220,7 +220,7 @@ export class ControllerRoute {
static SUBSPACE = class { static SUBSPACE = class {
public static readonly ROUTE = public static readonly ROUTE =
'/communities/:communityUuid/spaces/:spaceUuid/subspaces'; '/projects/:projectUuid/communities/:communityUuid/spaces/:spaceUuid/subspaces';
static ACTIONS = class { static ACTIONS = class {
public static readonly CREATE_SUBSPACE_SUMMARY = 'Create Subspace'; public static readonly CREATE_SUBSPACE_SUMMARY = 'Create Subspace';
public static readonly CREATE_SUBSPACE_DESCRIPTION = public static readonly CREATE_SUBSPACE_DESCRIPTION =

View File

@ -13,6 +13,7 @@ import {
} from '@app/common/models/typeOrmCustom.model'; } from '@app/common/models/typeOrmCustom.model';
import { PageResponse } from '@app/common/dto/pagination.response.dto'; import { PageResponse } from '@app/common/dto/pagination.response.dto';
import { SubspaceDto } from '@app/common/modules/space/dtos'; import { SubspaceDto } from '@app/common/modules/space/dtos';
import { SpaceService } from '../space.service';
@Injectable() @Injectable()
export class SubSpaceService { export class SubSpaceService {
@ -20,16 +21,18 @@ export class SubSpaceService {
private readonly spaceRepository: SpaceRepository, private readonly spaceRepository: SpaceRepository,
private readonly communityRepository: CommunityRepository, private readonly communityRepository: CommunityRepository,
private readonly subspaceRepository: SubspaceRepository, private readonly subspaceRepository: SubspaceRepository,
private readonly spaceService: SpaceService,
) {} ) {}
async createSubspace( async createSubspace(
addSubspaceDto: AddSubspaceDto, addSubspaceDto: AddSubspaceDto,
params: GetSpaceParam, params: GetSpaceParam,
): Promise<BaseResponseDto> { ): Promise<BaseResponseDto> {
const { communityUuid, spaceUuid } = params; const { communityUuid, spaceUuid, projectUuid } = params;
const space = await this.validateCommunityAndSpace( const space = await this.spaceService.validateCommunityAndSpace(
communityUuid, communityUuid,
spaceUuid, spaceUuid,
projectUuid,
); );
try { try {
@ -54,8 +57,12 @@ export class SubSpaceService {
params: GetSpaceParam, params: GetSpaceParam,
pageable: Partial<TypeORMCustomModelFindAllQuery>, pageable: Partial<TypeORMCustomModelFindAllQuery>,
): Promise<BaseResponseDto> { ): Promise<BaseResponseDto> {
const { communityUuid, spaceUuid } = params; const { communityUuid, spaceUuid, projectUuid } = params;
await this.validateCommunityAndSpace(communityUuid, spaceUuid); await this.spaceService.validateCommunityAndSpace(
communityUuid,
spaceUuid,
projectUuid,
);
try { try {
pageable.modelName = 'subspace'; pageable.modelName = 'subspace';
@ -74,8 +81,12 @@ export class SubSpaceService {
} }
async findOne(params: GetSubSpaceParam): Promise<BaseResponseDto> { async findOne(params: GetSubSpaceParam): Promise<BaseResponseDto> {
const { communityUuid, subSpaceUuid, spaceUuid } = params; const { communityUuid, subSpaceUuid, spaceUuid, projectUuid } = params;
await this.validateCommunityAndSpace(communityUuid, spaceUuid); await this.spaceService.validateCommunityAndSpace(
communityUuid,
spaceUuid,
projectUuid,
);
try { try {
const subSpace = await this.subspaceRepository.findOne({ const subSpace = await this.subspaceRepository.findOne({
where: { where: {
@ -110,8 +121,12 @@ export class SubSpaceService {
params: GetSubSpaceParam, params: GetSubSpaceParam,
updateSubSpaceDto: AddSubspaceDto, updateSubSpaceDto: AddSubspaceDto,
): Promise<BaseResponseDto> { ): Promise<BaseResponseDto> {
const { spaceUuid, communityUuid, subSpaceUuid } = params; const { spaceUuid, communityUuid, subSpaceUuid, projectUuid } = params;
await this.validateCommunityAndSpace(communityUuid, spaceUuid); await this.spaceService.validateCommunityAndSpace(
communityUuid,
spaceUuid,
projectUuid,
);
const subSpace = await this.subspaceRepository.findOne({ const subSpace = await this.subspaceRepository.findOne({
where: { uuid: subSpaceUuid }, where: { uuid: subSpaceUuid },
@ -146,8 +161,12 @@ export class SubSpaceService {
} }
async delete(params: GetSubSpaceParam): Promise<BaseResponseDto> { async delete(params: GetSubSpaceParam): Promise<BaseResponseDto> {
const { spaceUuid, communityUuid, subSpaceUuid } = params; const { spaceUuid, communityUuid, subSpaceUuid, projectUuid } = params;
await this.validateCommunityAndSpace(communityUuid, spaceUuid); await this.spaceService.validateCommunityAndSpace(
communityUuid,
spaceUuid,
projectUuid,
);
const subspace = await this.subspaceRepository.findOne({ const subspace = await this.subspaceRepository.findOne({
where: { uuid: subSpaceUuid }, 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;
}
} }