mirror of
https://github.com/immich-app/immich.git
synced 2025-11-03 15:52:34 +09:00
feat(server): search unknown place (#10866)
* Allow submission of null country
* Update searchAssetBuilder to handle nulls
andWhere({country:null}) produces `"exifInfo"."country" = NULL`. We want
`"exifInfo"."country" IS NULL`, so we have to treat NULL as a special
case
* Allow null country in frontend
* Make the query code a bit more straightforward
* Remove unused brackets import
* Remove log message
* Don't change whitespace for no reason
* Fix prettier style issue
* Update search.dto.ts validators per @jrasm91's recommendation
* Update api types
* Combine null country and state into one guard clause
* chore: clean up
* chore: add e2e for null/empty city, state, country search
* refactor: server returns suggestion for null values
* chore: clean up
---------
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
Co-authored-by: Jason Rasmussen <jason@rasm.me>
This commit is contained in:
@@ -66,6 +66,8 @@ export class UUIDParamDto {
|
||||
|
||||
export interface OptionalOptions extends ValidationOptions {
|
||||
nullable?: boolean;
|
||||
/** convert empty strings to null */
|
||||
emptyToNull?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,12 +78,20 @@ export interface OptionalOptions extends ValidationOptions {
|
||||
* @see IsOptional exported from `class-validator.
|
||||
*/
|
||||
// https://stackoverflow.com/a/71353929
|
||||
export function Optional({ nullable, ...validationOptions }: OptionalOptions = {}) {
|
||||
export function Optional({ nullable, emptyToNull, ...validationOptions }: OptionalOptions = {}) {
|
||||
const decorators: PropertyDecorator[] = [];
|
||||
|
||||
if (nullable === true) {
|
||||
return IsOptional(validationOptions);
|
||||
decorators.push(IsOptional(validationOptions));
|
||||
} else {
|
||||
decorators.push(ValidateIf((object: any, v: any) => v !== undefined, validationOptions));
|
||||
}
|
||||
|
||||
return ValidateIf((object: any, v: any) => v !== undefined, validationOptions);
|
||||
if (emptyToNull) {
|
||||
decorators.push(Transform(({ value }) => (value === '' ? null : value)));
|
||||
}
|
||||
|
||||
return applyDecorators(...decorators);
|
||||
}
|
||||
|
||||
type UUIDOptions = { optional?: boolean; each?: boolean; nullable?: boolean };
|
||||
|
||||
Reference in New Issue
Block a user