.ts
TypeScript
(application/typescript)
// 1st-party
import { ReqHandler } from "@ethicdevs/react-monolith";
// generated via script[generate:prisma]
import { ResourceVisibility } from "@prisma/client";
import { join, resolve } from "node:path";
// app
import { Env } from "../../env";
import { makeRepositoryService } from "../../services/repository";
// app views
import RepositoryExploreView, {
  RepositoryExploreViewProps,
} from "../../views/repository/RepositoryExploreView";

const TEST_ENABLE_CREATE_REPOSITORY: boolean = false;

const getRepositoryExploreView: ReqHandler = async (request, reply) => {
  const repoService = makeRepositoryService({ request });

  if ((TEST_ENABLE_CREATE_REPOSITORY as boolean) === true) {
    const newRepo = await repoService.createRepository({
      parentOrgSlug: "ethicdevs",
      repoSlug: "gitfoss-on-gitfoss",
      repoData: {
        avatarUri: null,
        displayName: "GitFOSS on GitFOSS",
        keywords: ["gitfoss", "self-hosted", "git", "foss", "server"],
        shortDescription:
          "GitFOSS is a Git Server and Client that is Free and Open-Source Software and that you can easily self-host",
        visibility: ResourceVisibility.PUBLIC,
        websiteUrl: "https://gitfoss.io/gitfoss/gitfoss",
      },
      repoInitFlags: {
        orgRepositoriesDir: resolve(
          join(Env.GIT_REPOSITORIES_ROOT, "ethicdevs")
        ),
        withBaseReadmeFile: false,
        withLicenseFile: "",
      },
    });

    console.log("MADE REPO FROM API:", newRepo);
  }

  const repositories = await repoService.getRepositoryExploreCollection();

  const reqHandler = reply.makeRequestHandler(request, reply);
  return reqHandler<RepositoryExploreViewProps>(RepositoryExploreView.name, {
    repositories,
  });
};

export default getRepositoryExploreView;