import { redirect } from "@sveltejs/kit";
import type { PageServerLoad } from "./$types";
import { OrderController } from "$lib/domains/order/domain/controller";
import { OrderRepository } from "$lib/domains/order/data/repository";
import { db } from "@pkg/db";

export const load: PageServerLoad = async ({ locals }) => {
	const sess = locals.session;
	if (!sess) {
		return redirect(302, "/auth/login");
	}
	const oc = new OrderController(new OrderRepository(db));
	const res = await oc.listAllOrders();
	return { orders: res.data ?? [], error: res.error };
};
