mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on some routing errors.
This commit is contained in:
+1
-1
@@ -37,7 +37,7 @@ export const schemas = {
|
||||
|
||||
export const db = drizzle({
|
||||
client: pool,
|
||||
logger: true,
|
||||
// logger: true,
|
||||
schema: schemas,
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user