mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-24 21:37:54 +00:00
Add PollutantType enum and update AQI-related entities and services to use it
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { PollutantType } from '@app/common/constants/pollutants.enum';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Matches, IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
@@ -16,8 +17,8 @@ export class GetAqiDailyBySpaceDto {
|
||||
export class GetAqiPollutantBySpaceDto {
|
||||
@ApiProperty({
|
||||
description: 'Pollutant Type',
|
||||
enum: ['aqi', 'pm25', 'pm10', 'voc', 'co2', 'ch2o'],
|
||||
example: 'aqi',
|
||||
enum: PollutantType,
|
||||
example: PollutantType.AQI,
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
|
||||
@@ -10,6 +10,7 @@ import { DataSource } from 'typeorm';
|
||||
import { SQL_PROCEDURES_PATH } from '@app/common/constants/sql-query-path';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import { PollutantType } from '@app/common/constants/pollutants.enum';
|
||||
|
||||
@Injectable()
|
||||
export class AqiService {
|
||||
@@ -24,15 +25,6 @@ export class AqiService {
|
||||
const { monthDate, pollutantType } = query;
|
||||
const { spaceUuid } = params;
|
||||
|
||||
// Validate pollutantType against the allowed values
|
||||
const allowedPollutants = ['aqi', 'pm25', 'pm10', 'voc', 'co2', 'ch2o'];
|
||||
if (!allowedPollutants.includes(pollutantType.toLowerCase())) {
|
||||
throw new HttpException(
|
||||
`Invalid pollutant type. Allowed values: ${allowedPollutants.join(', ')}`,
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await this.executeProcedure(
|
||||
'fact_daily_space_aqi',
|
||||
@@ -95,7 +87,7 @@ export class AqiService {
|
||||
);
|
||||
|
||||
// Define pollutants dynamically
|
||||
const pollutants = ['aqi', 'pm25', 'pm10', 'voc', 'co2', 'ch2o'];
|
||||
const pollutants = Object.values(PollutantType);
|
||||
|
||||
const transformedData = data.map((item) => {
|
||||
const date = new Date(item.event_date).toLocaleDateString('en-CA'); // YYYY-MM-DD
|
||||
|
||||
Reference in New Issue
Block a user