wrap repos query in withOptionalAuthV2

This commit is contained in:
bkellam 2025-10-17 14:47:53 -07:00
parent f6d5820ee2
commit 5035402287

View file

@ -1,10 +1,12 @@
import { auth } from "@/auth";
import { env } from "@/env.mjs"; import { env } from "@/env.mjs";
import { getPrismaClient } from "@/prisma";
import { RepoJob } from "@sourcebot/db"; import { RepoJob } from "@sourcebot/db";
import { Header } from "../components/header"; import { Header } from "../components/header";
import { RepoStatus } from "./columns"; import { RepoStatus } from "./columns";
import { RepositoryTable } from "./repositoryTable"; import { RepositoryTable } from "./repositoryTable";
import { sew } from "@/actions";
import { withOptionalAuthV2 } from "@/withAuthV2";
import { isServiceError } from "@/lib/utils";
import { ServiceErrorException } from "@/lib/serviceError";
function getRepoStatus(repo: { indexedAt: Date | null, jobs: RepoJob[] }): RepoStatus { function getRepoStatus(repo: { indexedAt: Date | null, jobs: RepoJob[] }): RepoStatus {
const latestJob = repo.jobs[0]; const latestJob = repo.jobs[0];
@ -23,14 +25,10 @@ export default async function ReposPage(props: { params: Promise<{ domain: strin
domain domain
} = params; } = params;
const session = await auth(); const repos = await getReposWithJobs();
const prisma = getPrismaClient(session?.user?.id); if (isServiceError(repos)) {
throw new ServiceErrorException(repos);
const repos = await prisma.repo.findMany({
include: {
jobs: true,
} }
});
return ( return (
<div> <div>
@ -54,3 +52,14 @@ export default async function ReposPage(props: { params: Promise<{ domain: strin
</div> </div>
) )
} }
const getReposWithJobs = async () => sew(() =>
withOptionalAuthV2(async ({ prisma }) => {
const repos = await prisma.repo.findMany({
include: {
jobs: true,
}
});
return repos;
}));