Skip to content

Commit

Permalink
Merge pull request #92 from emil-webkom/POreq
Browse files Browse the repository at this point in the history
POreq
  • Loading branch information
Mauritzskog authored Sep 22, 2024
2 parents 29b778e + 5839893 commit 1c3f1d1
Show file tree
Hide file tree
Showing 32 changed files with 2,508 additions and 376 deletions.
Binary file added frontend/public/image/sponsorer/norconsult.pdf
Binary file not shown.
47 changes: 25 additions & 22 deletions frontend/src/app/api/hovedsamarbeidspartner/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { db } from "@/lib/db";
import { HovedsamarbeidspartnerSchema } from "@/schemas/hovedsamarbeidspartner";
import { NextRequest, NextResponse } from "next/server";

export const revalidate = 0;
Expand All @@ -12,11 +13,11 @@ export async function DELETE(req: NextRequest,
{ params }: { params: { id: string } },
) {
try {
await db.samarbeidspartner.delete({
await db.hovedsamarbeidspartner.delete({
where: { id: params.id },
});
return NextResponse.json(
{ message: "Successfully deleted samarbeidspartner" },
{ message: "Successfully deleted HSP" },
{ status: 200 },
);
} catch (error) {
Expand All @@ -27,27 +28,29 @@ export async function DELETE(req: NextRequest,
}
}

// /**
// * Updates a given instance in samarbeidspartner table
// * @param id: string
// * @param data: {FILL IN LATER}
// * @returns Response indicating if the update was successfull.
// */
// export async function PATCH(req: NextRequest,
// { params }: { params: { id: string } },
// ) {
// try {
// await db.samarbeidspartner.delete({
// where: { id: params.id },
// });
// return NextResponse.json(
// { message: "Successfully updated samarbeidspartner" },
// { status: 200 },
// );
// } catch (error) {
// return NextResponse.json(
// { message: "Internal server error" },
// { status: 500 },
// );
// }
// }

export async function PATCH(req: NextRequest,
{ params }: { params: { id: string } },
) {
const updateData = await req.json();
const parsedData = HovedsamarbeidspartnerSchema.parse(updateData);
try {
await db.hovedsamarbeidspartner.update({
where: { id: params.id },
data: parsedData
});
return NextResponse.json(
{ message: "Successfully updated hovedsamarbeidspartner" },
{ status: 200 },
);
} catch (error) {
return NextResponse.json(
{ message: "Internal server error" },
{ status: 500 },
);
}
}
33 changes: 16 additions & 17 deletions frontend/src/app/api/hovedsamarbeidspartner/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ export async function GET(req: NextRequest) {
* @param data: { FILL OUT LATER}
* @returns An instance of the object created or generic error message.
*/
// export async function POST(req: NextRequest) {
// try {
// const requestData = await req.json();
export async function POST(req: NextRequest) {
try {
const requestData = await req.json();

// const parsedData = createlavterskelArrangementSchema.parse(requestData);
// const newLavterskelArrangement = await db.lavterskelArrangement.create({
// data: parsedData,
// });
const HSP = await db.hovedsamarbeidspartner.create({
data: requestData,
});

// return NextResponse.json({
// success: true,
// message: "Arrangement created",
// data: newLavterskelArrangement,
// });
// } catch (error) {
// console.log("Error in the POST request");
// return NextResponse.json({ error: error }, { status: 400 });
// }
// }
return NextResponse.json({
success: true,
message: "HSP created",
data: HSP,
});
} catch (error) {
console.log("Error in the POST request");
return NextResponse.json({ error: error }, { status: 400 });
}
}
24 changes: 24 additions & 0 deletions frontend/src/app/api/kontigent/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { db } from "@/lib/db";
import { NextRequest, NextResponse } from "next/server";

export const revalidate = 0;

/**
* @param id: string
* @returns Response indicating if the deletion was successfull.
*/
export async function PATCH(req: NextRequest,
{ params }: { params: { id: string } },
) {
const data = await req.json()
try {
await db.kontigentpris.update({
where: { id: params.id },
data: { pris: data.pris }
});

return NextResponse.json({message: "Successfully updated instance:"}, { status: 200 });
} catch (error) {
return NextResponse.json({ error: error }, { status: 500 });
}
}
20 changes: 20 additions & 0 deletions frontend/src/app/api/kontigent/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";

export const revalidate = 0;
/**
* Function for fetching Kontigent
* @returns An array of the kontigent
*/
export async function GET(request: NextRequest) {
try {
const kontigent = await db.kontigentpris.findMany();
return NextResponse.json({status: 200, data: kontigent});
} catch (error) {
console.error("Error fetching aeresEmilere:", error);
return NextResponse.json(
{ error: "Failed to fetch aeresEmilere" },
{ status: 500 },
);
}
}
27 changes: 26 additions & 1 deletion frontend/src/app/api/lavterskelarrangement/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { db } from "@/lib/db";
import { lavTerskelArrangementSchema } from "@/schemas/lavterskelArrangement";
import { NextRequest, NextResponse } from "next/server";

export const revalidate = 0;
Expand All @@ -21,4 +22,28 @@ export async function DELETE(req: NextRequest,
);
}
}


export async function PATCH(req: NextRequest) {
try {
const requestData = await req.json();

if (requestData.dato) {
requestData.dato = new Date(requestData.dato);
}

const parsedData = lavTerskelArrangementSchema.parse(requestData);
const lavterskelArrangement = await db.lavterskelArrangement.update({
where: {id: parsedData.id},
data: parsedData,
});

return NextResponse.json({
success: true,
message: "Lavterskelarrangement upated",
data: lavterskelArrangement,
});
} catch (error) {
console.log("Error in the PATCH request");
return NextResponse.json({ error: error }, { status: 400 });
}
}
41 changes: 23 additions & 18 deletions frontend/src/app/api/samarbeidspartner/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { db } from "@/lib/db";
import { SamarbeidspartnerSchema } from "@/schemas/samarbeidspartner";
import { NextRequest, NextResponse } from "next/server";

export const revalidate = 0;
Expand Down Expand Up @@ -33,21 +34,25 @@ export async function DELETE(req: NextRequest,
// * @param data: {FILL IN LATER}
// * @returns Response indicating if the update was successfull.
// */
// export async function PATCH(req: NextRequest,
// { params }: { params: { id: string } },
// ) {
// try {
// await db.samarbeidspartner.delete({
// where: { id: params.id },
// });
// return NextResponse.json(
// { message: "Successfully updated samarbeidspartner" },
// { status: 200 },
// );
// } catch (error) {
// return NextResponse.json(
// { message: "Internal server error" },
// { status: 500 },
// );
// }
// }

export async function PATCH(req: NextRequest,
{ params }: { params: { id: string } },
) {
const updateData = await req.json();
const parsedData = SamarbeidspartnerSchema.parse(updateData);
try {
await db.samarbeidspartner.update({
where: { id: params.id },
data: parsedData
});
return NextResponse.json(
{ message: "Successfully updated hovedsamarbeidspartner" },
{ status: 200 },
);
} catch (error) {
return NextResponse.json(
{ message: "Internal server error" },
{ status: 500 },
);
}
}
37 changes: 18 additions & 19 deletions frontend/src/app/api/samarbeidspartner/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@ export async function GET(req: NextRequest) {
* @param data: { FILL OUT LATER}
* @returns An instance of the object created or generic error message.
*/
// export async function POST(req: NextRequest) {
// try {
// const requestData = await req.json();

// const parsedData = createlavterskelArrangementSchema.parse(requestData);
// const newLavterskelArrangement = await db.lavterskelArrangement.create({
// data: parsedData,
// });

// return NextResponse.json({
// success: true,
// message: "Arrangement created",
// data: newLavterskelArrangement,
// });
// } catch (error) {
// console.log("Error in the POST request");
// return NextResponse.json({ error: error }, { status: 400 });
// }
// }
export async function POST(req: NextRequest) {
try {
const requestData = await req.json();

const HSP = await db.samarbeidspartner.create({
data: requestData,
});

return NextResponse.json({
success: true,
message: "SP created",
data: HSP,
});
} catch (error) {
console.log("Error in the POST request");
return NextResponse.json({ error: error }, { status: 400 });
}
}
6 changes: 3 additions & 3 deletions frontend/src/app/api/users/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export const revalidate = 0;

export async function GET(request: NextRequest) {
try {
const hovedstyret = await db.user.findMany();
const users = await db.user.findMany();

if (!hovedstyret || hovedstyret.length === 0) {
if (!users || users.length === 0) {
return NextResponse.json({ message: "No data found" }, { status: 404 });
}
return NextResponse.json({ data: hovedstyret }, { status: 200 });
return NextResponse.json({ status: 200, data: users });
} catch (error) {
console.error("Error fetching users data:", error);
return NextResponse.json(
Expand Down
16 changes: 14 additions & 2 deletions frontend/src/app/for_studenten/komiteer/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import HSCard from '@/components/cards/styretCard';
import SmallTransissionPCSPC from '@/components/hero/transissions/smallTransissionPCSPC';
import { Button } from '@/components/ui/button';
import useFetch from '@/hooks/use-fetch';
import { Komite } from '@/schemas/komite';
import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -92,8 +93,19 @@ const KomitePage = ({ params }: { params: { id: string } }) => {
</>
)}
</div>
</div>

{data?.mappe && (
<div className='flex flex-col justify-center items-center p-4 gap-y-4'>
<p>{data.navn} har opptak!</p>
<a
href={data.mappe.startsWith('http') ? data.mappe : `https://${data.mappe}`}
target="_blank"
rel="noopener noreferrer"
>
<Button>Her kan du søke {data.navn}</Button>
</a>
</div>
)}
</div>
</div>
</div>
);
Expand Down
Loading

0 comments on commit 1c3f1d1

Please sign in to comment.