commerce/framework/swell/utils/get-categories.ts
2021-03-29 17:05:20 -06:00

21 lines
426 B
TypeScript

import { SwellConfig } from '../api'
export type Category = {
id: string
name: string
slug: string
}
const getCategories = async (config: SwellConfig): Promise<Category[]> => {
const data = await config.fetchSwell('categories', 'get')
return (
data.results.map(({ id: entityId, name, slug }: Category) => ({
entityId,
name,
path: `/${slug}`,
})) ?? []
)
}
export default getCategories