procon aggregate
This commit is contained in:
1 parent
e284fae7b4
commit
d0655f3638
32 files changed
+1520
-1058
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import type { BandObenConfig, BandObenOptions } from '../graphics/elements/types';
|
||||
|
||||
export class BandObenRenderDto {
|
||||
config!: BandObenConfig;
|
||||
options?: Partial<BandObenOptions>;
|
||||
}
|
||||
|
||||
export function parseBandObenRequest(input: unknown): BandObenRenderDto {
|
||||
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)
|
||||
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: {
|
||||
fromNorthToSouth: options.fromNorthToSouth ?? false,
|
||||
trichterStart: options.trichterStart ?? false,
|
||||
trichterEnd: options.trichterEnd ?? false,
|
||||
} as BandObenOptions,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user