mirror of
https://github.com/immich-app/immich.git
synced 2026-05-22 07:32:32 -04:00
fix(server): require at least one field to be set when updating memory (#27842)
* add zod util to require one field is set in some schemas. appy to update memory endpoint * add test
This commit is contained in:
@@ -32,6 +32,22 @@ export function IsIPRange(options?: IsIPRangeOptions) {
|
||||
.refine((arr) => arr.every((item) => isIPOrRange(item, options)), 'Must be an ip address or ip address range');
|
||||
}
|
||||
|
||||
/**
|
||||
* Like z.object().partial(), but rejects objects where every field is undefined.
|
||||
* Use for update/patch DTOs where at least one field must be provided.
|
||||
*
|
||||
* @example
|
||||
* nonEmptyPartial({ name: z.string(), bio: z.string() }).meta({ id: 'UpdateDto' });
|
||||
*/
|
||||
export function nonEmptyPartial<T extends z.ZodRawShape>(shape: T) {
|
||||
return z
|
||||
.object(shape)
|
||||
.partial()
|
||||
.refine((data) => Object.values(data as Record<string, unknown>).some((value) => value !== undefined), {
|
||||
message: 'At least one field must be provided',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Zod schema that validates sibling-exclusion for object schemas.
|
||||
* Validation passes when the target property is missing, or when none of the sibling properties are present.
|
||||
|
||||
Reference in New Issue
Block a user