mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
Add get Communities endpoint
This commit is contained in:
@ -18,10 +18,10 @@ import {
|
|||||||
} from '../dtos/add.community.dto';
|
} from '../dtos/add.community.dto';
|
||||||
import { GetCommunityChildDto } from '../dtos/get.community.dto';
|
import { GetCommunityChildDto } from '../dtos/get.community.dto';
|
||||||
import { UpdateCommunityNameDto } from '../dtos/update.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 { AdminRoleGuard } from 'src/guards/admin.role.guard';
|
||||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.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')
|
@ApiTags('Community Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -53,7 +53,7 @@ export class CommunityController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard, CommunityPermissionGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':communityUuid')
|
@Get(':communityUuid')
|
||||||
async getCommunityByUuid(@Param('communityUuid') communityUuid: string) {
|
async getCommunityByUuid(@Param('communityUuid') communityUuid: string) {
|
||||||
try {
|
try {
|
||||||
@ -67,9 +67,22 @@ export class CommunityController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@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')
|
@Get('child/:communityUuid')
|
||||||
async getCommunityChildByUuid(
|
async getCommunityChildByUuid(
|
||||||
@Param('communityUuid') communityUuid: string,
|
@Param('communityUuid') communityUuid: string,
|
||||||
@ -103,7 +116,7 @@ export class CommunityController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(AdminRoleGuard, CheckUserCommunityGuard)
|
@UseGuards(AdminRoleGuard)
|
||||||
@Post('user')
|
@Post('user')
|
||||||
async addUserCommunity(@Body() addUserCommunityDto: AddUserCommunityDto) {
|
async addUserCommunity(@Body() addUserCommunityDto: AddUserCommunityDto) {
|
||||||
try {
|
try {
|
||||||
@ -121,7 +134,7 @@ export class CommunityController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard, CommunityPermissionGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Put('rename/:communityUuid')
|
@Put('rename/:communityUuid')
|
||||||
async renameCommunityByUuid(
|
async renameCommunityByUuid(
|
||||||
@Param('communityUuid') communityUuid: string,
|
@Param('communityUuid') communityUuid: string,
|
||||||
|
@ -24,3 +24,12 @@ export interface GetCommunityByUserUuidInterface {
|
|||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
export interface Community {
|
||||||
|
uuid: string;
|
||||||
|
createdAt: Date;
|
||||||
|
updatedAt: Date;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetCommunitiesInterface extends Array<Community> {}
|
||||||
|
@ -10,6 +10,7 @@ import { SpaceRepository } from '@app/common/modules/space/repositories';
|
|||||||
import { AddCommunityDto, AddUserCommunityDto } from '../dtos';
|
import { AddCommunityDto, AddUserCommunityDto } from '../dtos';
|
||||||
import {
|
import {
|
||||||
CommunityChildInterface,
|
CommunityChildInterface,
|
||||||
|
GetCommunitiesInterface,
|
||||||
GetCommunityByUserUuidInterface,
|
GetCommunityByUserUuidInterface,
|
||||||
GetCommunityByUuidInterface,
|
GetCommunityByUuidInterface,
|
||||||
RenameCommunityByUuidInterface,
|
RenameCommunityByUuidInterface,
|
||||||
@ -79,6 +80,23 @@ export class CommunityService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async getCommunities(): Promise<GetCommunitiesInterface> {
|
||||||
|
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(
|
async getCommunityChildByUuid(
|
||||||
communityUuid: string,
|
communityUuid: string,
|
||||||
getCommunityChildDto: GetCommunityChildDto,
|
getCommunityChildDto: GetCommunityChildDto,
|
||||||
|
Reference in New Issue
Block a user