From 4744b0844c06ee54628c3c6137dbc429cda4cdec Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Wed, 8 Jan 2025 21:34:59 +0400 Subject: [PATCH] get space model by id --- libs/common/src/constants/controller-route.ts | 4 ++++ .../controllers/space-model.controller.ts | 13 +++++++++++++ src/space-model/services/space-model.service.ts | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/libs/common/src/constants/controller-route.ts b/libs/common/src/constants/controller-route.ts index 67a0085..4012c1a 100644 --- a/libs/common/src/constants/controller-route.ts +++ b/libs/common/src/constants/controller-route.ts @@ -292,6 +292,10 @@ export class ControllerRoute { public static readonly CREATE_SPACE_MODEL_DESCRIPTION = 'This endpoint allows you to create a new space model within a specified project. A space model defines the structure of spaces, including subspaces, products, and product items, and is uniquely identifiable within the project.'; + public static readonly GET_SPACE_MODEL_SUMMARY = 'Get a New Space Model'; + public static readonly GET_SPACE_MODEL_DESCRIPTION = + 'Fetch a space model details'; + public static readonly LIST_SPACE_MODEL_SUMMARY = 'List Space Models'; public static readonly LIST_SPACE_MODEL_DESCRIPTION = 'This endpoint allows you to retrieve a list of space models within a specified project. Each space model includes its structure, associated subspaces, products, and product items.'; diff --git a/src/space-model/controllers/space-model.controller.ts b/src/space-model/controllers/space-model.controller.ts index 5708e3f..57e2db6 100644 --- a/src/space-model/controllers/space-model.controller.ts +++ b/src/space-model/controllers/space-model.controller.ts @@ -66,6 +66,19 @@ export class SpaceModelController { return await this.spaceModelService.list(projectParam, query); } + @ApiBearerAuth() + @UseGuards(PermissionsGuard) + @Permissions('SPACE_MODEL_VIEW') + @ApiOperation({ + summary: ControllerRoute.SPACE_MODEL.ACTIONS.LIST_SPACE_MODEL_SUMMARY, + description: + ControllerRoute.SPACE_MODEL.ACTIONS.LIST_SPACE_MODEL_DESCRIPTION, + }) + @Get(':spaceModelUuid') + async get(@Param() param: SpaceModelParam): Promise { + return await this.spaceModelService.findOne(param); + } + @ApiBearerAuth() @UseGuards(PermissionsGuard) @Permissions('SPACE_MODEL_UPDATE') diff --git a/src/space-model/services/space-model.service.ts b/src/space-model/services/space-model.service.ts index 321e942..c7ad97a 100644 --- a/src/space-model/services/space-model.service.ts +++ b/src/space-model/services/space-model.service.ts @@ -323,6 +323,22 @@ export class SpaceModelService { } } + async findOne(params: SpaceModelParam): Promise { + try { + await this.validateProject(params.projectUuid); + const spaceModel = await this.validateSpaceModel(params.spaceModelUuid); + return new SuccessResponseDto({ + message: 'SpaceModel retrieved successfully', + data: spaceModel, + }); + } catch (error) { + throw new HttpException( + `Failed to retrieve space model ${error}`, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + async validateSpaceModel(uuid: string): Promise { const spaceModel = await this.spaceModelRepository.findOne({ where: {