mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 07:34:54 +00:00
Add PowerClamp module with controller and service for energy data retrieval
This commit is contained in:
@ -31,6 +31,7 @@ import { PrivacyPolicyModule } from './privacy-policy/privacy-policy.module';
|
||||
import { TagModule } from './tags/tags.module';
|
||||
import { ClientModule } from './client/client.module';
|
||||
import { DeviceCommissionModule } from './commission-device/commission-device.module';
|
||||
import { PowerClampModule } from './power-clamp/power-clamp.module';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
@ -64,8 +65,8 @@ import { DeviceCommissionModule } from './commission-device/commission-device.mo
|
||||
TermsConditionsModule,
|
||||
PrivacyPolicyModule,
|
||||
TagModule,
|
||||
|
||||
DeviceCommissionModule,
|
||||
PowerClampModule,
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
|
||||
1
src/power-clamp/controllers/index.ts
Normal file
1
src/power-clamp/controllers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './power-clamp.controller';
|
||||
26
src/power-clamp/controllers/power-clamp.controller.ts
Normal file
26
src/power-clamp/controllers/power-clamp.controller.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } 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';
|
||||
|
||||
@ApiTags('Power Clamp Module')
|
||||
@Controller({
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: ControllerRoute.PowerClamp.ROUTE,
|
||||
})
|
||||
export class PowerClampController {
|
||||
constructor(private readonly powerClampService: PowerClampService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.PowerClamp.ACTIONS.GET_ENERGY_SUMMARY,
|
||||
description: ControllerRoute.PowerClamp.ACTIONS.GET_ENERGY_DESCRIPTION,
|
||||
})
|
||||
async getPowerClampData() {
|
||||
return await this.powerClampService.getPowerClampData();
|
||||
}
|
||||
}
|
||||
12
src/power-clamp/power-clamp.module.ts
Normal file
12
src/power-clamp/power-clamp.module.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { PowerClampService } from './services/power-clamp.service';
|
||||
import { PowerClampController } from './controllers';
|
||||
import { SqlLoaderService } from '@app/common/helper/services/sql-loader.service';
|
||||
@Module({
|
||||
imports: [ConfigModule],
|
||||
controllers: [PowerClampController],
|
||||
providers: [PowerClampService, SqlLoaderService],
|
||||
exports: [PowerClampService],
|
||||
})
|
||||
export class PowerClampModule {}
|
||||
1
src/power-clamp/services/index.ts
Normal file
1
src/power-clamp/services/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './power-clamp.service';
|
||||
27
src/power-clamp/services/power-clamp.service.ts
Normal file
27
src/power-clamp/services/power-clamp.service.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { SqlLoaderService } from '@app/common/helper/services/sql-loader.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class PowerClampService {
|
||||
constructor(
|
||||
private readonly sqlLoader: SqlLoaderService,
|
||||
private readonly dataSource: DataSource,
|
||||
) {}
|
||||
|
||||
async getPowerClampData() {
|
||||
const sql = this.sqlLoader.loadQuery(
|
||||
'power-clamp',
|
||||
'fact_daily_energy_consumed',
|
||||
);
|
||||
return this.dataSource.manager.query(sql);
|
||||
}
|
||||
|
||||
async getEnergyConsumed(code: string) {
|
||||
const sql = this.sqlLoader.loadQuery(
|
||||
'energy',
|
||||
'energy_consumed_with_params',
|
||||
);
|
||||
return this.dataSource.manager.query(sql, [code]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user