new logic routes

This commit is contained in:
Profile Profile
2026-01-22 00:00:07 +03:00
parent c5b00af520
commit ec2daae26b
4 changed files with 160 additions and 19 deletions

View File

@@ -186,6 +186,98 @@ export async function getProfileArticleById(databaseId) {
/**
* Получить Anews пост по databaseId
*/
export async function getAnewsById(databaseId: number): Promise<SingleAnewsPost | null> {
const cacheKey = `anews:${databaseId}`;
return await cache.wrap(
cacheKey,
async () => {
const query = `
query GetAnewsById($id: ID!) {
aNews(id: $id, idType: DATABASE_ID) {
id
databaseId
title
content
excerpt
uri
slug
date
modified
status
featuredImage {
node {
id
sourceUrl
altText
caption
mediaDetails {
width
height
}
}
}
author {
node {
id
name
firstName
lastName
avatar {
url
}
description
uri
}
}
categories {
nodes {
id
name
slug
uri
description
}
}
tags {
nodes {
id
name
slug
uri
}
}
seo {
title
metaDesc
canonical
opengraphTitle
opengraphDescription
opengraphImage {
sourceUrl
}
}
}
}
`;
try {
const data = await fetchGraphQL(query, { id: databaseId });
return data?.aNews || null;
} catch (error) {
console.error(`Error fetching Anews post with ID ${databaseId}:`, error);
return null;
}
},
{ ttl: CACHE_TTL.POST_DETAIL } // Можно использовать отдельный TTL для деталей постов
);
}