commerce/framework/swell/utils/get-categories.ts
2021-06-01 07:55:04 -03:00

21 lines
422 B
TypeScript

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