From 72756e4e0801f34a2f499cdc64175110700850ab Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:31:20 +0300 Subject: [PATCH] Add endpoint to get community child by UUID --- .../controllers/community.controller.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/community/controllers/community.controller.ts b/src/community/controllers/community.controller.ts index 127ea72..6b1a5a7 100644 --- a/src/community/controllers/community.controller.ts +++ b/src/community/controllers/community.controller.ts @@ -7,11 +7,13 @@ import { HttpStatus, Param, Post, + Query, UseGuards, } from '@nestjs/common'; import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard'; import { AddCommunityDto } from '../dtos/add.community.dto'; +import { GetCommunityChildDto } from '../dtos/get.community.dto'; @ApiTags('Community Module') @Controller({ @@ -55,4 +57,29 @@ export class CommunityController { } } } + + @ApiBearerAuth() + @UseGuards(JwtAuthGuard) + @Get('child/:communityUuid') + async getCommunityChildByUuid( + @Param('communityUuid') communityUuid: string, + @Query() query: GetCommunityChildDto, + ) { + try { + const community = await this.communityService.getCommunityChildByUuid( + communityUuid, + query, + ); + return community; + } catch (error) { + if (error.status === 404) { + throw new HttpException('Community not found', HttpStatus.NOT_FOUND); + } else { + throw new HttpException( + error.message || 'Internal server error', + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + } }