Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

854 B
Raw Blame
import { and, eq } from "drizzle-orm";
import { HTTPException } from "hono/http-exception";
import db from "../../database";
import { projectTable } from "../../database/schema";
import type { IntegrationDatabase } from "../../plugins/github/services/integration-task-scope";

export async function getAuthorizedSyncProject(
  projectId: string,
  authorizedWorkspaceId: string,
  database: IntegrationDatabase = db,
  lock = false,
) {
  const query = database
    .select()
    .from(projectTable)
    .where(
      and(
        eq(projectTable.id, projectId),
        eq(projectTable.workspaceId, authorizedWorkspaceId),
      ),
    );
  const [project] = await (lock ? query.for("share") : query);
  if (!project)
    throw new HTTPException(403, {
      message: "Project no longer belongs to the authorized workspace",
    });
  return project;
}