mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 18:44:54 +00:00
added space delete
This commit is contained in:
@ -58,7 +58,7 @@ export class SpaceService {
|
||||
projectUuid,
|
||||
);
|
||||
|
||||
this.validateSpaceCreation(spaceModelUuid);
|
||||
this.validateSpaceCreation(addSpaceDto, spaceModelUuid);
|
||||
|
||||
const parent = parentUuid
|
||||
? await this.validationService.validateSpace(parentUuid)
|
||||
@ -91,6 +91,7 @@ export class SpaceService {
|
||||
subspaces,
|
||||
newSpace,
|
||||
queryRunner,
|
||||
tags,
|
||||
);
|
||||
}
|
||||
|
||||
@ -189,6 +190,10 @@ export class SpaceService {
|
||||
}
|
||||
|
||||
async delete(params: GetSpaceParam): Promise<BaseResponseDto> {
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
try {
|
||||
const { communityUuid, spaceUuid, projectUuid } = params;
|
||||
|
||||
@ -205,14 +210,38 @@ export class SpaceService {
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
// Delete the space
|
||||
await this.spaceRepository.remove(space);
|
||||
|
||||
if (space.tags?.length) {
|
||||
const deleteSpaceTagsDtos = space.tags.map((tag) => tag.uuid);
|
||||
await this.tagService.deleteTags(deleteSpaceTagsDtos, queryRunner);
|
||||
}
|
||||
|
||||
if (space.subspaces?.length) {
|
||||
const deleteSubspaceDtos = space.subspaces.map((subspace) => ({
|
||||
subspaceUuid: subspace.uuid,
|
||||
}));
|
||||
|
||||
await this.subSpaceService.deleteSubspaces(
|
||||
deleteSubspaceDtos,
|
||||
queryRunner,
|
||||
);
|
||||
}
|
||||
|
||||
await queryRunner.manager.update(
|
||||
this.spaceRepository.target,
|
||||
{ uuid: params.spaceUuid },
|
||||
{ disabled: true },
|
||||
);
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
return new SuccessResponseDto({
|
||||
message: `Space with ID ${spaceUuid} successfully deleted`,
|
||||
statusCode: HttpStatus.OK,
|
||||
});
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
|
||||
if (error instanceof HttpException) {
|
||||
throw error;
|
||||
}
|
||||
@ -220,6 +249,8 @@ export class SpaceService {
|
||||
'An error occurred while deleting the space',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -384,8 +415,11 @@ export class SpaceService {
|
||||
return rootSpaces;
|
||||
}
|
||||
|
||||
private validateSpaceCreation(spaceModelUuid?: string) {
|
||||
if (spaceModelUuid) {
|
||||
private validateSpaceCreation(
|
||||
addSpaceDto: AddSpaceDto,
|
||||
spaceModelUuid?: string,
|
||||
) {
|
||||
if (spaceModelUuid && (addSpaceDto.tags || addSpaceDto.subspaces)) {
|
||||
throw new HttpException(
|
||||
'For space creation choose either space model or products and subspace',
|
||||
HttpStatus.CONFLICT,
|
||||
|
||||
Reference in New Issue
Block a user