19 lines
545 B
TypeScript
19 lines
545 B
TypeScript
|
|
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 };
|
||
|
|
};
|