pronounscc/frontend/src/routes/reports/+page.ts

24 lines
659 B
TypeScript
Raw Normal View History

2023-03-23 11:30:47 +01:00
import { ErrorCode, type APIError, type Report } from "$lib/api/entities";
2023-03-23 09:30:23 +01:00
import { apiFetchClient } from "$lib/api/fetch";
2023-03-23 11:30:47 +01:00
import { error } from "@sveltejs/kit";
2023-03-23 09:30:23 +01:00
export const load = async () => {
2023-03-23 11:30:47 +01:00
try {
const reports = await apiFetchClient<Report[]>("/admin/reports");
return { page: 0, isClosed: false, userId: null, reporterId: null, reports } as PageLoadData;
} catch (e) {
if ((e as APIError).code === ErrorCode.Forbidden) {
throw error(400, "You're not an admin");
}
throw e;
}
2023-03-23 09:30:23 +01:00
};
interface PageLoadData {
page: number;
isClosed: boolean;
userId: string | null;
reporterId: string | null;
reports: Report[];
}