Add endpoint to get community child by UUID

This commit is contained in:
faris Aljohari
2024-04-02 17:31:20 +03:00
parent ca5d67e291
commit 72756e4e08

View File

@ -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,
);
}
}
}
}