Files
immich/server/src/utils/bbox.ts
Michel Heusschen 771816f601 feat(web): map timeline sidepanel (#26532)
* feat(web): map timeline panel

* update openapi

* remove #key

* add index on lat/lng
2026-02-26 12:03:23 -05:00

33 lines
1.1 KiB
TypeScript

import { applyDecorators } from '@nestjs/common';
import { ApiPropertyOptions } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { IsNotEmpty, ValidateNested } from 'class-validator';
import { Property } from 'src/decorators';
import { BBoxDto } from 'src/dtos/bbox.dto';
import { Optional } from 'src/validation';
type BBoxOptions = { optional?: boolean };
export const ValidateBBox = (options: BBoxOptions & ApiPropertyOptions = {}) => {
const { optional, ...apiPropertyOptions } = options;
return applyDecorators(
Transform(({ value }) => {
if (typeof value !== 'string') {
return value;
}
const [west, south, east, north] = value.split(',', 4).map(Number);
return Object.assign(new BBoxDto(), { west, south, east, north });
}),
Type(() => BBoxDto),
ValidateNested(),
Property({
type: 'string',
description: 'Bounding box coordinates as west,south,east,north (WGS84)',
example: '11.075683,49.416711,11.117589,49.454875',
...apiPropertyOptions,
}),
optional ? Optional({}) : IsNotEmpty(),
);
};