diverse änderungen
This commit is contained in:
1 parent
3dc1ad623c
commit
f51631100d
85 files changed
+1880
-56
No files matched your search
@@ -31,6 +31,10 @@ export class DrawDataDto {
|
||||
}
|
||||
|
||||
export class DrawShapeOptionenDto{
|
||||
text?: string;
|
||||
fontSize?: number;
|
||||
frame?: boolean;
|
||||
direction?: 'oben' | 'unten' | 'rechts' | 'links';
|
||||
stroke?:string;
|
||||
strokeWidth?:number;
|
||||
fill?:string;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import { parseMotorRequest } from './motor.dto';
|
||||
import type { EndschalterDirection } from '../graphics/elements/types';
|
||||
|
||||
export function parseEndschalterRequest(input: unknown) {
|
||||
if (!input || typeof input !== 'object' || Array.isArray(input)) {
|
||||
throw new BadRequestException('Erwartet werden config und optional options');
|
||||
}
|
||||
const request = input as Record<string, unknown>;
|
||||
const options = request.options === undefined ? {} : request.options;
|
||||
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
||||
throw new BadRequestException('Endschalter-options muss ein Objekt sein');
|
||||
}
|
||||
const { direction = 'unten', ...colors } = options as Record<string, unknown>;
|
||||
if (typeof direction !== 'string' || !['oben', 'unten', 'rechts', 'links'].includes(direction)) {
|
||||
throw new BadRequestException('direction muss oben, unten, rechts oder links sein');
|
||||
}
|
||||
const parsed = parseMotorRequest({ ...request, options: colors });
|
||||
return { config: parsed.config, options: { ...parsed.options, direction: direction as EndschalterDirection } };
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import type { TextConfig, TextOptions } from '../graphics/elements/types';
|
||||
import { parseMotorRequest } from './motor.dto';
|
||||
import { parseRechteckRequest } from './rechteck.dto';
|
||||
|
||||
export function parseTextRequest(input: unknown): { config: TextConfig; options: TextOptions } {
|
||||
const isObject = (value: unknown): value is Record<string, unknown> =>
|
||||
typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||
if (!isObject(input) || !isObject(input.config) || Object.keys(input).some(key => !['config', 'options'].includes(key))) {
|
||||
throw new BadRequestException('Text erwartet config und optional options.');
|
||||
}
|
||||
const config = input.config;
|
||||
if (Object.keys(config).some(key => !['text', 'width', 'height', 'fontSize'].includes(key))) {
|
||||
throw new BadRequestException('Text-config erlaubt text, width, height und fontSize.');
|
||||
}
|
||||
const text = config.text ?? 'Text';
|
||||
const fontSize = config.fontSize ?? 16;
|
||||
if (typeof text !== 'string' || text.length > 2000 || /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(text)) {
|
||||
throw new BadRequestException('Text muss eine Zeichenfolge mit maximal 2000 Zeichen sein.');
|
||||
}
|
||||
if (typeof fontSize !== 'number' || !Number.isFinite(fontSize) || fontSize <= 0) {
|
||||
throw new BadRequestException('Schriftgröße muss eine positive endliche Zahl sein.');
|
||||
}
|
||||
const options = input.options === undefined ? {} : input.options;
|
||||
const allowed = ['frame', 'stroke', 'strokeWidth', 'fill', 'colorInactive', 'colorActive', 'colorError'];
|
||||
if (!isObject(options) || Object.keys(options).some(key => !allowed.includes(key))) {
|
||||
throw new BadRequestException('Ungültige Text-options.');
|
||||
}
|
||||
const frame = options.frame ?? false;
|
||||
if (typeof frame !== 'boolean') throw new BadRequestException('frame muss true oder false sein.');
|
||||
const rectangle = parseRechteckRequest({
|
||||
config: { width: config.width ?? 120, height: config.height ?? 40 },
|
||||
options: { stroke: options.stroke ?? '#000000', strokeWidth: options.strokeWidth ?? 1, fill: options.fill ?? 'transparent' },
|
||||
});
|
||||
const colors = parseMotorRequest({ config: {}, options: {
|
||||
colorInactive: options.colorInactive ?? '#808080', colorActive: options.colorActive ?? '#00f000', colorError: options.colorError ?? '#f00000',
|
||||
} }).options!;
|
||||
return {
|
||||
config: { text, fontSize, ...rectangle.config },
|
||||
options: { ...rectangle.options, ...colors, frame,
|
||||
strokeWidth: frame ? rectangle.options.strokeWidth : 0 } as TextOptions,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user