Skip to content

Commit

Permalink
fix(database): no error when setting body params in GET/DELETE custom…
Browse files Browse the repository at this point in the history
… endpoints (#442)
  • Loading branch information
sdimitris committed Nov 22, 2022
1 parent 3caed9f commit 676a4e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class CustomEndpointsAdmin {
if (error !== true) {
throw new GrpcError(status.INVALID_ARGUMENT, error as string);
}
error = inputValidation(inputs);
error = inputValidation(operation, inputs);
if (error !== true) {
throw new GrpcError(status.INVALID_ARGUMENT, error as string);
}
Expand Down
28 changes: 23 additions & 5 deletions modules/database/src/admin/customEndpoints/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function _queryValidation(
* }
*/
function _inputValidation(
operation: number,
name: string,
type: any,
location: number,
Expand All @@ -155,20 +156,37 @@ function _inputValidation(
}

if (location === 2 && isArray) {
return 'Url params cant have an array input';
return "Url params can't have an array input";
}

if (
(operation === OperationsEnum.GET || operation === OperationsEnum.DELETE) &&
location === 0
) {
return 'GET or DELETE requests can not have body parameters';
}

return true;
}

export function inputValidation(inputs?: Indexable | null): boolean | string {
export function inputValidation(
operation: number,
inputs?: Indexable | null,
): boolean | string {
if (!isNil(inputs) && inputs.length) {
inputs.forEach((r: Indexable) => {
const error = _inputValidation(r.name, r.type, r.location, r.array);
for (const r of Object.keys(inputs)) {
const input = inputs[r];
const error = _inputValidation(
operation,
input.name,
input.type,
input.location,
input.array,
);
if (error !== true) {
return error as string;
}
});
}
}
return true;
}
Expand Down

0 comments on commit 676a4e5

Please sign in to comment.