opc meldunge parameter fehler io
This commit is contained in:
1 parent
ee408475de
commit
3dc1ad623c
115 files changed
+5891
-13
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { SignalCreateDto } from "./signals";
|
||||
|
||||
export enum ComponentTypes {
|
||||
GENERAL = "Allgemein",
|
||||
UNKNOWN = "unknown",
|
||||
ANTRIEB = "Antrieb",
|
||||
FREQUENZUMRICHTER = "Frequenzumrichter",
|
||||
@@ -46,4 +47,4 @@ export class ComponentCreateDto {
|
||||
index?:number;
|
||||
type!: ComponentTypes;
|
||||
properties?: Record<string, unknown>;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { ComponentResponseDto } from "./components";
|
||||
|
||||
|
||||
export enum UnitTypeDto {
|
||||
GENERAL = 'Allgemein',
|
||||
BAND = 'Band',
|
||||
BRECHER = 'Brecher',
|
||||
WEICHE = 'Weiche',
|
||||
|
||||
@@ -31,6 +31,9 @@ export class DrawDataDto {
|
||||
}
|
||||
|
||||
export class DrawShapeOptionenDto{
|
||||
stroke?:string;
|
||||
strokeWidth?:number;
|
||||
fill?:string;
|
||||
scale?:number;
|
||||
raster?:number;
|
||||
angle?:number;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import type { RechteckConfig, RechteckOptions } from '../graphics/elements/types';
|
||||
export function parseRechteckRequest(input: unknown): { config: RechteckConfig; options: RechteckOptions } {
|
||||
const object=(v:unknown):v is Record<string,unknown>=>typeof v==='object'&&v!==null&&!Array.isArray(v);
|
||||
if(!object(input)||Object.keys(input).some(k=>!['config','options'].includes(k))||!object(input.config)||Object.keys(input.config).some(k=>!['width','height'].includes(k)))throw new BadRequestException('Rechteck erwartet config mit width und height sowie optional options');
|
||||
const width=input.config.width??100,height=input.config.height??50;
|
||||
if(typeof width!=='number'||typeof height!=='number'||![width,height].every(n=>Number.isFinite(n)&&n>0))throw new BadRequestException('Breite und Höhe müssen positive endliche Zahlen sein');
|
||||
const options=input.options===undefined?{}:input.options;
|
||||
if(!object(options)||Object.keys(options).some(k=>!['stroke','strokeWidth','fill'].includes(k)))throw new BadRequestException('Rechteck-options erlaubt stroke, strokeWidth und fill');
|
||||
const stroke=options.stroke??'#000000',fill=options.fill??'transparent',strokeWidth=options.strokeWidth??Math.min(1,width/4,height/4);
|
||||
if(typeof stroke!=='string'||!(stroke==='none'||/^#[0-9a-fA-F]{6}$/.test(stroke))||typeof fill!=='string'||!(fill==='transparent'||fill==='none'||/^#[0-9a-fA-F]{6}$/.test(fill)))throw new BadRequestException('Farben als #RRGGBB; Rahmen alternativ none, Füllung alternativ transparent');
|
||||
if(typeof strokeWidth!=='number'||!Number.isFinite(strokeWidth)||strokeWidth<0||stroke!=='none'&&strokeWidth>=Math.min(width,height))throw new BadRequestException('Rahmenstärke muss >= 0 und kleiner als Breite und Höhe sein');
|
||||
return {config:{width,height},options:{stroke,strokeWidth:stroke==='none'?0:strokeWidth,fill:fill==='none'?'transparent':fill}};
|
||||
}
|
||||
Reference in new issue
Block a user