-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from CrystallizeAPI/feature/shop-api-functions
Feature/shop api functions
- Loading branch information
Showing
4 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { jsonToGraphQLQuery } from 'json-to-graphql-query'; | ||
import { ClientInterface } from './client'; | ||
import { Customer } from '../types/customer'; | ||
|
||
type Deps = { | ||
apiClient: ClientInterface; | ||
}; | ||
|
||
export const placeCart = async (cartId: string, { apiClient }: Deps, extraQuery?: any): Promise<void> => { | ||
const mutation = { | ||
place: { | ||
__args: { | ||
id: cartId, | ||
}, | ||
id: true, | ||
...extraQuery, | ||
}, | ||
}; | ||
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation })); | ||
return response.place; | ||
}; | ||
|
||
export const addSkuItem = async ( | ||
cartId: string, | ||
sku: string, | ||
quantity: number, | ||
{ apiClient }: Deps, | ||
extraQuery?: any, | ||
) => { | ||
const mutation = { | ||
addSkuItem: { | ||
__args: { | ||
id: cartId, | ||
input: { | ||
sku, | ||
quantity, | ||
}, | ||
}, | ||
id: true, | ||
...extraQuery, | ||
}, | ||
}; | ||
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation })); | ||
return response.addSkuItem; | ||
}; | ||
|
||
export const removeCartItem = async ( | ||
cartId: string, | ||
sku: string, | ||
quantity: number, | ||
{ apiClient }: Deps, | ||
extraQuery?: any, | ||
) => { | ||
const mutation = { | ||
removeCartItem: { | ||
__args: { | ||
id: cartId, | ||
sku, | ||
quantity, | ||
}, | ||
id: true, | ||
...extraQuery, | ||
}, | ||
}; | ||
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation })); | ||
return response.removeCartItem; | ||
}; | ||
|
||
export const setCartMeta = async ( | ||
cartId: string, | ||
meta: Array<{ | ||
key: string; | ||
value: string; | ||
}>, | ||
merge: Boolean, | ||
{ apiClient }: Deps, | ||
extraQuery?: any, | ||
): Promise<void> => { | ||
const mutation = { | ||
setMeta: { | ||
__args: { | ||
id: cartId, | ||
merge, | ||
meta, | ||
}, | ||
id: true, | ||
...extraQuery, | ||
}, | ||
}; | ||
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation })); | ||
return response.setMeta; | ||
}; | ||
|
||
export const setCartCustomer = async ( | ||
cartId: string, | ||
customer: Customer, | ||
isGuest: boolean, | ||
{ apiClient }: Deps, | ||
extraQuery?: any, | ||
): Promise<void> => { | ||
const mutation = { | ||
setCustomer: { | ||
__args: { | ||
id: cartId, | ||
input: { | ||
isGuest, | ||
...customer, | ||
}, | ||
}, | ||
id: true, | ||
...extraQuery, | ||
}, | ||
}; | ||
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation })); | ||
return response.setCustomer; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters