mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 12:25:22 +00:00
wrap repos query in withOptionalAuthV2
This commit is contained in:
parent
f6d5820ee2
commit
5035402287
1 changed files with 19 additions and 10 deletions
|
|
@ -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;
|
||||||
|
}));
|
||||||
Loading…
Reference in a new issue