Add endpoint to get community by UUID

This commit is contained in:
faris Aljohari
2024-04-01 00:04:38 +03:00
parent d765d090ea
commit ae8d909268
4 changed files with 71 additions and 0 deletions

View File

@ -2,8 +2,10 @@ import { CommunityService } from '../services/community.service';
import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Post,
UseGuards,
} from '@nestjs/common';
@ -33,4 +35,25 @@ export class CommunityController {
);
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':communityUuid')
async getCommunityByUuid(@Param('communityUuid') communityUuid: string) {
try {
const community =
await this.communityService.getCommunityByUuid(communityUuid);
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,
);
}
}
}
}