visualisierung
This commit is contained in:
1 parent
d0655f3638
commit
367c93c93e
84 files changed
+2265
-148
No files matched your search
@@ -7,21 +7,27 @@ export class BandObenRenderDto {
|
||||
}
|
||||
|
||||
export function parseBandObenRequest(input: unknown): BandObenRenderDto {
|
||||
const object = (value: unknown): value is Record<string, unknown> =>
|
||||
typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||
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 => !['width', 'length'].includes(key)) ||
|
||||
typeof config.width !== 'number' || !Number.isFinite(config.width) || config.width <= 10 ||
|
||||
typeof config.length !== 'number' || !Number.isFinite(config.length) || config.length <= 0)
|
||||
typeof config.width !== 'number' || !Number.isFinite(config.width) || config.width <= 10 ||
|
||||
typeof config.length !== 'number' || !Number.isFinite(config.length) || config.length <= 0)
|
||||
throw new BadRequestException('config.width muss größer als 10 und config.length positiv sein; beide Werte müssen endliche Zahlen sein');
|
||||
|
||||
const options = input.options === undefined ? {} : input.options;
|
||||
|
||||
if (!object(options) || Object.entries(options).some(([key, value]) =>
|
||||
!['fromNorthToSouth', 'trichterStart', 'trichterEnd'].includes(key) || typeof value !== 'boolean'))
|
||||
throw new BadRequestException('options erlaubt nur fromNorthToSouth, trichterStart und trichterEnd als Boolean');
|
||||
|
||||
if ((options.trichterStart || options.trichterEnd) && config.length < 20)
|
||||
throw new BadRequestException('Mit Trichter muss die Bandlänge mindestens 20 sein');
|
||||
|
||||
return {
|
||||
config: { width: config.width, length: config.length },
|
||||
options: {
|
||||
|
||||
@@ -27,8 +27,7 @@ export class DrawDataDto {
|
||||
name!:string;
|
||||
height!: number;
|
||||
width!:number;
|
||||
svg!:{state:string,data:string}[]
|
||||
xaml!:{state:"inactive" | "active" | "error",data:string,base64?:string}[]
|
||||
varianten!: { state: 'inactive' | 'active' | 'error'; svg: string; xaml: string; xamlBase64: string }[];
|
||||
}
|
||||
|
||||
export class DrawShapeOptionenDto{
|
||||
@@ -54,4 +53,4 @@ export class DrawParameterDto{
|
||||
colorActive?:string;
|
||||
colorError?:string;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import type { MotorConfig, MotorOptions } from '../graphics/elements/types';
|
||||
|
||||
export class MotorRenderDto {
|
||||
config!: MotorConfig;
|
||||
options?: Partial<MotorOptions>;
|
||||
}
|
||||
|
||||
export function parseMotorRequest(input: unknown): MotorRenderDto {
|
||||
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('Motor-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', 'colorError'].includes(key) ||
|
||||
typeof value !== 'string' || !/^#[0-9a-fA-F]{6}$/.test(value))
|
||||
)
|
||||
throw new BadRequestException('Motor-options erlaubt colorInactive, colorActive und colorError als Hexfarbe #RRGGBB');
|
||||
|
||||
return { config: { scale, raster }, options: options as Partial<MotorOptions> };
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import { Types } from 'mongoose';
|
||||
import type { ProConVerbindung } from '../_schemas/procon-verbindung';
|
||||
|
||||
export class ProConVerbindungenDto {
|
||||
verbindungen!: (Omit<ProConVerbindung, '_id'> & { id?: string })[];
|
||||
aktiveVerbindungId!: string | null;
|
||||
}
|
||||
|
||||
export function parseVerbindungen(input: ProConVerbindungenDto) {
|
||||
if (!input || !Array.isArray(input.verbindungen)) throw new BadRequestException('Verbindungsliste fehlt');
|
||||
const ids = new Set<string>();
|
||||
const verbindungen = input.verbindungen.map(item => {
|
||||
if (!item || ['name', 'server', 'datenbank', 'benutzer'].some(key => typeof item[key] !== 'string' || !item[key].trim()) ||
|
||||
typeof item.passwort !== 'string' || typeof item.instanz !== 'string' ||
|
||||
!['test', 'produktion'].includes(item.umgebung) ||
|
||||
typeof item.encrypt !== 'boolean' || typeof item.trustServerCertificate !== 'boolean')
|
||||
throw new BadRequestException('Verbindungsdaten sind unvollständig');
|
||||
if (item.server.includes('\\') || item.server.includes('/') || (item.instanz && item.port !== null))
|
||||
throw new BadRequestException('Server und Instanz getrennt eingeben; entweder Instanz oder Port verwenden');
|
||||
if ((item.port !== null && (!Number.isInteger(item.port) || item.port < 1 || item.port > 65535)) ||
|
||||
!Number.isInteger(item.connectionTimeoutMs) || item.connectionTimeoutMs < 1000 || item.connectionTimeoutMs > 60000)
|
||||
throw new BadRequestException('Port muss 1–65535 und Timeout 1000–60000 ms betragen');
|
||||
if (item.id && !Types.ObjectId.isValid(item.id)) throw new BadRequestException('Ungültige Verbindungs-ID');
|
||||
const _id = item.id ? new Types.ObjectId(item.id) : new Types.ObjectId();
|
||||
if (ids.has(_id.toString())) throw new BadRequestException('Doppelte Verbindungs-ID');
|
||||
ids.add(_id.toString());
|
||||
return {
|
||||
_id, name: item.name.trim(), server: item.server.trim(), instanz: item.instanz.trim(),
|
||||
port: item.port, datenbank: item.datenbank.trim(), benutzer: item.benutzer.trim(),
|
||||
passwort: item.passwort, umgebung: item.umgebung, encrypt: item.encrypt,
|
||||
trustServerCertificate: item.trustServerCertificate, connectionTimeoutMs: item.connectionTimeoutMs,
|
||||
};
|
||||
});
|
||||
if (input.aktiveVerbindungId !== null && !ids.has(input.aktiveVerbindungId))
|
||||
throw new BadRequestException('Aktive Verbindung ist nicht in der Liste enthalten');
|
||||
return { verbindungen, aktiveVerbindungId: input.aktiveVerbindungId };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user