Skip to content

Commit

Permalink
fix: fixed creating a body of POST requests. (#619)
Browse files Browse the repository at this point in the history
* Fixed creating a body of POST requests.
  • Loading branch information
b4rtaz authored Aug 26, 2022
1 parent d42222e commit 5bfb635
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/dull-pianos-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moralisweb3/api-utils': patch
'@moralisweb3/evm-api': patch
---

Fixed creating a body of POST requests.
14 changes: 10 additions & 4 deletions packages/apiUtils/src/resolvers/EndpointParamsReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ export class EndpointParamsReader<ApiParams, Params, ApiResult, AdaptedResult, J
}

public getBodyParams(params: ApiParams) {
if (this.endpoint.bodyType === EndpointBodyType.BODY && this.endpoint.bodyParams) {
// TODO: delete `as unknown`
const paramName = this.endpoint.bodyParams[0] as unknown as keyof ApiParams;
return params[paramName];
}

return Object.keys(params).reduce((result, key) => {
// @ts-ignore TODO: fix the ApiParams type, as it should extend object/record
if (!params[key] || !this.isBodyParam(key)) {
// TODO: delete `as unknown`
const paramName = key as unknown as keyof ApiParams;
if (!params[paramName] || !this.isBodyParam(key)) {
return result;
}
if (this.endpoint.bodyType === EndpointBodyType.PROPERTY) {
// @ts-ignore TODO: fix the ApiParams type, as it should extend object/record
return { ...result, [key]: params[key] };
return { ...result, [key]: params[paramName] };
}
return result;
}, {});
Expand Down

0 comments on commit 5bfb635

Please sign in to comment.