Skip to content

Commit

Permalink
fix(router): relation handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis committed Mar 31, 2023
1 parent 2261590 commit ef84def
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions libraries/hermes/src/Rest/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ef84def

Please sign in to comment.