fix(medusa-js): Allow payload in DELETE and POST (#1985)

This commit is contained in:
Adrien de Peretti
2022-08-04 11:47:54 +02:00
committed by GitHub
parent b1f88f917b
commit badda5233c
3 changed files with 18 additions and 13 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/medusa-js": patch
"@medusajs/medusa": patch
---
Only include payload on POST and DELETE requests

View File

@@ -173,33 +173,32 @@ class Client {
/**
* Axios request
* @param {Types.RequestMethod} method request method
* @param {string} path request path
* @param {object} payload request payload
* @param {RequestOptions} options axios configuration
* @param {object} customHeaders custom request headers
* @return {object}
* @param method request method
* @param path request path
* @param payload request payload
* @param options axios configuration
* @param customHeaders custom request headers
* @return
*/
async request(
method: RequestMethod,
path: string,
payload: Record<string, any> | null = null,
payload: Record<string, any> = {},
options: RequestOptions = {},
customHeaders: Record<string, any> = {}
): Promise<any> {
if (method === "POST" && !payload) {
payload = {}
}
const reqOpts = {
method,
withCredentials: true,
url: path,
data: payload,
json: true,
headers: this.setHeaders(options, method, path, customHeaders),
}
if (["POST", "DELETE"].includes(method)) {
reqOpts["data"] = payload
}
// e.g. data = { cart: { ... } }, response = { status, headers, ... }
const { data, ...response } = await this.axiosClient(reqOpts)

View File

@@ -7,7 +7,7 @@ import {
import { createWrapper } from "../../../utils"
describe("useAdminDeleteFile hook", () => {
test("Removes file with key and returns deleteresult", async () => {
test("Removes file with key and returns delete result", async () => {
const file_key = "test"
const { result, waitFor } = renderHook(() => useAdminDeleteFile(), {