From ef84def11b5e55c4feea31cbfcc49372e6476494 Mon Sep 17 00:00:00 2001 From: Konstantinos Kopanidis Date: Fri, 31 Mar 2023 18:13:45 +0300 Subject: [PATCH] fix(router): relation handling --- libraries/hermes/src/Rest/util.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/libraries/hermes/src/Rest/util.ts b/libraries/hermes/src/Rest/util.ts index db9ccbe43..00df3e1a2 100644 --- a/libraries/hermes/src/Rest/util.ts +++ b/libraries/hermes/src/Rest/util.ts @@ -110,19 +110,28 @@ function validateArray( return; } param.forEach((obj: any, index: number) => { - if (isObject(type) && isObject(type.type)) { + if (isObject(obj) && isObject(type) && isObject(type.type)) { validateObject(index as unknown as string, obj, type.type); param[index] = obj; - } else if (isObject(type) && !type.hasOwnProperty('type')) { + } else if (isObject(obj) && isObject(type) && !type.hasOwnProperty('type')) { validateObject(index as unknown as string, obj, type); param[index] = obj; } else if (isObject(type) && type.hasOwnProperty('type')) { - param[index] = validateType( - `${fieldName}[${index}]`, - type.type as string, - obj, - false, - ); + if (type.type.hasOwnProperty('type')) { + param[index] = validateType( + `${fieldName}[${index}]`, + type.type.type as string, + obj, + type.type.required, + ); + } else { + param[index] = validateType( + `${fieldName}[${index}]`, + type.type as string, + obj, + false, + ); + } } else { param[index] = validateType(`${fieldName}[${index}]`, type as string, obj, false); } @@ -208,6 +217,10 @@ function validateType( if (typeof value !== 'string') throw ConduitError.userInput(`${fieldName} must be a string`); break; + case TYPE.Relation: + if (typeof value !== 'string') + throw ConduitError.userInput(`${fieldName} must be a string`); + break; } return value;