import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";
import type { PullRequest } from "@prisma/client";
import { default as makeGetRepository } from "../repository/getRepository";
import type {
PullRequestSelectOrIncludes,
PullRequestServiceDeps,
} from "./types";
const getPullRequestByUid: ServiceMethodFactory<
PullRequestServiceDeps,
[string, string, number, PullRequestSelectOrIncludes | undefined],
Promise<PullRequest | null>
> = ({ request }) => {
const getRepository = makeGetRepository({ request });
return async (orgSlug, repoSlug, pullRequestUid, selectOrIncludes) => {
const repo = await getRepository(orgSlug, repoSlug);
if (repo == null) return null;
const pullRequest = await request.prisma.pullRequest.findUnique({
...(selectOrIncludes || {}),
where: {
uid_targetRepositoryId: {
targetRepositoryId: repo.id,
uid: pullRequestUid,
},
},
});
return pullRequest;
};
};
export default getPullRequestByUid;