mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 23:44:55 +00:00
merge dev to main
This commit is contained in:
@ -1,6 +1,23 @@
|
||||
import { IsUUID } from 'class-validator';
|
||||
import { IsNotEmpty, IsOptional, IsUUID, ValidateIf } from 'class-validator';
|
||||
|
||||
export class PowerClampParamsDto {
|
||||
@IsUUID('4', { message: 'Invalid UUID format' })
|
||||
powerClampUuid: string;
|
||||
}
|
||||
export class SpaceParamsDto {
|
||||
@IsUUID('4', { message: 'Invalid UUID format' })
|
||||
spaceUuid: string;
|
||||
}
|
||||
export class ResourceParamsDto {
|
||||
@IsUUID('4', { message: 'Invalid UUID format' })
|
||||
@IsOptional()
|
||||
spaceUuid?: string;
|
||||
|
||||
@IsUUID('4', { message: 'Invalid UUID format' })
|
||||
@IsOptional()
|
||||
communityUuid?: string;
|
||||
|
||||
@ValidateIf((o) => !o.spaceUuid && !o.communityUuid)
|
||||
@IsNotEmpty({ message: 'Either spaceUuid or communityUuid must be provided' })
|
||||
requireEither?: never; // This ensures at least one of them is provided
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ import { AqiDataService } from '@app/common/helper/services/aqi.data.service';
|
||||
imports: [ConfigModule],
|
||||
controllers: [PowerClampController],
|
||||
providers: [
|
||||
PowerClampService,
|
||||
PowerClamp,
|
||||
PowerClampDailyRepository,
|
||||
PowerClampHourlyRepository,
|
||||
PowerClampMonthlyRepository,
|
||||
|
||||
@ -1,13 +1,32 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { GetPowerClampDto } from '../dto/get-power-clamp.dto';
|
||||
import {
|
||||
BadRequestException,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Injectable,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
GetPowerClampBySpaceDto,
|
||||
GetPowerClampDto,
|
||||
} from '../dto/get-power-clamp.dto';
|
||||
import {
|
||||
PowerClampDailyRepository,
|
||||
PowerClampHourlyRepository,
|
||||
PowerClampMonthlyRepository,
|
||||
} from '@app/common/modules/power-clamp/repositories';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { PowerClampParamsDto } from '../dto/power-clamp-params.dto';
|
||||
import {
|
||||
PowerClampParamsDto,
|
||||
ResourceParamsDto,
|
||||
} from '../dto/power-clamp-params.dto';
|
||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||
import { SpaceDeviceService } from 'src/space/services';
|
||||
import { SqlLoaderService } from '@app/common/helper/services/sql-loader.service';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { SQL_PROCEDURES_PATH } from '@app/common/constants/sql-query-path';
|
||||
import { ProductType } from '@app/common/constants/product-type.enum';
|
||||
import { CommunityService } from 'src/community/services';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { filterByMonth, toMMYYYY } from '@app/common/helper/date-format';
|
||||
|
||||
@Injectable()
|
||||
export class PowerClampService {
|
||||
@ -210,4 +229,17 @@ export class PowerClampService {
|
||||
statusCode: HttpStatus.OK,
|
||||
});
|
||||
}
|
||||
private async executeProcedure(
|
||||
procedureFileName: string,
|
||||
params: (string | number | null)[],
|
||||
): Promise<any[]> {
|
||||
const query = this.loadQuery(
|
||||
'fact_space_energy_consumed',
|
||||
procedureFileName,
|
||||
);
|
||||
return await this.dataSource.query(query, params);
|
||||
}
|
||||
private loadQuery(folderName: string, fileName: string): string {
|
||||
return this.sqlLoader.loadQuery(folderName, fileName, SQL_PROCEDURES_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { GetSpaceParam } from '../dtos';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
@ -21,6 +26,7 @@ export class SpaceDeviceService {
|
||||
private readonly tuyaService: TuyaService,
|
||||
private readonly validationService: ValidationService,
|
||||
private readonly deviceService: DeviceService,
|
||||
private readonly spaceRepository: SpaceRepository,
|
||||
) {}
|
||||
|
||||
async listDevicesInSpace(
|
||||
|
||||
Reference in New Issue
Block a user