Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async function RiskManagement({
const overview = await getRiskOverview();

if (overview?.risks === 0) {
redirect(`/${session.user.organizationId} /risk/register`);
redirect(`/${session.user.organizationId}/risk/register`);
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function Layout({ children, params }: LayoutProps) {
redirect("/");
}

const riskId = await params;
const { riskId } = await params;

if (!riskId) {
redirect(`/${session.user.organizationId}/risk`);
Expand All @@ -32,11 +32,11 @@ export default async function Layout({ children, params }: LayoutProps) {
backButtonHref={`/${orgId}/risk/register`}
items={[
{
path: `/${orgId}/risk/${riskId.riskId}`,
path: `/${orgId}/risk/${riskId}`,
label: t("risk.overview"),
},
{
path: `/${orgId}/risk/${riskId.riskId}/comments`,
path: `/${orgId}/risk/${riskId}/comments`,
label: t("common.comments.title"),
},
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface PageProps {
export default async function RiskPage({ searchParams, params }: PageProps) {
const { riskId } = await params;
const risk = await getRisk(riskId);

const users = await useUsers();
const t = await getI18n();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function getRisks({
...(assigneeId ? { ownerId: assigneeId } : {}),
};

const skip = (page ?? 1 - 1) * (pageSize ?? 10);
const skip = ((page ?? 1) - 1) * (pageSize ?? 10);

const risks = await db.risk.findMany({
where,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ import { RiskRegisterTable } from "./RiskRegisterTable";
import type { Metadata } from "next";
import { getI18n } from "@/locales/server";
import { setStaticParamsLocale } from "next-international/server";
import { auth } from "@/auth";
import { db } from "@bubba/db";
import { type RiskStatus, type Departments, Prisma } from "@bubba/db/types";
import { cache } from "react";
import type { RiskStatus, Departments } from "@bubba/db/types";
import { getRisks } from "./data/getRisks";

export default async function RiskRegisterPage({
params,
}: {
params: Promise<{ locale: string; search: string; page: number; pageSize: number; status: RiskStatus | null; department: Departments | null; assigneeId: string | null }>;
params: Promise<{
locale: string;
search: string;
page: number;
pageSize: number;
status: RiskStatus | null;
department: Departments | null;
assigneeId: string | null;
}>;
}) {
const { locale, search, page, pageSize, status, department, assigneeId } =
const { search, page, pageSize, status, department, assigneeId } =
await params;
const t = await getI18n();

const risks = await getRisks({
search: search || "",
Expand All @@ -40,59 +45,4 @@ export async function generateMetadata({
return {
title: t("risk.register.title"),
};
}

const getRisks = cache(
async ({
search,
page,
pageSize,
status,
department,
assigneeId,
}: {
search?: string;
page?: number;
pageSize?: number;
status?: RiskStatus | null;
department?: Departments | null;
assigneeId?: string | null;
}) => {
const session = await auth();

if (!session || !session.user.organizationId) {
return {
success: false,
error: "Unauthorized",
};
}

const where = {
organizationId: session.user.organizationId,
...(search && {
title: {
contains: search,
mode: Prisma.QueryMode.insensitive,
},
}),
...(status ? { status } : {}),
...(department ? { department } : {}),
...(assigneeId ? { ownerId: assigneeId } : {}),
};

const skip = ((page ?? 1) - 1) * (pageSize ?? 10);

const risks = await db.risk.findMany({
where,
skip,
take: pageSize,
include: {
owner: true,
},
});

return {
risks,
};
}
);
}