mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 03:44:55 +00:00
updated group module
This commit is contained in:
@ -2,7 +2,6 @@ import { GroupService } from '../services/group.service';
|
|||||||
import { Controller, Get, UseGuards, Param, Req } from '@nestjs/common';
|
import { Controller, Get, UseGuards, Param, Req } from '@nestjs/common';
|
||||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||||
import { UnitPermissionGuard } from 'src/guards/unit.permission.guard';
|
|
||||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||||
|
|
||||||
@ApiTags('Group Module')
|
@ApiTags('Group Module')
|
||||||
@ -17,21 +16,21 @@ export class GroupController {
|
|||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':spaceUuid')
|
@Get(':spaceUuid')
|
||||||
async getGroupsBySpaceUuid(@Param('spaceUuid') spaceUuid: string) {
|
async getGroupsBySpaceUuid(@Param('spaceUuid') spaceUuid: string) {
|
||||||
return await this.groupService.getGroupsByUnitUuid(spaceUuid);
|
return await this.groupService.getGroupsBySpaceUuid(spaceUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':unitUuid/devices/:groupName')
|
@Get(':spaceUuid/devices/:groupName')
|
||||||
async getUnitDevicesByGroupName(
|
async getUnitDevicesByGroupName(
|
||||||
@Param('unitUuid') unitUuid: string,
|
@Param('spaceUuid') spaceUuid: string,
|
||||||
@Param('groupName') groupName: string,
|
@Param('groupName') groupName: string,
|
||||||
@Req() req: any,
|
@Req() req: any,
|
||||||
) {
|
) {
|
||||||
const userUuid = req.user.uuid;
|
const userUuid = req.user.uuid;
|
||||||
|
|
||||||
return await this.groupService.getUnitDevicesByGroupName(
|
return await this.groupService.getSpaceDevicesByGroupName(
|
||||||
unitUuid,
|
spaceUuid,
|
||||||
groupName,
|
groupName,
|
||||||
userUuid,
|
userUuid,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -27,11 +27,11 @@ export class GroupService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroupsByUnitUuid(unitUuid: string) {
|
async getGroupsBySpaceUuid(spaceUuid: string) {
|
||||||
try {
|
try {
|
||||||
const spaces = await this.spaceRepository.find({
|
const spaces = await this.spaceRepository.find({
|
||||||
where: {
|
where: {
|
||||||
uuid: unitUuid,
|
uuid: spaceUuid,
|
||||||
},
|
},
|
||||||
relations: ['devices', 'devices.productDevice'],
|
relations: ['devices', 'devices.productDevice'],
|
||||||
});
|
});
|
||||||
@ -61,23 +61,21 @@ export class GroupService {
|
|||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'This unit does not have any groups',
|
'This space does not have any groups',
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUnitDevicesByGroupName(
|
async getSpaceDevicesByGroupName(
|
||||||
unitUuid: string,
|
spaceUuid: string,
|
||||||
groupName: string,
|
groupName: string,
|
||||||
userUuid: string,
|
userUuid: string,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const spaces = await this.spaceRepository.find({
|
const spaces = await this.spaceRepository.find({
|
||||||
where: {
|
where: {
|
||||||
parent: {
|
uuid: spaceUuid,
|
||||||
uuid: unitUuid,
|
|
||||||
},
|
|
||||||
devices: {
|
devices: {
|
||||||
productDevice: {
|
productDevice: {
|
||||||
prodType: groupName,
|
prodType: groupName,
|
||||||
@ -122,8 +120,9 @@ export class GroupService {
|
|||||||
throw new HttpException('No devices found', HttpStatus.NOT_FOUND);
|
throw new HttpException('No devices found', HttpStatus.NOT_FOUND);
|
||||||
return devices.flat(); // Flatten the array since flatMap was used
|
return devices.flat(); // Flatten the array since flatMap was used
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'This unit does not have any devices for the specified group name',
|
'This space does not have any devices for the specified group name',
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -100,6 +100,7 @@ export class SpaceDeviceService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Exclude specific keys and add `productUuid`
|
// Exclude specific keys and add `productUuid`
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { uuid, ...rest } = camelCaseResponse;
|
const { uuid, ...rest } = camelCaseResponse;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
|||||||
Reference in New Issue
Block a user