Skip to content

Commit

Permalink
Merge pull request #54 from emil-webkom/16-admin-page
Browse files Browse the repository at this point in the history
16 admin page
  • Loading branch information
Mauritzskog authored Aug 30, 2024
2 parents c3a2ba9 + fd9bb2a commit ad1c31f
Show file tree
Hide file tree
Showing 33 changed files with 1,152 additions and 556 deletions.
9 changes: 9 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"clsx": "^2.1.1",
"cmdk": "^1.0.0",
"date-fns": "^3.6.0",
"date-fns-tz": "^3.1.3",
"firebase": "^10.12.3",
"geist": "^1.3.1",
"lucide-react": "^0.376.0",
Expand Down
57 changes: 28 additions & 29 deletions frontend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ datasource db {
}

model User {
id String @id @default(cuid())
name String?
email String @unique
emailVerified DateTime?
image String?
password String?
role UserRole @default(USER)
nummer Int?
isActive Boolean @default(true)
username String? @unique
accounts Account[]
paameldinger ArrangementPaamelding[]
bookings Booking[]
Hovedstyret Hovedstyret?
id String @id @default(cuid())
name String?
email String @unique
emailVerified DateTime?
image String?
password String?
role UserRole @default(USER)
nummer Int?
isActive Boolean @default(true)
username String? @unique
accounts Account[]
paameldinger ArrangementPaamelding[]
bookings Booking[]
Hovedstyret Hovedstyret?
lavterskelArrangements LavterskelArrangement[]
}

Expand Down Expand Up @@ -106,27 +106,13 @@ model Arrangement {
paameldinger ArrangementPaamelding[]
}

model LavterskelArrangement {
id String @id @default(cuid())
navn String
sted String?
dato DateTime
type String
beskrivelse String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String
user User @relation(fields: [userId], references: [id])
@@index([userId])
}

model Booking {
id String @id @default(cuid())
userID String
komiteID String?
item BookedItem
bookedAt DateTime
duration Int
duration Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
komite komite? @relation(fields: [komiteID], references: [id])
Expand All @@ -145,6 +131,19 @@ model ArrangementPaamelding {
@@unique([userID, arrangementID])
}

model LavterskelArrangement {
id String @id @default(cuid())
navn String
sted String?
dato DateTime
type String
beskrivelse String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String
user User @relation(fields: [userId], references: [id])
@@index([userId])
}
enum BookedItem {
KONTOR
ONE_SOUNDBOX
Expand Down
94 changes: 54 additions & 40 deletions frontend/src/app/api/arrangementer/[id]/paamelding/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getUserById } from "@/data/user";
import { db } from "@/lib/db";
import {
ArrangementPaamelding,
Expand All @@ -22,47 +23,60 @@ export async function GET(
}
}

export async function POST(
req: NextRequest,
{ params }: { params: { id: string } },
) {
try {
const arrangement = await db.arrangement.findFirst({
where: { id: params.id },
});
// export async function POST(
// req: NextRequest,
// { params }: { params: { id: string } },
// ) {
// try {
// const arrangement = await db.arrangement.findUnique({
// where: { id: params.id },
// });

if (!arrangement) {
return NextResponse.json({ error: "Arrangement not found" });
}
const parsedData = ArrangementPaameldingSchema.parse(await req.json());
console.log(parsedData);
const arrangementPaamelding = await db.arrangementPaamelding.create({
data: parsedData,
});
// if (!arrangement) {
// return NextResponse.json({ error: "Arrangement not found" });
// }
// const user = await getUserById(params.id);

await db.user.update({
where: { id: parsedData.userID },
data: {
paameldinger: {
connect: { id: arrangementPaamelding.id },
},
},
});
// const signup = await db.arrangementPaamelding.create({
// data: {
// user: {
// connect: { id: user?.id },
// },
// arrangement: {
// connect: { id: params.id },
// },
// },
// });

await db.arrangement.update({
where: { id: params.id },
data: {
paameldinger: {
connect: { id: arrangementPaamelding.id },
},
},
});
// // const parsedData = ArrangementPaameldingSchema.parse(await req.json());
// // console.log(parsedData);
// // const arrangementPaamelding = await db.arrangementPaamelding.create({
// // data: parsedData,
// // });

return NextResponse.json(
{ message: "Paamelding successfull", arrangementPaamelding },
{ status: 201 },
);
} catch (error) {
return NextResponse.json({ error: error }, { status: 500 });
}
}
// // await db.user.update({
// // where: { id: parsedData.userID },
// // data: {
// // paameldinger: {
// // connect: { id: arrangementPaamelding.id },
// // },
// // },
// // });

// // await db.arrangement.update({
// // where: { id: params.id },
// // data: {
// // paameldinger: {
// // connect: { id: arrangementPaamelding.id },
// // },
// // },
// // });

// return NextResponse.json(
// { message: "Paamelding successfull", arrangementPaamelding },
// { status: 201 },
// );
// } catch (error) {
// return NextResponse.json({ error: error }, { status: 500 });
// }
// }
35 changes: 32 additions & 3 deletions frontend/src/app/api/bookings/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,40 @@ import { db } from "@/lib/db";
import { NextRequest, NextResponse } from "next/server";
import { BookingSchema } from "@/schemas/booking";

export async function GET() {
const bookings = await db.booking.findMany();
return NextResponse.json(bookings, { status: 200 });
export async function GET(req: NextRequest) {
const { searchParams } = new URL(req.url);
const userID = searchParams.get("userID");

if (userID) {
try {
const bookings = await db.booking.findMany({
where: {
userID: userID,
},
});
return NextResponse.json(bookings, { status: 200 });
} catch (error) {
return NextResponse.json(
{ error: "Failed to fetch bookings" },
{ status: 500 },
);
}
} else {
try {
const bookings = await db.booking.findMany();
return NextResponse.json(bookings, { status: 200 });
} catch (error) {
return NextResponse.json(
{ error: "Failed to fetch bookings" },
{ status: 500 },
);
}
}
}

// const bookings = await db.booking.findMany();
// return NextResponse.json(bookings, { status: 200 });

export async function POST(req: NextRequest) {
try {
const parsedData = BookingSchema.parse(await req.json());
Expand Down
69 changes: 69 additions & 0 deletions frontend/src/app/for_studenten/arkiv/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"use client";

import MenuCard, {
MenuCardProps,
} from "@/components/ForStudenten/ui/menu-card";
import MenuCardView from "@/components/ForStudenten/ui/menu-card-view";
import { HandCoins, ScrollText, Archive, NotebookPen } from "lucide-react";

const ArkivPage = () => {
const cards: MenuCardProps[] = [
{
title: "Vedtekter",
logo: <ScrollText />,
description:
"Nedenfor finner du vedtektene til EMIL. Disse blir gjennomgått hvert år på budsjett- og vedtektsmøtet.",
buttonLabel: "Se vedtekter",
href: "https://www.youtube.com/watch?v=xvFZjo5PgG0&ab_channel=Duran",
},
{
title: "Søknader",
logo: <HandCoins />,
description:
"Her finner du alle tidligere søknader, både søknader til Leo's minnefond og Blomsterpotten.",
buttonLabel: "Se søknader",
href: "https://www.youtube.com/watch?v=xvFZjo5PgG0&ab_channel=Duran",
},
{
title: "Rapporter",
logo: <Archive />,
description:
"Se arkivet for en oversikt over gamle rapporter f. eks. diplomundersøkelsen og trivselsrapporter. ",
buttonLabel: "Se rapporter",
href: "https://www.youtube.com/watch?v=xvFZjo5PgG0&ab_channel=Duran",
},
{
title: "Hvordan føre bilag",
logo: <NotebookPen />,
description:
"Lurer du på hvordan du skal føre et bilag? Trykk på knappen nedenfor og les guiden.",
href: "https://www.youtube.com/watch?v=xvFZjo5PgG0&ab_channel=Duran",
buttonLabel: "Hvordan føre bilag",
},
];

return (
<div className="flex flex-col items-center justify-center p-12 gap-y-6">
<div className="flex flex-col space-y-4">
<h1 className=" text-white text-center font-semibold text-4xl w-full">
Viktige dokumenter
</h1>
<p className="text-white text-md text-center">
Her ligger alle viktige dokumenter som Emil publiserer hvert år. For å
se Diplomundersøkelsen må du trykke på “Se rapporter”.{" "}
</p>
</div>
<MenuCardView cards={cards}></MenuCardView>
</div>
);
};

export default ArkivPage;

// <MenuCard
// href="https://youtube.com"
// logo={<Speaker />}
// title="Soundbox"
// description="Emil har hele 2 soundboxer som studenter kan låne! Book en soundbox til en valgt dato eller tid. Ventetiden kan være lang så vær obs på å booke i god tid!"
// buttonLabel="Book Soundbox"
// ></MenuCard>
Loading

0 comments on commit ad1c31f

Please sign in to comment.