106 lines
2.9 KiB
TypeScript
106 lines
2.9 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
|
|
import { PrismaClient } from '@prisma/client';
|
|
import { env } from '@utils/env';
|
|
import { verifyJwt } from '@utils/verifyJwt';
|
|
|
|
const usingPrisma = false;
|
|
let prisma: PrismaClient;
|
|
if (usingPrisma) prisma = new PrismaClient();
|
|
|
|
// Artifact type
|
|
interface Artifact {
|
|
id: number;
|
|
name: string;
|
|
description: string;
|
|
location: string;
|
|
earthquakeId: string;
|
|
isRequired: boolean;
|
|
isSold: boolean;
|
|
isCollected: boolean;
|
|
dateAdded: string;
|
|
}
|
|
|
|
export async function POST(req: Request) {
|
|
try {
|
|
// todo fix, moron the token will be in the cookie header
|
|
const json = await req.json(); // Parse incoming JSON data
|
|
const { token } = json.body;
|
|
if (!token) return NextResponse.json({ message: "Unauthorised" }, { status: 401 });
|
|
await verifyJwt({ token, secret: env.JWT_SECRET_KEY });
|
|
|
|
const warehouseArtifacts: Artifact[] = [
|
|
{
|
|
id: 1,
|
|
name: "Solidified Lava Chunk",
|
|
description: "A chunk of solidified lava from the 2023 Iceland eruption.",
|
|
location: "Reykjanes, Iceland",
|
|
earthquakeId: "EQ2023ICL",
|
|
isRequired: true,
|
|
isSold: false,
|
|
isCollected: false,
|
|
dateAdded: "2025-05-04",
|
|
},
|
|
{
|
|
id: 2,
|
|
name: "Tephra Sample",
|
|
description: "Foreign debris from the 2022 Tonga volcanic eruption.",
|
|
location: "Tonga",
|
|
earthquakeId: "EQ2022TGA",
|
|
isRequired: false,
|
|
isSold: true,
|
|
isCollected: true,
|
|
dateAdded: "2025-05-03",
|
|
},
|
|
{
|
|
id: 3,
|
|
name: "Ash Sample",
|
|
description: "Volcanic ash from the 2021 La Palma eruption.",
|
|
location: "La Palma, Spain",
|
|
earthquakeId: "EQ2021LPA",
|
|
isRequired: false,
|
|
isSold: false,
|
|
isCollected: false,
|
|
dateAdded: "2025-05-04",
|
|
},
|
|
{
|
|
id: 4,
|
|
name: "Ground Soil",
|
|
description: "Soil sample from the 2020 Croatia earthquake site.",
|
|
location: "Zagreb, Croatia",
|
|
earthquakeId: "EQ2020CRO",
|
|
isRequired: true,
|
|
isSold: false,
|
|
isCollected: false,
|
|
dateAdded: "2025-05-02",
|
|
},
|
|
{
|
|
id: 5,
|
|
name: "Basalt Fragment",
|
|
description: "Basalt rock from the 2019 New Zealand eruption.",
|
|
location: "White Island, New Zealand",
|
|
earthquakeId: "EQ2019NZL",
|
|
isRequired: false,
|
|
isSold: true,
|
|
isCollected: false,
|
|
dateAdded: "2025-05-04",
|
|
},
|
|
];
|
|
|
|
let artifacts;
|
|
if (usingPrisma) artifacts = await prisma.artifacts.findMany();
|
|
|
|
if (artifacts) {
|
|
return NextResponse.json({ message: "Got artifacts successfully", artifacts }, { status: 200 });
|
|
} else {
|
|
return NextResponse.json({ message: "Got earthquakes successfully", earthquakes: warehouseArtifacts }, { status: 200 });
|
|
// return NextResponse.json({ message: "Failed to get earthquakes" }, { status: 401 });
|
|
}
|
|
} catch (error) {
|
|
console.error("Error in artifacts endpoint:", error);
|
|
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
|
|
} finally {
|
|
if (usingPrisma) await prisma.$disconnect();
|
|
}
|
|
}
|