Skip to content

Commit

Permalink
feat: Setup queries for organisasi pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsanzizan committed Jun 12, 2024
1 parent d16b977 commit 1e5a3e7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/app/(main)/organisasi/[slug]/[period]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Organisasi_Type } from "@prisma/client";
import { notFound } from "next/navigation";

import { findOrganisasi } from "@/utils/database/organisasi.query";
import { findPeriod } from "@/utils/database/period.query";

export default async function OrganisasiByPeriod({
param,
}: {
param: { slug: string; period: string };
}) {
const period = await findPeriod(param.period);
if (!period) return notFound();

const organisasi = await findOrganisasi({
organisasi_period_id: {
organisasi: param.slug.toUpperCase() as Organisasi_Type,
period_id: period.id,
},
});
console.log(organisasi);

return <></>;
}
17 changes: 14 additions & 3 deletions src/app/(main)/organisasi/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { Organisasi_Type } from "@prisma/client";

import { findOrganisasi } from "@/utils/database/organisasi.query";
import { findLatestPeriod } from "@/utils/database/period.query";
import { findNewestPost } from "@/utils/database/post.query";

import Contact from "./components/parts/Contact";
Expand All @@ -10,9 +14,16 @@ import VisiMisi from "./components/parts/VisiMisi";
const image = "https://placehold.co/750x500?text=1";

export default async function Organ({ params }: { params: { slug: string } }) {
const organisasiName = params.slug.toUpperCase();
const organisasiType = params.slug.toUpperCase() as Organisasi_Type;
const latestPeriod = await findLatestPeriod();
const organisasi = await findOrganisasi({
organisasi_period_id: {
organisasi: organisasiType,
period_id: latestPeriod.id,
},
});
const relatedNews = await findNewestPost(5, {
tags: { some: { tagName: organisasiName } },
tags: { some: { tagName: organisasiType } },
});

return (
Expand All @@ -21,7 +32,7 @@ export default async function Organ({ params }: { params: { slug: string } }) {
<VisiMisi />
<Structure />
<OrgGallery image={image} />
<RelatedNews data={relatedNews} orgName={organisasiName} />
<RelatedNews data={relatedNews} orgName={organisasiType} />
<Contact />
</>
);
Expand Down
9 changes: 7 additions & 2 deletions src/utils/database/period.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import prisma from "@/lib/prisma";
export const findLatestPeriod = async () => {
const currentYear = new Date().getFullYear();
// Period year format example: 2023/2024
const latestPeriod = await prisma.period_Year.findUnique({
const latestPeriodYear = await prisma.period_Year.findUnique({
where: { period: `${currentYear}/${currentYear + 1}` },
});

return latestPeriod as Period_Year;
return latestPeriodYear as Period_Year;
};

export const findPeriod = async (period: string) => {
const periodYear = await prisma.period_Year.findUnique({ where: { period } });
return periodYear;
};

0 comments on commit 1e5a3e7

Please sign in to comment.