fix: default POST request payloads to an empty object (#1141)

* defaulted carts.create payload to an empty object

* fix linting

* requested changes
This commit is contained in:
Kasper Fabricius Kristensen
2022-03-09 17:19:38 +01:00
committed by GitHub
parent 5f5a2af30b
commit 4e7435e4d7
2 changed files with 34 additions and 11 deletions

View File

@@ -187,6 +187,10 @@ class Client {
options: RequestOptions = {},
customHeaders: Record<string, any> = {}
): Promise<any> {
if (method === "POST" && !payload) {
payload = {}
}
const reqOpts = {
method,
withCredentials: true,

View File

@@ -24,7 +24,8 @@ class CartsResource extends BaseResource {
addShippingMethod(
cart_id: string,
payload: StorePostCartsCartShippingMethodReq,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/shipping-methods`
return this.client.request("POST", path, payload, {}, customHeaders)
}
@@ -39,7 +40,10 @@ class CartsResource extends BaseResource {
* @param customHeaders
* @return {ResponsePromise<StoreCompleteCartRes>}
*/
complete(cart_id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreCompleteCartRes> {
complete(
cart_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCompleteCartRes> {
const path = `/store/carts/${cart_id}/complete`
return this.client.request("POST", path, {}, {}, customHeaders)
}
@@ -51,7 +55,10 @@ class CartsResource extends BaseResource {
* @param customHeaders
* @return {ResponsePromise<StoreCartsRes>}
*/
create(payload?: StorePostCartReq, customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
create(
payload?: StorePostCartReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts`
return this.client.request("POST", path, payload, {}, customHeaders)
}
@@ -64,7 +71,10 @@ class CartsResource extends BaseResource {
* @param customHeaders
* @return {ResponsePromise<StoreCartsRes>}
*/
createPaymentSessions(cart_id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
createPaymentSessions(
cart_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/payment-sessions`
return this.client.request("POST", path, {}, {}, customHeaders)
}
@@ -79,7 +89,8 @@ class CartsResource extends BaseResource {
deleteDiscount(
cart_id: string,
code: string,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/discounts/${code}`
return this.client.request("DELETE", path, {}, {}, customHeaders)
}
@@ -95,7 +106,8 @@ class CartsResource extends BaseResource {
deletePaymentSession(
cart_id: string,
provider_id: string,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}`
return this.client.request("DELETE", path, {}, {}, customHeaders)
}
@@ -110,7 +122,8 @@ class CartsResource extends BaseResource {
refreshPaymentSession(
cart_id: string,
provider_id: string,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}/refresh`
return this.client.request("POST", path, {}, {}, customHeaders)
}
@@ -121,7 +134,10 @@ class CartsResource extends BaseResource {
* @param customHeaders
* @return {ResponsePromise<StoreCartsRes>}
*/
retrieve(cart_id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
retrieve(
cart_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}`
return this.client.request("GET", path, {}, {}, customHeaders)
}
@@ -136,7 +152,8 @@ class CartsResource extends BaseResource {
setPaymentSession(
cart_id: string,
payload: StorePostCartsCartPaymentSessionReq,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/payment-session`
return this.client.request("POST", path, payload, {}, customHeaders)
}
@@ -151,7 +168,8 @@ class CartsResource extends BaseResource {
update(
cart_id: string,
payload: StorePostCartsCartReq,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}`
return this.client.request("POST", path, payload, {}, customHeaders)
}
@@ -168,7 +186,8 @@ class CartsResource extends BaseResource {
cart_id: string,
provider_id: string,
payload: StorePostCartsCartPaymentSessionUpdateReq,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> {
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}`
return this.client.request("POST", path, payload, {}, customHeaders)
}