commerce/packages/swell/utils/get-categories.ts
2022-01-14 23:33:01 -05:00

17 lines
382 B
TypeScript

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