mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 11:34:55 +00:00
updated endpoint of subspaces
This commit is contained in:
@ -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 =
|
||||
|
||||
@ -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<BaseResponseDto> {
|
||||
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<TypeORMCustomModelFindAllQuery>,
|
||||
): Promise<BaseResponseDto> {
|
||||
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<BaseResponseDto> {
|
||||
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<BaseResponseDto> {
|
||||
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<BaseResponseDto> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user