mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 12:47:55 +00:00
Added all community endpoints
This commit is contained in:
@@ -6,31 +6,32 @@ import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { CommunitySpaceService } from '../services';
|
||||
import { CommunityPermissionGuard } from 'src/guards/community.permission.guard';
|
||||
|
||||
@ApiTags('Community Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: ControllerRoute.COMMUNITYSPACE.ROUTE,
|
||||
path: ControllerRoute.COMMUNITY_SPACE.ROUTE,
|
||||
})
|
||||
export class CommunitySpaceController {
|
||||
constructor(private readonly communitySpaceService: CommunitySpaceService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, CommunityPermissionGuard)
|
||||
@ApiOperation({
|
||||
summary:
|
||||
ControllerRoute.COMMUNITYSPACE.ACTIONS
|
||||
ControllerRoute.COMMUNITY_SPACE.ACTIONS
|
||||
.GET_COMMUNITY_SPACES_HIERARCHY_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.COMMUNITYSPACE.ACTIONS
|
||||
ControllerRoute.COMMUNITY_SPACE.ACTIONS
|
||||
.GET_COMMUNITY_SPACES_HIERARCHY_DESCRIPTION,
|
||||
})
|
||||
@Get('/:communityId')
|
||||
@Get()
|
||||
async getCommunityByUuid(
|
||||
@Param() params: GetCommunityParams,
|
||||
): Promise<BaseResponseDto> {
|
||||
return await this.communitySpaceService.getSpacesHierarchyForCommunity(
|
||||
params.communityId,
|
||||
params.communityUuid,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
@@ -13,18 +11,15 @@ import {
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import {
|
||||
AddCommunityDto,
|
||||
AddUserCommunityDto,
|
||||
} from '../dtos/add.community.dto';
|
||||
import { AddCommunityDto } from '../dtos/add.community.dto';
|
||||
import { GetCommunityParams } from '../dtos/get.community.dto';
|
||||
import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
||||
// 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 { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { PaginationRequestGetListDto } from '@app/common/dto/pagination.request.dto';
|
||||
import { CommunityPermissionGuard } from 'src/guards/community.permission.guard';
|
||||
|
||||
@ApiTags('Community Module')
|
||||
@Controller({
|
||||
@@ -48,17 +43,17 @@ export class CommunityController {
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, CommunityPermissionGuard)
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.COMMUNITY.ACTIONS.GET_COMMUNITY_BY_ID_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.COMMUNITY.ACTIONS.GET_COMMUNITY_BY_ID_DESCRIPTION,
|
||||
})
|
||||
@Get('/:communityId')
|
||||
@Get('/:communityUuid')
|
||||
async getCommunityByUuid(
|
||||
@Param() params: GetCommunityParams,
|
||||
): Promise<BaseResponseDto> {
|
||||
return await this.communityService.getCommunityById(params.communityId);
|
||||
return await this.communityService.getCommunityById(params.communityUuid);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@@ -75,25 +70,25 @@ export class CommunityController {
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, CommunityPermissionGuard)
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.COMMUNITY.ACTIONS.UPDATE_COMMUNITY_SUMMARY,
|
||||
description: ControllerRoute.COMMUNITY.ACTIONS.UPDATE_COMMUNITY_DESCRIPTION,
|
||||
})
|
||||
@Put('/:communityId')
|
||||
@Put('/:communityUuid')
|
||||
async updateCommunity(
|
||||
@Param() param: GetCommunityParams,
|
||||
@Body() updateCommunityDto: UpdateCommunityNameDto,
|
||||
) {
|
||||
return this.communityService.updateCommunity(
|
||||
param.communityId,
|
||||
param.communityUuid,
|
||||
updateCommunityDto,
|
||||
);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete('/:communityId')
|
||||
@Delete('/:communityUuid')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.COMMUNITY.ACTIONS.DELETE_COMMUNITY_SUMMARY,
|
||||
description: ControllerRoute.COMMUNITY.ACTIONS.DELETE_COMMUNITY_DESCRIPTION,
|
||||
@@ -101,39 +96,6 @@ export class CommunityController {
|
||||
async deleteCommunity(
|
||||
@Param() param: GetCommunityParams,
|
||||
): Promise<BaseResponseDto> {
|
||||
return this.communityService.deleteCommunity(param.communityId);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('user/:userUuid')
|
||||
async getCommunitiesByUserId(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
return await this.communityService.getCommunitiesByUserId(userUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard)
|
||||
@Post('user')
|
||||
async addUserCommunity(@Body() addUserCommunityDto: AddUserCommunityDto) {
|
||||
try {
|
||||
await this.communityService.addUserCommunity(addUserCommunityDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user community added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return this.communityService.deleteCommunity(param.communityUuid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user