|
@@ -4,14 +4,15 @@ export type InputPatch<T> = { [K in keyof T]?: T[K] | null };
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Updates only the specified properties from an Input object as long as the value is not
|
|
* Updates only the specified properties from an Input object as long as the value is not
|
|
|
- * null or undefined.
|
|
|
|
|
|
|
+ * undefined. Null values can be passed, however, which will set the corresponding entity
|
|
|
|
|
+ * field to "null". So case must be taken that this is only done on nullable fields.
|
|
|
*/
|
|
*/
|
|
|
export function patchEntity<T extends VendureEntity, I extends InputPatch<T>>(entity: T, input: I): T {
|
|
export function patchEntity<T extends VendureEntity, I extends InputPatch<T>>(entity: T, input: I): T {
|
|
|
for (const key of Object.keys(entity)) {
|
|
for (const key of Object.keys(entity)) {
|
|
|
const value = input[key as keyof T];
|
|
const value = input[key as keyof T];
|
|
|
if (key === 'customFields') {
|
|
if (key === 'customFields') {
|
|
|
patchEntity((entity as any)[key], value as any);
|
|
patchEntity((entity as any)[key], value as any);
|
|
|
- } else if (value != null && key !== 'id') {
|
|
|
|
|
|
|
+ } else if (value !== undefined && key !== 'id') {
|
|
|
entity[key as keyof T] = value as any;
|
|
entity[key as keyof T] = value as any;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|