.ts
TypeScript
(application/typescript)
// 1st-party
import type { ReqHandler } from "@ethicdevs/react-monolith";
// app
import { AppRoute, AppRoutesParams } from "../../routes";
// app services
import { makeOrganizationService } from "../../services/organization";
import { makeRepositoryService } from "../../services/repository";
// app views
import RepositoryCommitsLogView, {
  RepositoryCommitsLogViewProps,
} from "../../views/repository/RepositoryCommitsLogView";

const getRepositoryCommitsLogView: ReqHandler = async (request, reply) => {
  const { orgSlug, repoSlug } =
    request.params as AppRoutesParams[AppRoute.REPOSITORY_BROWSER]["params"];

  const orgService = makeOrganizationService({ request });
  const repoService = makeRepositoryService({ request });

  const parentOrg = await orgService.getOrganizationBySlug(orgSlug);
  const repo = await repoService.getRepository(orgSlug, repoSlug);

  if (repo == null) {
    return reply.status(404).callNotFound();
  }

  const history = await repoService.getRepositoryCommitLog(repo);

  const reqHandler = reply.makeRequestHandler(request, reply);
  return reqHandler<RepositoryCommitsLogViewProps>(
    RepositoryCommitsLogView.name,
    {
      parentOrg,
      repo,
      history,
    }
  );
};

export default getRepositoryCommitsLogView;