Add PowerClamp module with controller and service for energy data retrieval

This commit is contained in:
faris Aljohari
2025-04-14 12:17:44 +03:00
parent 5bc69f869d
commit 3745962827
11 changed files with 172 additions and 2 deletions

View File

@ -0,0 +1,28 @@
import { SQL_QUERIES_PATH } from '@app/common/constants/sql-query-path';
import { Injectable, Logger } from '@nestjs/common';
import { readFileSync } from 'fs';
import { join } from 'path';
@Injectable()
export class SqlLoaderService {
private readonly logger = new Logger(SqlLoaderService.name);
private readonly sqlRootPath = join(__dirname, '../sql/queries');
loadQuery(module: string, queryName: string): string {
const filePath = join(
process.cwd(),
SQL_QUERIES_PATH,
module,
`${queryName}.sql`,
);
try {
return readFileSync(filePath, 'utf8');
} catch (error) {
this.logger.error(
`Failed to load SQL query: ${module}/${queryName}`,
error.stack,
);
throw new Error(`SQL query not found: ${module}/${queryName}`);
}
}
}