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:
+29
-8
@@ -1,5 +1,5 @@
|
|||||||
import {PageParams} from "@/types/next";
|
import {PageParams} from "@/types/next";
|
||||||
import {notFound} from "next/navigation";
|
import {notFound, redirect} from "next/navigation";
|
||||||
import {Page, PageActions, PageContent, PageDescription, PageTitle} from "@/features/layout/page";
|
import {Page, PageActions, PageContent, PageDescription, PageTitle} from "@/features/layout/page";
|
||||||
import {BackupButton} from "@/components/wrappers/dashboard/backup/backup-button/backup-button";
|
import {BackupButton} from "@/components/wrappers/dashboard/backup/backup-button/backup-button";
|
||||||
import {DatabaseTabs} from "@/components/wrappers/dashboard/projects/database/database-tabs";
|
import {DatabaseTabs} from "@/components/wrappers/dashboard/projects/database/database-tabs";
|
||||||
@@ -8,18 +8,38 @@ import {EditButton} from "@/components/wrappers/dashboard/database/edit-button/e
|
|||||||
import {CronButton} from "@/components/wrappers/dashboard/database/cron-button/cron-button";
|
import {CronButton} from "@/components/wrappers/dashboard/database/cron-button/cron-button";
|
||||||
|
|
||||||
import {db} from "@/db";
|
import {db} from "@/db";
|
||||||
import {eq, and} from "drizzle-orm";
|
import {eq, and, inArray} from "drizzle-orm";
|
||||||
import * as drizzleDb from "@/db";
|
import * as drizzleDb from "@/db";
|
||||||
|
import {getOrganizationProjectDatabases} from "@/lib/services";
|
||||||
|
import {getOrganization} from "@/lib/auth/auth";
|
||||||
|
|
||||||
export default async function RoutePage(props: PageParams<{ databaseId: string }>) {
|
export default async function RoutePage(props: PageParams<{
|
||||||
const {databaseId} = await props.params;
|
projectId: string;
|
||||||
|
databaseId: string
|
||||||
|
}>) {
|
||||||
|
const {projectId, databaseId} = await props.params;
|
||||||
|
|
||||||
|
console.log("ici", projectId);
|
||||||
|
console.log("laa", databaseId);
|
||||||
|
|
||||||
|
const organization = await getOrganization({});
|
||||||
|
|
||||||
|
if (!organization) {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const databasesProject = await getOrganizationProjectDatabases({
|
||||||
|
organizationSlug: organization.slug,
|
||||||
|
projectId: projectId
|
||||||
|
})
|
||||||
|
|
||||||
const dbItem = await db.query.database.findFirst({
|
const dbItem = await db.query.database.findFirst({
|
||||||
where: eq(drizzleDb.schemas.database.id, databaseId),
|
where: and(inArray(drizzleDb.schemas.backup.id, databasesProject.ids ?? []), eq(drizzleDb.schemas.database.id, databaseId), eq(drizzleDb.schemas.database.projectId, projectId)),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!dbItem) {
|
if (!dbItem) {
|
||||||
notFound();
|
redirect("/dashboard/projects");
|
||||||
}
|
}
|
||||||
|
|
||||||
const backups = await db.query.backup.findMany({
|
const backups = await db.query.backup.findMany({
|
||||||
@@ -67,8 +87,9 @@ export default async function RoutePage(props: PageParams<{ databaseId: string }
|
|||||||
</div>
|
</div>
|
||||||
<PageDescription className="mt-5 sm:mt-0">{dbItem.description}</PageDescription>
|
<PageDescription className="mt-5 sm:mt-0">{dbItem.description}</PageDescription>
|
||||||
<PageContent className="flex flex-col w-full h-full">
|
<PageContent className="flex flex-col w-full h-full">
|
||||||
<DatabaseKpi successRate={successRate} database={dbItem} totalBackups={totalBackups} />
|
<DatabaseKpi successRate={successRate} database={dbItem} totalBackups={totalBackups}/>
|
||||||
<DatabaseTabs database={dbItem} isAlreadyRestore={isAlreadyRestore} backups={backups} restorations={restorations} />
|
<DatabaseTabs database={dbItem} isAlreadyRestore={isAlreadyRestore} backups={backups}
|
||||||
|
restorations={restorations}/>
|
||||||
</PageContent>
|
</PageContent>
|
||||||
</Page>
|
</Page>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import Link from "next/link";
|
|||||||
import { ButtonDeleteProject } from "@/components/wrappers/dashboard/projects/button-delete-project/button-delete-project";
|
import { ButtonDeleteProject } from "@/components/wrappers/dashboard/projects/button-delete-project/button-delete-project";
|
||||||
import { CardsWithPagination } from "@/components/wrappers/common/cards-with-pagination";
|
import { CardsWithPagination } from "@/components/wrappers/common/cards-with-pagination";
|
||||||
import { ProjectDatabaseCard } from "@/components/wrappers/dashboard/projects/project-card/project-database-card";
|
import { ProjectDatabaseCard } from "@/components/wrappers/dashboard/projects/project-card/project-database-card";
|
||||||
import { notFound } from "next/navigation";
|
import {notFound, redirect} from "next/navigation";
|
||||||
|
|
||||||
import { db } from "@/db";
|
import { db } from "@/db";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
@@ -14,15 +14,12 @@ import {getOrganization} from "@/lib/auth/auth";
|
|||||||
import * as drizzleDb from "@/db";
|
import * as drizzleDb from "@/db";
|
||||||
|
|
||||||
export default async function RoutePage(props: PageParams<{
|
export default async function RoutePage(props: PageParams<{
|
||||||
// slug: string;
|
|
||||||
projectId: string
|
projectId: string
|
||||||
}>) {
|
}>) {
|
||||||
const {
|
const {
|
||||||
// slug: organizationSlug,
|
|
||||||
projectId } = await props.params;
|
projectId } = await props.params;
|
||||||
|
|
||||||
const organization = await getOrganization({});
|
const organization = await getOrganization({});
|
||||||
|
|
||||||
if (!organization) {
|
if (!organization) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
@@ -39,7 +36,9 @@ export default async function RoutePage(props: PageParams<{
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!proj) notFound();
|
if (!proj) {
|
||||||
|
redirect("/dashboard/projects");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ export const schemas = {
|
|||||||
|
|
||||||
export const db = drizzle({
|
export const db = drizzle({
|
||||||
client: pool,
|
client: pool,
|
||||||
logger: true,
|
// logger: true,
|
||||||
schema: schemas,
|
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