mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import {auth, getOrganization} from "@/lib/auth/auth";
|
|
import {db} from "@/db";
|
|
import {and, eq} from "drizzle-orm";
|
|
import * as drizzleDb from "@/db";
|
|
|
|
|
|
export const getOrganizationProjectDatabases = async ({organizationSlug, projectId}: {
|
|
organizationSlug: string, projectId: string
|
|
}) => {
|
|
try {
|
|
|
|
const organization = await getOrganization({});
|
|
|
|
if (!organization) {
|
|
return {
|
|
name: "ErrorGettingOrganizationProjectDatabases",
|
|
message: "No organization found.",
|
|
status: 400,
|
|
cause: "Unknown error occurred.",
|
|
};
|
|
}
|
|
const databasesProject = await db.query.project.findFirst({
|
|
where: and(eq(drizzleDb.schemas.project.organizationId, organization.id), eq(drizzleDb.schemas.project.id, projectId)),
|
|
with: {
|
|
databases: true
|
|
}
|
|
});
|
|
|
|
if (!databasesProject) {
|
|
return {
|
|
name: "ErrorGettingOrganizationProjectDatabases",
|
|
message: "No organization found.",
|
|
status: 400,
|
|
cause: "Unknown error occurred.",
|
|
};
|
|
}
|
|
|
|
return {
|
|
data: databasesProject.databases,
|
|
ids: databasesProject.databases.map((project) => project.id)
|
|
}
|
|
|
|
|
|
} catch (e: any) {
|
|
const errorMessage = e?.response?.data?.message || e?.message || "Unknown auth error";
|
|
const status = e?.response?.status || 500;
|
|
|
|
console.error("API GettingOrganizationProjectDatabases error:", {
|
|
message: errorMessage,
|
|
status,
|
|
raw: e,
|
|
});
|
|
|
|
throw {
|
|
name: "ErrorGettingOrganizationProjectDatabases",
|
|
message: errorMessage,
|
|
status,
|
|
cause: e,
|
|
};
|
|
}
|
|
}; |