GitFOSS
.ts
TypeScript
(application/typescript)
// 1st-party
import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";
// generated via script[generate:prisma]
import type { PullRequest, Repository } from "@prisma/client";
// service
import type {
  PullRequestSelectOrIncludes,
  PullRequestServiceDeps,
} from "./types";

const getPullRequestsInRepository: ServiceMethodFactory<
  PullRequestServiceDeps,
  [Repository, PullRequestSelectOrIncludes | undefined],
  Promise<PullRequest[]>
> = ({ request }) => {
  return async (repository, selectOrIncludes) => {
    const pullRequestsInRepository = await request.prisma.pullRequest.findMany({
      ...(selectOrIncludes || {}),
      where: {
        targetRepositoryId: repository.id,
      },
    });

    return pullRequestsInRepository;
  };
};

export default getPullRequestsInRepository;