mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 04:39:45 +00:00
Убрал категорию в получении одного поста по ID
This commit is contained in:
1 parent
dec6721456
commit
eb6d72f5db
1 file changed
+1
-13
@@ -4,24 +4,12 @@ import { parseContent } from "@/shared/api/parseContent";
|
|||||||
import { App, WPv2 } from "@/shared/types/app";
|
import { App, WPv2 } from "@/shared/types/app";
|
||||||
|
|
||||||
export const fetchPostById = async (id: number): Promise<App.WpPostPage> => {
|
export const fetchPostById = async (id: number): Promise<App.WpPostPage> => {
|
||||||
const [post, categories] = await Promise.all([
|
const post = await wp.posts().id(id).get() as WPv2.Post;
|
||||||
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 = {
|
const result: App.WpPostPage = {
|
||||||
id: post.id,
|
id: post.id,
|
||||||
title: post.title.rendered,
|
title: post.title.rendered,
|
||||||
content: parseContent(post.content.rendered),
|
content: parseContent(post.content.rendered),
|
||||||
categories: postCategories,
|
|
||||||
tag: post.tags[0],
|
tag: post.tags[0],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user