2026-03-17 15:35:58 +01:00
|
|
|
export type HelpArticle = {
|
|
|
|
|
id: string;
|
|
|
|
|
slug: string;
|
|
|
|
|
title: string;
|
|
|
|
|
summary: string;
|
|
|
|
|
categoryKey: string;
|
2026-04-02 13:36:16 +02:00
|
|
|
category: string;
|
2026-03-17 15:35:58 +01:00
|
|
|
role: 'ALL' | 'company' | 'jobSeeker' | 'professional' | 'customer' | 'platform';
|
|
|
|
|
tags: string[];
|
|
|
|
|
updatedAt: string;
|
|
|
|
|
content: string;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-02 13:36:16 +02:00
|
|
|
export type HelpCategory = {
|
|
|
|
|
id: string;
|
|
|
|
|
key: string;
|
|
|
|
|
title: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ── API fetchers ──────────────────────────────────────────────────────────────
|
2026-03-17 15:35:58 +01:00
|
|
|
|
2026-04-02 13:36:16 +02:00
|
|
|
export async function fetchHelpCenterArticles(input: {
|
|
|
|
|
role?: string;
|
|
|
|
|
categoryKey?: string;
|
|
|
|
|
q?: string;
|
|
|
|
|
}): Promise<HelpArticle[]> {
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
if (input.role && input.role !== 'ALL') params.set('role', input.role);
|
|
|
|
|
if (input.categoryKey) params.set('category', input.categoryKey);
|
|
|
|
|
if (input.q) params.set('q', input.q);
|
2026-03-17 15:35:58 +01:00
|
|
|
|
2026-04-02 13:36:16 +02:00
|
|
|
try {
|
|
|
|
|
const res = await fetch(`/api/kb/articles?${params.toString()}`);
|
|
|
|
|
if (!res.ok) return [];
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
const raw: any[] = Array.isArray(data) ? data : (data.articles ?? []);
|
|
|
|
|
return raw.map(normalizeArticle);
|
|
|
|
|
} catch {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchHelpCenterCategories(): Promise<HelpCategory[]> {
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch('/api/kb/categories');
|
|
|
|
|
if (!res.ok) return [];
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
const raw: any[] = Array.isArray(data) ? data : (data.categories ?? []);
|
|
|
|
|
return raw.map((c) => ({
|
|
|
|
|
id: c.id,
|
|
|
|
|
key: c.slug,
|
|
|
|
|
title: c.name,
|
|
|
|
|
}));
|
|
|
|
|
} catch {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2026-03-17 15:35:58 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-02 13:36:16 +02:00
|
|
|
export async function fetchArticleBySlug(slug: string): Promise<HelpArticle | null> {
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`/api/kb/articles/${slug}`);
|
|
|
|
|
if (!res.ok) return null;
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
return normalizeArticle(data);
|
|
|
|
|
} catch {
|
|
|
|
|
return null;
|
2026-03-17 15:35:58 +01:00
|
|
|
}
|
2026-04-02 13:36:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Normalizer ────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
function normalizeArticle(raw: any): HelpArticle {
|
|
|
|
|
return {
|
|
|
|
|
id: raw.id ?? '',
|
|
|
|
|
slug: raw.slug ?? '',
|
|
|
|
|
title: raw.title ?? '',
|
|
|
|
|
summary: raw.summary ?? raw.content?.slice(0, 160) ?? '',
|
|
|
|
|
categoryKey: raw.categoryKey ?? raw.category_key ?? raw.categorySlug ?? '',
|
|
|
|
|
category: raw.category ?? raw.categoryKey ?? '',
|
|
|
|
|
role: (raw.role ?? 'ALL') as HelpArticle['role'],
|
|
|
|
|
tags: Array.isArray(raw.tags) ? raw.tags : [],
|
|
|
|
|
updatedAt: raw.updatedAt ?? raw.updated_at ?? new Date().toISOString(),
|
|
|
|
|
content: raw.content ?? raw.body ?? '',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Legacy sync shims (kept for any remaining call sites) ─────────────────────
|
|
|
|
|
// These return empty data synchronously — pages should use the async fetch* functions above.
|
|
|
|
|
|
|
|
|
|
export function listHelpCenterArticles(_input: { role?: string; categoryKey?: string; q?: string }): HelpArticle[] {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2026-03-17 15:35:58 +01:00
|
|
|
|
2026-04-02 13:36:16 +02:00
|
|
|
export function listHelpCenterCategories(): HelpCategory[] {
|
|
|
|
|
return [];
|
2026-03-17 15:35:58 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-02 13:36:16 +02:00
|
|
|
export function getArticleBySlug(_slug: string): HelpArticle | null {
|
|
|
|
|
return null;
|
2026-03-17 15:35:58 +01:00
|
|
|
}
|