sensorDigital, grafik Fest, drawPunkt eingefügt

This commit is contained in:
marco committed 2026-10-28 09:23:01 +01:00
1 parent f43053d7b3
commit 6e4bd5339f
51 files changed
+1203 -31

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import { BadRequestException } from '@nestjs/common';
import type { PunktConfig, PunktOptions } from '../graphics/elements/types';
export class PunktRenderDto {
config!: PunktConfig;
options?: Partial<PunktOptions>;
}
export function parsePunktRequest(input: unknown): PunktRenderDto {
const object = (value: unknown): value is Record<string, unknown> =>
typeof value === 'object' && value !== null && !Array.isArray(value);
if (!object(input) || Object.keys(input).some(key => !['config', 'options'].includes(key)) || !object(input.config))
throw new BadRequestException('Erwartet werden config und optional options');
const config = input.config;
if (Object.keys(config).some(key => !['scale', 'raster'].includes(key)))
throw new BadRequestException('Punkt-config erlaubt nur scale und raster');
const scale = config.scale ?? 2, raster = config.raster ?? 4;
if (typeof scale !== 'number' ||
!Number.isFinite(scale) ||
scale <= 0 ||
typeof raster !== 'number' ||
!Number.isFinite(raster) ||
raster <= 0 ||
!Number.isFinite(3 * scale * raster)
)
throw new BadRequestException('scale und raster müssen positive endliche Zahlen sein');
const options = input.options === undefined ? {} : input.options;
if (!object(options) ||
Object.entries(options).some(([key, value]) => !['colorInactive', 'colorActive'].includes(key) ||
typeof value !== 'string' || !/^#[0-9a-fA-F]{6}$/.test(value))
)
throw new BadRequestException('Punkt-options erlaubt colorInactive, colorActive als Hexfarbe #RRGGBB');
return { config: { scale, raster }, options: options as Partial<PunktOptions> };
}