This commit is contained in:
marco committed 2026-10-26 14:56:24 +01:00
1 parent 367c93c93e
commit 4bfd5d9bf7
34 files changed
+558 -94

No files matched your search

+1 -1
View File
@@ -27,7 +27,7 @@ export class DrawDataDto {
name!:string;
height!: number;
width!:number;
varianten!: { state: 'inactive' | 'active' | 'error'; svg: string; xaml: string; xamlBase64: string }[];
varianten!: { state: string; svg: string; xaml: string; xamlBase64: string }[];
}
export class DrawShapeOptionenDto{
+32
View File
@@ -0,0 +1,32 @@
import { BadRequestException } from '@nestjs/common';
export interface PfeilVariant { name: string; state: 'active' | 'inactive' | 'error'; reverse?: boolean }
export interface PfeilConfig { points: { x: number; y: number }[]; variants?: PfeilVariant[] }
export interface PfeilOptions { colorInactive?: string; colorActive?: string; colorError?: string }
export function parsePfeilRequest(input: unknown): { config: PfeilConfig; options: PfeilOptions } {
const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === 'object' && !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 points = input.config.points;
if (Object.keys(input.config).some(key => !['points', 'variants'].includes(key)) || !Array.isArray(points) || points.length < 2 || points.length > 1000 ||
points.some(point => !object(point) || Object.keys(point).some(key => !['x', 'y'].includes(key)) ||
[point.x, point.y].some(value => typeof value !== 'number' || !Number.isFinite(value) || Math.abs(value) > 1000000)))
throw new BadRequestException('Pfeil benötigt 2 bis 1000 Punkte mit endlichen Koordinaten zwischen -1000000 und 1000000');
const typed = points as PfeilConfig['points'];
if (!typed.some(point => point.x !== typed[0].x || point.y !== typed[0].y))
throw new BadRequestException('Pfeil benötigt mindestens zwei unterschiedliche Punkte');
const variants = input.config.variants;
if (variants !== undefined && (!Array.isArray(variants) || !variants.length || variants.length > 100 || variants.some(variant =>
!object(variant) || Object.keys(variant).some(key => !['name', 'state', 'reverse'].includes(key)) ||
typeof variant.name !== 'string' || !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$/.test(variant.name) ||
!['active', 'inactive', 'error'].includes(String(variant.state)) ||
(variant.reverse !== undefined && typeof variant.reverse !== 'boolean')) ||
new Set(variants.map(variant => variant.name.toLowerCase())).size !== variants.length))
throw new BadRequestException('Varianten benötigen eindeutige Dateinamen (Buchstaben, Zahlen, _ und -), einen Grundzustand active/inactive/error und optional reverse');
const options = input.options ?? {};
if (!object(options) || Object.entries(options).some(([key, value]) =>
!['colorInactive', 'colorActive', 'colorError'].includes(key) || typeof value !== 'string' || !/^#[0-9a-fA-F]{6}$/.test(value)))
throw new BadRequestException('Pfeilfarben müssen Hexfarben #RRGGBB sein');
return { config: { points: typed.map(({ x, y }) => ({ x, y })), ...(variants !== undefined ? { variants: variants as PfeilVariant[] } : {}) }, options };
}