Update getContentItems to return total count and items
The changes involved modifying the implementation of `getContentItems` across multiple files, specifically in the CMS-related codebase. This method now returns an object containing the total count of items and the items themselves. The updates also included necessary adjustments in the code where `getContentItems` is called to accommodate the new structure of the returned result.
This commit is contained in:
@@ -79,12 +79,14 @@ export class WordpressClient implements CmsClient {
|
||||
|
||||
const url = `${this.apiUrl}${endpoint}`;
|
||||
|
||||
const posts = await fetch(url).then(
|
||||
(value) => value.json() as Promise<WP_REST_API_Post[]>,
|
||||
);
|
||||
const response = await fetch(url);
|
||||
const totalHeader = response.headers.get('X-WP-Total');
|
||||
|
||||
return Promise.all(
|
||||
posts.map(async (item: WP_REST_API_Post) => {
|
||||
const total = totalHeader ? Number(totalHeader) : 0;
|
||||
const results = (await response.json()) as WP_REST_API_Post[];
|
||||
|
||||
const posts = await Promise.all(
|
||||
results.map(async (item: WP_REST_API_Post) => {
|
||||
let parentId: string | undefined;
|
||||
|
||||
if (!item) {
|
||||
@@ -117,6 +119,11 @@ export class WordpressClient implements CmsClient {
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return {
|
||||
total,
|
||||
items: posts,
|
||||
};
|
||||
}
|
||||
|
||||
async getContentItemBySlug({
|
||||
|
||||
Reference in New Issue
Block a user