import { client } from "$lib/server/lucia";
import { error } from "@sveltejs/kit";

const prisma = client;

export const load = async ({ params }) => {
    const some_user = await prisma.authUser.findUnique({
        where: {
            username: params.usernameProfile
        }
    });
    
    if (!some_user) {
        const wasNotfoundErrorMsg = 'User named ,,'+ params.usernameProfile +'"does not exist!'
        throw error(404, {message: wasNotfoundErrorMsg});
    }

    const notReversedPosts = await prisma.authPost.findMany({
        where: {
            author_username: params.usernameProfile
        }
    });
    const posts = notReversedPosts.reverse();
    return {
        posts
    };
};



