fix(medusa-js): Allow payload in DELETE and POST (#1985)
This commit is contained in:
committed by
GitHub
parent
b1f88f917b
commit
badda5233c
6
.changeset/five-pets-move.md
Normal file
6
.changeset/five-pets-move.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/medusa-js": patch
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
Only include payload on POST and DELETE requests
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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(), {
|
||||
|
||||
Reference in New Issue
Block a user