From 37ea9420c86f13bad1123d13b140fdea2b77a4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B2=20=D0=90=D1=80=D1=82?= =?UTF-8?q?=D0=B5=D0=BC?= Date: Mon, 22 Jun 2026 03:20:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=88=D0=BD=D1=8E=D1=8E=20=D0=BD=D0=BE=D1=80=D0=BC=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8E=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B5=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BD=D0=B0=20ui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/history/dto/history-response.dto.ts | 23 ++++---------- src/history/history.mapper.ts | 41 ------------------------- src/history/history.service.ts | 19 ++---------- 3 files changed, 8 insertions(+), 75 deletions(-) delete mode 100644 src/history/history.mapper.ts 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 }; } }