23 lines
736 B
TypeScript
23 lines
736 B
TypeScript
import type { ArticleSummary, Paginated } from '#shared/types/blog'
|
|||
|
|
|
||
|
|
export default defineEventHandler(async (event): Promise<Paginated<ArticleSummary>> => {
|
||
|
|
const query = getQuery(event)
|
||
|
|
const page = pageParam(query.page)
|
||
|
|
const category = typeof query.category === 'string' ? query.category : null
|
||
|
|
|
||
|
|
const filter = category
|
||
|
|
? `&filters[category][slug][$eq]=${encodeURIComponent(category)}`
|
||
|
|
: ''
|
||
|
|
|
||
|
|
const response = await strapiFetch<StrapiList<ArticleSummary>>(
|
||
|
|
`/api/articles?${ARTICLE_SUMMARY_QUERY}&${pagination(page)}${filter}`
|
||
|
|
)
|
||
|
|
|
||
|
|
return {
|
||
|
|
items: response.data,
|
||
|
|
page: response.meta.pagination.page,
|
||
|
|
pageCount: response.meta.pagination.pageCount,
|
||
|
|
total: response.meta.pagination.total,
|
||
|
|
}
|
||
|
|
})
|