update JobPresenter query to use findFirst.

This commit is contained in:
kaf-lamed-beyt
2023-07-16 15:21:19 +01:00
parent 184c24cace
commit 6099e06a71
2 changed files with 23 additions and 8 deletions
@@ -12,15 +12,31 @@ export class JobsListPresenter {
public async call({
slug,
userId,
}: {
slug: string;
userId: string;
}): Promise<Job[]> {
return this.#prismaClient.job.findMany({
}: Pick<Job, "slug"> & { userId: User["id"] }) {
const project = await this.#prismaClient.project.findFirst({
where: {
projectId: slug,
id: userId,
slug,
organization: {
members: {
some: {
userId,
},
},
},
},
select: {
jobs: {
where: {
internal: false,
},
},
},
});
if (!project) {
return undefined;
}
return project.jobs.filter((job) => !job.internal);
}
}
@@ -38,7 +38,6 @@ export const loader = async ({ request, params }: LoaderArgs) => {
const { projectParam } = params;
const userId = await requireUserId(request);
invariant(projectParam, "projectParam not found");
invariant(userId, "jobId not found");
try {
const jobsPresenter = new JobsListPresenter();