Merge pull request #15 from TouchInstinct/feature/request_form-data

Change request FormData
This commit is contained in:
grigoriishveps 2022-01-25 18:51:21 +03:00 committed by GitHub
commit 0c74192cd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -63,17 +63,28 @@ class ApiMethodFactory {
method: HttpMethod = HttpMethod.GET, {
path: pathKeys = [],
query: queryKeys = [],
}: { path?: string[], query?: string[] } = {},
isFormData = false,
}: { path?: string[], query?: string[], isFormData?: boolean } = {},
) => async (data: Nullable<T> = null, headers: HeadersType = {}): Promise<R> => {
const getBody = (body: Nullable<T>) => {
if (R.isNil(body) || body instanceof FormData) {
return body
}
return R.pipe(
const preResult = R.pipe(
R.omit(R.concat(pathKeys, queryKeys)),
R.when(R.isEmpty, R.always(null)),
)(body)
if (isFormData) {
const formData = new FormData()
R.forEachObjIndexed<any>((value, key) => formData.append(key as string, value), body)
return formData
}
return preResult
}
const body = getBody(data)