diff --git a/src/history/dto/history-response.dto.ts b/src/history/dto/history-response.dto.ts index a28cc2c..83c6d0f 100644 --- a/src/history/dto/history-response.dto.ts +++ b/src/history/dto/history-response.dto.ts @@ -1,22 +1,11 @@ export type HistoryPointDto = { - t: number; - min: number; - avg: number; - max: number; - count: number; -}; - -export type HistorySeriesDto = { - edge: string; - tag: string; - points: HistoryPointDto[]; + time: Date; + min_value: number; + avg_value: number; + max_value: number; + point_count: number; }; export type HistoryResponseDto = { - edge: string; - tag: string; - from: Date; - to: Date; - granulate: string; - series: HistorySeriesDto[]; + rows: HistoryPointDto[]; }; diff --git a/src/history/history.mapper.ts b/src/history/history.mapper.ts deleted file mode 100644 index c481fab..0000000 --- a/src/history/history.mapper.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { HistoryResponseDto, HistorySeriesDto } from './dto/history-response.dto'; -import { HistoryRow } from './history.types'; - -type HistoryResponseOptions = { - edge: string; - tag: string; - from: Date; - to: Date; - granulate: string; - rows: HistoryRow[]; -}; - -/** Переводит строки агрегированной истории в формат графика min/avg/max. */ -export function createHistoryResponse(options: HistoryResponseOptions): HistoryResponseDto { - return { - edge: options.edge, - tag: options.tag, - from: options.from, - to: options.to, - granulate: options.granulate, - series: options.rows.length - ? [ - { - edge: options.edge, - tag: options.tag, - points: mapHistoryRowsToPoints(options.rows), - }, - ] - : [], - }; -} - -function mapHistoryRowsToPoints(rows: HistoryRow[]): HistorySeriesDto['points'] { - return rows.map((row) => ({ - t: row.time.getTime(), - min: row.min_value, - avg: row.avg_value, - max: row.max_value, - count: row.point_count, - })); -} diff --git a/src/history/history.service.ts b/src/history/history.service.ts index 8e80f85..a1c7719 100644 --- a/src/history/history.service.ts +++ b/src/history/history.service.ts @@ -1,7 +1,6 @@ import { BadRequestException, Injectable } from '@nestjs/common'; import { GetHistoryDto } from './dto/get-history.dto'; import { HistoryResponseDto } from './dto/history-response.dto'; -import { createHistoryResponse } from './history.mapper'; import { HistoryRepository } from './history.repository'; @Injectable() @@ -21,21 +20,7 @@ export class HistoryService { throw new BadRequestException('from cannot be greater than to.'); } - const rows = await this.repository.findBucketedRange( - query.edge, - query.tag, - from, - to, - query.granulate, - ); - - return createHistoryResponse({ - edge: query.edge, - tag: query.tag, - from, - to, - granulate: query.granulate, - rows, - }); + const rows = await this.repository.findBucketedRange(query.edge, query.tag, from, to, query.granulate); + return { rows }; } }