added space model delete

This commit is contained in:
hannathkadher
2024-12-23 22:13:24 +04:00
parent 41c86b47eb
commit fef44b3c4f
5 changed files with 77 additions and 4 deletions
@@ -169,6 +169,58 @@ export class SpaceModelService {
}
}
async deleteSpaceModel(param: SpaceModelParam): Promise<BaseResponseDto> {
const queryRunner = this.dataSource.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
await this.validateProject(param.projectUuid);
const spaceModel = await this.validateSpaceModel(param.spaceModelUuid);
if (spaceModel.subspaceModels?.length) {
const deleteSubspaceDtos = spaceModel.subspaceModels.map(
(subspace) => ({
subspaceUuid: subspace.uuid,
}),
);
await this.subSpaceModelService.deleteSubspaceModels(
deleteSubspaceDtos,
queryRunner,
);
}
await queryRunner.manager.update(
this.spaceModelRepository.target,
{ uuid: param.spaceModelUuid },
{ disabled: true },
);
await queryRunner.commitTransaction();
return new SuccessResponseDto({
message: `SpaceModel with UUID ${param.spaceModelUuid} deleted successfully.`,
statusCode: HttpStatus.OK,
});
} catch (error) {
await queryRunner.rollbackTransaction();
const errorMessage =
error instanceof HttpException
? error.message
: 'An unexpected error occurred while deleting the SpaceModel';
const statusCode =
error instanceof HttpException
? error.getStatus()
: HttpStatus.INTERNAL_SERVER_ERROR;
throw new HttpException(errorMessage, statusCode);
} finally {
await queryRunner.release();
}
}
async validateName(modelName: string, projectUuid: string): Promise<void> {
const isModelExist = await this.spaceModelRepository.findOne({
where: { modelName, project: { uuid: projectUuid }, disabled: false },