mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { GroupService } from '../services/group.service';
|
|
import {
|
|
Controller,
|
|
Get,
|
|
UseGuards,
|
|
Param,
|
|
HttpException,
|
|
HttpStatus,
|
|
Req,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
|
import { UnitPermissionGuard } from 'src/guards/unit.permission.guard';
|
|
|
|
@ApiTags('Group Module')
|
|
@Controller({
|
|
version: '1',
|
|
path: 'group',
|
|
})
|
|
export class GroupController {
|
|
constructor(private readonly groupService: GroupService) {}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
|
@Get(':unitUuid')
|
|
async getGroupsBySpaceUuid(@Param('unitUuid') unitUuid: string) {
|
|
try {
|
|
return await this.groupService.getGroupsByUnitUuid(unitUuid);
|
|
} catch (error) {
|
|
throw new HttpException(
|
|
error.message || 'Internal server error',
|
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
);
|
|
}
|
|
}
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
|
@Get(':unitUuid/devices/:groupName')
|
|
async getUnitDevicesByGroupName(
|
|
@Param('unitUuid') unitUuid: string,
|
|
@Param('groupName') groupName: string,
|
|
@Req() req: any,
|
|
) {
|
|
try {
|
|
const userUuid = req.user.uuid;
|
|
|
|
return await this.groupService.getUnitDevicesByGroupName(
|
|
unitUuid,
|
|
groupName,
|
|
userUuid,
|
|
);
|
|
} catch (error) {
|
|
throw new HttpException(
|
|
error.message || 'Internal server error',
|
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
);
|
|
}
|
|
}
|
|
}
|