Browse Source

fix(core): Fix custom field validation when updating ProductVariants

Fixes #1014
Michael Bromley 4 years ago
parent
commit
372b4af5e5

+ 8 - 5
packages/core/src/api/middleware/validate-custom-fields-interceptor.ts

@@ -51,12 +51,15 @@ export class ValidateCustomFieldsInterceptor implements NestInterceptor {
                 for (const [inputName, typeName] of Object.entries(inputTypeNames)) {
                     if (this.inputsWithCustomFields.has(typeName)) {
                         if (variables[inputName]) {
-                            await this.validateInput(
-                                typeName,
-                                ctx.languageCode,
-                                injector,
+                            const inputVariables: Array<Record<string, any>> = Array.isArray(
                                 variables[inputName],
-                            );
+                            )
+                                ? variables[inputName]
+                                : [variables[inputName]];
+
+                            for (const inputVariable of inputVariables) {
+                                await this.validateInput(typeName, ctx.languageCode, injector, inputVariable);
+                            }
                         }
                     }
                 }