refactor: api validators (boolean and date) (#7709)

* refactor: api validators (boolean and date)

* chore: open api

* revert: time bucket change
This commit is contained in:
Jason Rasmussen
2024-03-07 22:59:02 -05:00
committed by GitHub
parent 753842745d
commit a50f125dd1
41 changed files with 276 additions and 368 deletions
+15 -38
View File
@@ -1,6 +1,5 @@
import { Type } from 'class-transformer';
import {
IsBoolean,
IsDateString,
IsInt,
IsLatitude,
@@ -10,7 +9,7 @@ import {
IsString,
ValidateIf,
} from 'class-validator';
import { Optional, ValidateUUID } from '../../domain.util';
import { Optional, ValidateBoolean, ValidateUUID } from '../../domain.util';
import { BulkIdsDto } from '../response-dto';
export class DeviceIdDto {
@@ -28,23 +27,13 @@ const hasGPS = (o: { latitude: undefined; longitude: undefined }) =>
o.latitude !== undefined || o.longitude !== undefined;
const ValidateGPS = () => ValidateIf(hasGPS);
export class AssetBulkUpdateDto extends BulkIdsDto {
@Optional()
@IsBoolean()
export class UpdateAssetBase {
@ValidateBoolean({ optional: true })
isFavorite?: boolean;
@Optional()
@IsBoolean()
@ValidateBoolean({ optional: true })
isArchived?: boolean;
@Optional()
@ValidateUUID()
stackParentId?: string;
@Optional()
@IsBoolean()
removeParent?: boolean;
@Optional()
@IsDateString()
dateTimeOriginal?: string;
@@ -60,32 +49,21 @@ export class AssetBulkUpdateDto extends BulkIdsDto {
longitude?: number;
}
export class UpdateAssetDto {
@Optional()
@IsBoolean()
isFavorite?: boolean;
export class AssetBulkUpdateDto extends UpdateAssetBase {
@ValidateUUID({ each: true })
ids!: string[];
@Optional()
@IsBoolean()
isArchived?: boolean;
@ValidateUUID({ optional: true })
stackParentId?: string;
@ValidateBoolean({ optional: true })
removeParent?: boolean;
}
export class UpdateAssetDto extends UpdateAssetBase {
@Optional()
@IsString()
description?: string;
@Optional()
@IsDateString()
dateTimeOriginal?: string;
@ValidateGPS()
@IsLatitude()
@IsNotEmpty()
latitude?: number;
@ValidateGPS()
@IsLongitude()
@IsNotEmpty()
longitude?: number;
}
export class RandomAssetsDto {
@@ -97,7 +75,6 @@ export class RandomAssetsDto {
}
export class AssetBulkDeleteDto extends BulkIdsDto {
@Optional()
@IsBoolean()
@ValidateBoolean({ optional: true })
force?: boolean;
}