GitFOSS
.ts
TypeScript
(application/typescript)
// 1st-party
import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";
// app
import { RepositoryWithForkedFromRepo } from "../../types";
// service
import type { RepositoryServiceDeps } from "./types";

const makeGetRepositoryById: ServiceMethodFactory<
  RepositoryServiceDeps,
  [string],
  Promise<RepositoryWithForkedFromRepo | null>
> = ({ request }) => {
  return async (repoId) => {
    const repository = await request.prisma.repository.findFirst({
      include: {
        forkedFromRepo: {
          select: {
            id: true,
            slug: true,
            displayName: true,
            organization: {
              select: {
                id: true,
                slug: true,
                displayName: true,
              },
            },
          },
        },
        forks: {
          select: {
            _count: true,
          },
        },
      },
      where: {
        id: repoId,
      },
    });
    return repository;
  };
};

export default makeGetRepositoryById;