Files
backend/src/power-clamp/controllers/power-clamp.controller.ts
faris Aljohari 45b8cdcaae Add endpoints and logic for fetching power clamp data by community or space
- Introduced new API endpoints to retrieve power clamp historical data based on community or space UUID.
- Updated PowerClampController to handle requests with optional parameters for community and space.
- Enhanced PowerClampService to validate input and fetch devices accordingly.
- Created ResourceParamsDto to manage request parameters.
- Updated ControllerRoute with new action summaries and descriptions.
2025-05-07 23:09:01 +03:00

80 lines
2.3 KiB
TypeScript

import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
import {
ApiTags,
ApiBearerAuth,
ApiOperation,
ApiParam,
ApiQuery,
} from '@nestjs/swagger';
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
import { ControllerRoute } from '@app/common/constants/controller-route';
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
import { PowerClampService } from '../services/power-clamp.service';
import {
GetPowerClampBySpaceDto,
GetPowerClampDto,
} from '../dto/get-power-clamp.dto';
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import {
PowerClampParamsDto,
ResourceParamsDto,
} from '../dto/power-clamp-params.dto';
@ApiTags('Power Clamp Module')
@Controller({
version: EnableDisableStatusEnum.ENABLED,
path: ControllerRoute.PowerClamp.ROUTE,
})
export class PowerClampController {
constructor(private readonly powerClampService: PowerClampService) {}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':powerClampUuid/historical')
@ApiOperation({
summary: ControllerRoute.PowerClamp.ACTIONS.GET_ENERGY_SUMMARY,
description: ControllerRoute.PowerClamp.ACTIONS.GET_ENERGY_DESCRIPTION,
})
@ApiParam({
name: 'powerClampUuid',
description: 'UUID of the Power Clamp device',
required: true,
})
async getPowerClampData(
@Param() params: PowerClampParamsDto,
@Query() query: GetPowerClampDto,
): Promise<BaseResponseDto> {
return await this.powerClampService.getPowerClampData(params, query);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('historical')
@ApiOperation({
summary:
ControllerRoute.PowerClamp.ACTIONS
.GET_ENERGY_BY_COMMUNITY_OR_SPACE_SUMMARY,
description:
ControllerRoute.PowerClamp.ACTIONS
.GET_ENERGY_BY_COMMUNITY_OR_SPACE_DESCRIPTION,
})
@ApiQuery({
name: 'spaceUuid',
description: 'UUID of the Space',
required: false,
})
@ApiQuery({
name: 'communityUuid',
description: 'UUID of the Community',
required: false,
})
async getPowerClampDataBySpaceOrCommunity(
@Query() params: ResourceParamsDto,
@Query() query: GetPowerClampBySpaceDto,
): Promise<BaseResponseDto> {
return await this.powerClampService.getPowerClampDataBySpaceOrCommunity(
params,
query,
);
}
}