Loan Laux 09249045eb
Add Reaction Commerce provider
Signed-off-by: Loan Laux <loan@outgrow.io>
2021-03-30 20:07:48 +04:00

35 lines
713 B
TypeScript

import { ReactionCommerceConfig } from '../api'
import { CollectionEdge, TagEdge } from '../schema'
import getTagsQuery from './queries/get-all-collections-query'
export type Category = {
entityId: string
name: string
path: string
}
const getCategories = async (
config: ReactionCommerceConfig
): Promise<Tag[]> => {
const { data } = await config.fetch(getTagsQuery, {
variables: {
first: 250,
shopId: config.shopId,
},
})
return (
data.tags?.edges?.map(
({
node: { _id: entityId, displayTitle: name, slug: handle },
}: TagEdge) => ({
entityId,
name,
path: `/${handle}`,
})
) ?? []
)
}
export default getCategories