Skip to content

Commit 2212966

Browse files
author
Crhistian Ramirez
committed
🐛 post/put/patch not working
I thought i could send the data on the axios config but it needs to be its own parameter
1 parent 8162fb8 commit 2212966

3 files changed

Lines changed: 35 additions & 14 deletions

File tree

codegen/templates/utils/HttpClient.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,22 @@ class HttpClient {
6969
config
7070
) {
7171
const requestConfig = await this._buildRequestConfig(config)
72-
const response = await axios[verb as string](
73-
`${Configuration.Get().baseApiUrl}${path}`,
74-
requestConfig
75-
)
76-
return response.data
72+
if (verb === 'put' || verb === 'post' || verb === 'patch') {
73+
const requestBody = requestConfig.data
74+
delete requestConfig.data
75+
const response = await axios[verb as string](
76+
`${Configuration.Get().baseApiUrl}${path}`,
77+
requestBody,
78+
requestConfig
79+
)
80+
return response.data
81+
} else {
82+
const response = await axios[verb as string](
83+
`${Configuration.Get().baseApiUrl}${path}`,
84+
requestConfig
85+
)
86+
return response.data
87+
}
7788
}
7889

7990
// sets the token on every outgoing request, will attempt to

src/utils/HttpClient.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,22 @@ class HttpClient {
6969
config
7070
) {
7171
const requestConfig = await this._buildRequestConfig(config)
72-
const response = await axios[verb as string](
73-
`${Configuration.Get().baseApiUrl}${path}`,
74-
requestConfig
75-
)
76-
return response.data
72+
if (verb === 'put' || verb === 'post' || verb === 'patch') {
73+
const requestBody = requestConfig.data
74+
delete requestConfig.data
75+
const response = await axios[verb as string](
76+
`${Configuration.Get().baseApiUrl}${path}`,
77+
requestBody,
78+
requestConfig
79+
)
80+
return response.data
81+
} else {
82+
const response = await axios[verb as string](
83+
`${Configuration.Get().baseApiUrl}${path}`,
84+
requestConfig
85+
)
86+
return response.data
87+
}
7788
}
7889

7990
// sets the token on every outgoing request, will attempt to

tests/products.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ test('can create product', async () => {
1818
}
1919
await Products.Create(product)
2020
expect(mockAxios.post).toHaveBeenCalledTimes(1)
21-
expect(mockAxios.post).toHaveBeenCalledWith(`${apiUrl}/products`, {
21+
expect(mockAxios.post).toHaveBeenCalledWith(`${apiUrl}/products`, product, {
2222
params: {},
2323
paramsSerializer: expect.any(Function),
2424
timeout: 10000,
25-
data: product,
2625
headers: {
2726
'Content-Type': 'application/json',
2827
'Authorization': `Bearer ${validToken}`,
@@ -40,9 +39,9 @@ test('can patch product', async () => {
4039
expect(mockAxios.patch).toHaveBeenCalledTimes(1)
4140
expect(mockAxios.patch).toHaveBeenCalledWith(
4241
`${apiUrl}/products/${productID}`,
42+
partialProduct,
4343
{
4444
params: {},
45-
data: partialProduct,
4645
paramsSerializer: expect.any(Function),
4746
timeout: 10000,
4847
headers: {
@@ -64,9 +63,9 @@ test('can update product', async () => {
6463
expect(mockAxios.put).toHaveBeenCalledTimes(1)
6564
expect(mockAxios.put).toHaveBeenCalledWith(
6665
`${apiUrl}/products/${productID}`,
66+
product,
6767
{
6868
params: {},
69-
data: product,
7069
paramsSerializer: expect.any(Function),
7170
timeout: 10000,
7271
headers: {

0 commit comments

Comments
 (0)