Skip to content

Commit 06b3a0e

Browse files
committed
fix: cleanups
1 parent 13baa49 commit 06b3a0e

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/app/api/categories/[...category]/route.ts renamed to src/app/api/categories/[...handle]/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export async function GET(
1818
const searchParams = Object.fromEntries(request.nextUrl.searchParams)
1919
const { page, limit } = searchParams
2020

21-
let { category: categoryHandle } = params
21+
let { handle: categoryHandle } = params
2222

23-
const handle = categoryHandle.map((handle: string, index: number) => {
24-
return categoryHandle.slice(0, index + 1).join("/")
25-
})
23+
const handle = categoryHandle.map((handle: string, index: number) =>
24+
categoryHandle.slice(0, index + 1).join("/")
25+
)
2626

2727
const product_categories = await productService
2828
.listCategories(

src/lib/data/index.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,14 @@ export async function getCategoryByHandle(categoryHandle: string[]): Promise<{
337337
}> {
338338
if (PRODUCT_MODULE_ENABLED) {
339339
DEBUG && console.log("PRODUCT_MODULE_ENABLED")
340-
const data = await fetch(`${API_BASE_URL}/api/categories/${categoryHandle}`)
340+
const data = await fetch(
341+
`${API_BASE_URL}/api/categories/${categoryHandle}`,
342+
{
343+
next: {
344+
tags: ["categories"],
345+
},
346+
}
347+
)
341348
.then((res) => res.json())
342349
.catch((err) => {
343350
throw err
@@ -348,9 +355,9 @@ export async function getCategoryByHandle(categoryHandle: string[]): Promise<{
348355

349356
DEBUG && console.log("PRODUCT_MODULE_DISABLED")
350357

351-
const handles = categoryHandle.map((handle: string, index: number) => {
352-
return categoryHandle.slice(0, index + 1).join("/")
353-
})
358+
const handles = categoryHandle.map((handle: string, index: number) =>
359+
categoryHandle.slice(0, index + 1).join("/")
360+
)
354361

355362
const product_categories = [] as ProductCategoryWithChildren[]
356363

@@ -398,7 +405,12 @@ export async function getProductsByCategoryHandle({
398405
if (PRODUCT_MODULE_ENABLED) {
399406
DEBUG && console.log("PRODUCT_MODULE_ENABLED")
400407
const { response, nextPage } = await fetch(
401-
`${API_BASE_URL}/api/categories/${handle}?currency_code=${currencyCode}&page=${pageParam.toString()}`
408+
`${API_BASE_URL}/api/categories/${handle}?currency_code=${currencyCode}&page=${pageParam.toString()}`,
409+
{
410+
next: {
411+
tags: ["categories"],
412+
},
413+
}
402414
)
403415
.then((res) => res.json())
404416
.catch((err) => {

0 commit comments

Comments
 (0)