mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 02:39:45 +00:00
Переделал запросы к постам
This commit is contained in:
1 parent
c66b352d3d
commit
26018016e1
7 files changed
+143
-129
No files matched your search
@@ -0,0 +1,29 @@
|
||||
// posts/api/get.ts
|
||||
import { wp } from "@/shared/api/wp-client";
|
||||
import { parseContent } from "@/shared/api/parseContent";
|
||||
import { App, WPv2 } from "@/shared/types/app";
|
||||
|
||||
export const fetchPostById = async (id: number): Promise<App.WpPostPage> => {
|
||||
const [post, categories] = await Promise.all([
|
||||
wp.posts().id(id).get() as Promise<WPv2.Post>,
|
||||
wp.categories().get() as Promise<WPv2.Category[]>
|
||||
]);
|
||||
|
||||
const categoryMap = new Map<number, string>(
|
||||
categories.map((c) => [c.id, c.name])
|
||||
);
|
||||
|
||||
const postCategories = post.categories.map(
|
||||
(id) => categoryMap.get(id) || ""
|
||||
);
|
||||
|
||||
const result: App.WpPostPage = {
|
||||
id: post.id,
|
||||
title: post.title.rendered,
|
||||
content: parseContent(post.content.rendered),
|
||||
categories: postCategories,
|
||||
tag: post.tags[0],
|
||||
};
|
||||
|
||||
return result;
|
||||
};
|
||||
Reference in new issue
Block a user