Add PollutantType enum and update AQI-related entities and services to use it

This commit is contained in:
faris Aljohari
2025-06-11 00:28:00 -06:00
parent c86be27576
commit 2cb77504ca
5 changed files with 72 additions and 67 deletions
+3 -2
View File
@@ -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()
+2 -10
View File
@@ -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