From 8819adf42bd0f10d2e2017b493c8c3bcbd5e2f49 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: Sun, 21 Jun 2026 02:21:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=83=D1=8E=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D1=83=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8=20?= =?UTF-8?q?=D0=B2=20ingest.service.=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=BD=D0=B5=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B9=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B4=20normalizePoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ingest/ingest.service.ts | 37 ++++++------------------------------ 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/src/ingest/ingest.service.ts b/src/ingest/ingest.service.ts index dd575f4..19c2494 100644 --- a/src/ingest/ingest.service.ts +++ b/src/ingest/ingest.service.ts @@ -25,7 +25,12 @@ export class IngestService { this.assertBatchSize(points.length); - const normalized = points.map((point) => this.normalizePoint(point)); + const normalized: NormalizedPoint[] = points.map((point) => ({ + edge: point.edge, + tag: point.tag, + value: point.value, + time: new Date((point.time ?? point.timestamp) as string | number), + })); await this.db.query( ` @@ -88,34 +93,4 @@ export class IngestService { } } - /** Приводит входной DTO к нормализованному виду для вставки в history. */ - private normalizePoint(point: IngestPointDto): NormalizedPoint { - const time = this.parsePointTime(point); - - return { - edge: point.edge, - tag: point.tag, - value: point.value, - time, - }; - } - - /** Принимает ISO-время или миллисекунды Unix и отклоняет точки без валидного времени. */ - private parsePointTime(point: IngestPointDto): Date { - if (point.time) { - const date = new Date(point.time); - if (!Number.isNaN(date.getTime())) { - return date; - } - } - - if (point.timestamp !== undefined) { - const date = new Date(point.timestamp); - if (!Number.isNaN(date.getTime())) { - return date; - } - } - - throw new BadRequestException('Each point must contain valid time or timestamp.'); - } }