diff --git a/src/community/controllers/community.controller.ts b/src/community/controllers/community.controller.ts index c88acf1..af8d137 100644 --- a/src/community/controllers/community.controller.ts +++ b/src/community/controllers/community.controller.ts @@ -18,10 +18,10 @@ import { } from '../dtos/add.community.dto'; import { GetCommunityChildDto } from '../dtos/get.community.dto'; import { UpdateCommunityNameDto } from '../dtos/update.community.dto'; -import { CheckUserCommunityGuard } from 'src/guards/user.community.guard'; +// import { CheckUserCommunityGuard } from 'src/guards/user.community.guard'; import { AdminRoleGuard } from 'src/guards/admin.role.guard'; import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard'; -import { CommunityPermissionGuard } from 'src/guards/community.permission.guard'; +// import { CommunityPermissionGuard } from 'src/guards/community.permission.guard'; @ApiTags('Community Module') @Controller({ @@ -53,7 +53,7 @@ export class CommunityController { } @ApiBearerAuth() - @UseGuards(JwtAuthGuard, CommunityPermissionGuard) + @UseGuards(JwtAuthGuard) @Get(':communityUuid') async getCommunityByUuid(@Param('communityUuid') communityUuid: string) { try { @@ -67,9 +67,22 @@ export class CommunityController { ); } } - @ApiBearerAuth() - @UseGuards(JwtAuthGuard, CommunityPermissionGuard) + @UseGuards(JwtAuthGuard) + @Get() + async getCommunities() { + try { + const communities = await this.communityService.getCommunities(); + return communities; + } catch (error) { + throw new HttpException( + error.message || 'Internal server error', + error.status || HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + @ApiBearerAuth() + @UseGuards(JwtAuthGuard) @Get('child/:communityUuid') async getCommunityChildByUuid( @Param('communityUuid') communityUuid: string, @@ -103,7 +116,7 @@ export class CommunityController { } } @ApiBearerAuth() - @UseGuards(AdminRoleGuard, CheckUserCommunityGuard) + @UseGuards(AdminRoleGuard) @Post('user') async addUserCommunity(@Body() addUserCommunityDto: AddUserCommunityDto) { try { @@ -121,7 +134,7 @@ export class CommunityController { } } @ApiBearerAuth() - @UseGuards(JwtAuthGuard, CommunityPermissionGuard) + @UseGuards(JwtAuthGuard) @Put('rename/:communityUuid') async renameCommunityByUuid( @Param('communityUuid') communityUuid: string, diff --git a/src/community/interface/community.interface.ts b/src/community/interface/community.interface.ts index 31c0579..e65a053 100644 --- a/src/community/interface/community.interface.ts +++ b/src/community/interface/community.interface.ts @@ -24,3 +24,12 @@ export interface GetCommunityByUserUuidInterface { name: string; type: string; } +export interface Community { + uuid: string; + createdAt: Date; + updatedAt: Date; + name: string; + type: string; +} + +export interface GetCommunitiesInterface extends Array {} diff --git a/src/community/services/community.service.ts b/src/community/services/community.service.ts index 2476c25..27d7bcf 100644 --- a/src/community/services/community.service.ts +++ b/src/community/services/community.service.ts @@ -10,6 +10,7 @@ import { SpaceRepository } from '@app/common/modules/space/repositories'; import { AddCommunityDto, AddUserCommunityDto } from '../dtos'; import { CommunityChildInterface, + GetCommunitiesInterface, GetCommunityByUserUuidInterface, GetCommunityByUuidInterface, RenameCommunityByUuidInterface, @@ -79,6 +80,23 @@ export class CommunityService { } } } + async getCommunities(): Promise { + try { + const community = await this.spaceRepository.find({ + where: { spaceType: { type: 'community' } }, + relations: ['spaceType'], + }); + return community.map((community) => ({ + uuid: community.uuid, + createdAt: community.createdAt, + updatedAt: community.updatedAt, + name: community.spaceName, + type: community.spaceType.type, + })); + } catch (err) { + throw new HttpException(err.message, HttpStatus.INTERNAL_SERVER_ERROR); + } + } async getCommunityChildByUuid( communityUuid: string, getCommunityChildDto: GetCommunityChildDto,