updated group module

This commit is contained in:
hannathkadher
2024-11-04 20:57:32 +04:00
parent 6e2f3bb8b6
commit 0d000e4b60
3 changed files with 15 additions and 16 deletions

View File

@ -2,7 +2,6 @@ import { GroupService } from '../services/group.service';
import { Controller, Get, UseGuards, Param, 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';
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
@ApiTags('Group Module')
@ -17,21 +16,21 @@ export class GroupController {
@UseGuards(JwtAuthGuard)
@Get(':spaceUuid')
async getGroupsBySpaceUuid(@Param('spaceUuid') spaceUuid: string) {
return await this.groupService.getGroupsByUnitUuid(spaceUuid);
return await this.groupService.getGroupsBySpaceUuid(spaceUuid);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':unitUuid/devices/:groupName')
@Get(':spaceUuid/devices/:groupName')
async getUnitDevicesByGroupName(
@Param('unitUuid') unitUuid: string,
@Param('spaceUuid') spaceUuid: string,
@Param('groupName') groupName: string,
@Req() req: any,
) {
const userUuid = req.user.uuid;
return await this.groupService.getUnitDevicesByGroupName(
unitUuid,
return await this.groupService.getSpaceDevicesByGroupName(
spaceUuid,
groupName,
userUuid,
);

View File

@ -27,11 +27,11 @@ export class GroupService {
});
}
async getGroupsByUnitUuid(unitUuid: string) {
async getGroupsBySpaceUuid(spaceUuid: string) {
try {
const spaces = await this.spaceRepository.find({
where: {
uuid: unitUuid,
uuid: spaceUuid,
},
relations: ['devices', 'devices.productDevice'],
});
@ -61,23 +61,21 @@ export class GroupService {
);
} catch (error) {
throw new HttpException(
'This unit does not have any groups',
'This space does not have any groups',
HttpStatus.NOT_FOUND,
);
}
}
async getUnitDevicesByGroupName(
unitUuid: string,
async getSpaceDevicesByGroupName(
spaceUuid: string,
groupName: string,
userUuid: string,
) {
try {
const spaces = await this.spaceRepository.find({
where: {
parent: {
uuid: unitUuid,
},
uuid: spaceUuid,
devices: {
productDevice: {
prodType: groupName,
@ -122,8 +120,9 @@ export class GroupService {
throw new HttpException('No devices found', HttpStatus.NOT_FOUND);
return devices.flat(); // Flatten the array since flatMap was used
} catch (error) {
console.log(error);
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,
);
}

View File

@ -100,6 +100,7 @@ export class SpaceDeviceService {
});
// Exclude specific keys and add `productUuid`
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { uuid, ...rest } = camelCaseResponse;
return {
...rest,