language-learning-app/frontend/src/routes/app/articles/+page.server.ts

19 lines
545 B
TypeScript
Raw Normal View History

2026-03-29 07:54:27 +00:00
import type { PageServerLoad } from './$types';
import { listArticlesBffArticlesGet } from '../../../client/sdk.gen.ts';
export const load: PageServerLoad = async ({ locals }) => {
const { data, response } = await listArticlesBffArticlesGet({
headers: { Authorization: `Bearer ${locals.authToken ?? ''}` }
});
if (!data || response.status !== 200) {
return { articles: [] };
}
const articles = [...data.articles].sort(
(a, b) => new Date(b.published_at).getTime() - new Date(a.published_at).getTime()
);
return { articles };
};