import { eq, sql } from 'drizzle-orm'; import type { TopicPart } from '@erudit-js/core/content/topic'; export async function getTopicParts(fullId: string): Promise { const dbResult = await ERUDIT.db .select({ hasArticle: sql`(${ERUDIT.db.schema.topics.article} IS NOT NULL)`, hasSummary: sql`(${ERUDIT.db.schema.topics.summary} IS NOT NULL)`, hasPractice: sql`(${ERUDIT.db.schema.topics.practice} IS NOT NULL)`, }) .from(ERUDIT.db.schema.topics) .where(eq(ERUDIT.db.schema.topics.fullId, fullId)); const topic = dbResult?.[0]; if (!topic) { return []; } const parts: TopicPart[] = []; if (topic.hasArticle) { parts.push('article'); } if (topic.hasSummary) { parts.push('summary'); } if (topic.hasPractice) { parts.push('practice'); } return parts; } export async function getDefaultTopicPart(fullId: string): Promise { const parts = await getTopicParts(fullId); return parts[0]!; }