81f0265095
* refactor: validation * refactor: utilities * refactor: config
76 lines
1.5 KiB
TypeScript
76 lines
1.5 KiB
TypeScript
import { Type } from 'class-transformer';
|
|
import {
|
|
IsDateString,
|
|
IsInt,
|
|
IsLatitude,
|
|
IsLongitude,
|
|
IsNotEmpty,
|
|
IsPositive,
|
|
IsString,
|
|
ValidateIf,
|
|
} from 'class-validator';
|
|
import { BulkIdsDto } from 'src/domain/asset/response-dto/asset-ids-response.dto';
|
|
import { Optional, ValidateBoolean, ValidateUUID } from 'src/validation';
|
|
|
|
export class DeviceIdDto {
|
|
@IsNotEmpty()
|
|
@IsString()
|
|
deviceId!: string;
|
|
}
|
|
|
|
const hasGPS = (o: { latitude: undefined; longitude: undefined }) =>
|
|
o.latitude !== undefined || o.longitude !== undefined;
|
|
const ValidateGPS = () => ValidateIf(hasGPS);
|
|
|
|
export class UpdateAssetBase {
|
|
@ValidateBoolean({ optional: true })
|
|
isFavorite?: boolean;
|
|
|
|
@ValidateBoolean({ optional: true })
|
|
isArchived?: boolean;
|
|
|
|
@Optional()
|
|
@IsDateString()
|
|
dateTimeOriginal?: string;
|
|
|
|
@ValidateGPS()
|
|
@IsLatitude()
|
|
@IsNotEmpty()
|
|
latitude?: number;
|
|
|
|
@ValidateGPS()
|
|
@IsLongitude()
|
|
@IsNotEmpty()
|
|
longitude?: number;
|
|
}
|
|
|
|
export class AssetBulkUpdateDto extends UpdateAssetBase {
|
|
@ValidateUUID({ each: true })
|
|
ids!: string[];
|
|
|
|
@ValidateUUID({ optional: true })
|
|
stackParentId?: string;
|
|
|
|
@ValidateBoolean({ optional: true })
|
|
removeParent?: boolean;
|
|
}
|
|
|
|
export class UpdateAssetDto extends UpdateAssetBase {
|
|
@Optional()
|
|
@IsString()
|
|
description?: string;
|
|
}
|
|
|
|
export class RandomAssetsDto {
|
|
@Optional()
|
|
@IsInt()
|
|
@IsPositive()
|
|
@Type(() => Number)
|
|
count?: number;
|
|
}
|
|
|
|
export class AssetBulkDeleteDto extends BulkIdsDto {
|
|
@ValidateBoolean({ optional: true })
|
|
force?: boolean;
|
|
}
|