diff --git a/README.md b/README.md index 03c4403..acf07e8 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Historical chart ranges use continuous aggregates: { "edge": "edge5", "tag": "hook_weight_1", - "time": "2026-06-19T00:00:00Z", + "timestamp": "2026-06-19T00:00:00Z", "value": 12.34 } ``` @@ -51,7 +51,7 @@ Historical chart ranges use continuous aggregates: ```json { - "time": "2026-06-19T00:00:00Z", + "timestamp": "2026-06-19T00:00:00Z", "values": { "hook_weight_1": 12.34, "rotary_rpm": 80 diff --git a/src/ingest/dto/ingest-edge-values.dto.ts b/src/ingest/dto/ingest-edge-values.dto.ts index dbe180a..fabdd5a 100644 --- a/src/ingest/dto/ingest-edge-values.dto.ts +++ b/src/ingest/dto/ingest-edge-values.dto.ts @@ -1,15 +1,8 @@ -import { Type } from 'class-transformer'; -import { IsDateString, IsNumber, IsObject, IsOptional } from 'class-validator'; +import { IsDateString, IsObject } from 'class-validator'; export class IngestEdgeValuesDto { - @IsOptional() @IsDateString() - time?: string; - - @IsOptional() - @Type(() => Number) - @IsNumber() - timestamp?: number; + timestamp!: string; @IsObject() values!: Record; diff --git a/src/ingest/dto/ingest-point.dto.ts b/src/ingest/dto/ingest-point.dto.ts index b51de41..8d1d7c4 100644 --- a/src/ingest/dto/ingest-point.dto.ts +++ b/src/ingest/dto/ingest-point.dto.ts @@ -1,5 +1,5 @@ import { Type } from 'class-transformer'; -import { IsDateString, IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator'; +import { IsDateString, IsNotEmpty, IsNumber, IsString } from 'class-validator'; export class IngestPointDto { @IsNotEmpty() @@ -10,14 +10,8 @@ export class IngestPointDto { @IsString() tag!: string; - @IsOptional() @IsDateString() - time?: string; - - @IsOptional() - @Type(() => Number) - @IsNumber() - timestamp?: number; + timestamp!: string; @Type(() => Number) @IsNumber() diff --git a/src/ingest/ingest.controller.ts b/src/ingest/ingest.controller.ts index 02d25e4..befcc55 100644 --- a/src/ingest/ingest.controller.ts +++ b/src/ingest/ingest.controller.ts @@ -22,7 +22,6 @@ export class IngestController { edge, tag, value: Number(value), - time: body.time, timestamp: body.timestamp, })); diff --git a/src/ingest/ingest.service.ts b/src/ingest/ingest.service.ts index e44a44f..c93e337 100644 --- a/src/ingest/ingest.service.ts +++ b/src/ingest/ingest.service.ts @@ -2,13 +2,6 @@ import { Injectable } from '@nestjs/common'; import { DbService } from '../db/db.service'; import { IngestPointDto } from './dto/ingest-point.dto'; -type NormalizedPoint = { - time: Date; - edge: string; - tag: string; - value: number; -}; - type IngestResult = { processed: number; }; @@ -17,21 +10,14 @@ type IngestResult = { export class IngestService { constructor(private readonly db: DbService) {} - /** Пишет одну сырую точку в history и обновляет текущий снимок current для UI/SSE. */ + /** Пишет одну входящую точку в history и обновляет текущий снимок current для UI/SSE. */ async ingestPoint(point: IngestPointDto): Promise { - const normalized: NormalizedPoint = { - edge: point.edge, - tag: point.tag, - value: point.value, - time: new Date((point.time ?? point.timestamp) as string | number), - }; - await this.db.query( ` INSERT INTO history (timestamp, edge, tag, value) VALUES ($1, $2, $3, $4) `, - [normalized.time, normalized.edge, normalized.tag, normalized.value], + [point.timestamp, point.edge, point.tag, point.value], ); await this.db.query( @@ -43,7 +29,7 @@ export class IngestService { value = $3, "updatedAt" = NOW() `, - [normalized.edge, normalized.tag, normalized.value], + [point.edge, point.tag, point.value], ); return { processed: 1 };