Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed creating a body of POST requests. #619

Merged
merged 2 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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