import { redirect } from "@sveltejs/kit";
import type { PageServerLoad } from "./$types";
import { UserController } from "$lib/domains/user/domain/controller";

export const load: PageServerLoad = async ({ locals }) => {
	const sess = locals.session;
	if (!sess) {
		return redirect(302, "/auth/login");
	}
	const userController = new UserController();
	const res = await userController.listChildUsers(sess.userId);
	return { users: res.error ? [] : res.data, error: res.error };
};
