2025-05-04 16:04:44 +01:00
|
|
|
import { NextResponse } from "next/server";
|
2025-04-29 18:50:03 +01:00
|
|
|
|
2025-05-19 14:36:29 +01:00
|
|
|
import { PrismaClient } from "@prismaclient";
|
2025-04-29 18:50:03 +01:00
|
|
|
|
|
|
|
|
const usingPrisma = false;
|
|
|
|
|
let prisma: PrismaClient;
|
|
|
|
|
if (usingPrisma) prisma = new PrismaClient();
|
|
|
|
|
|
2025-05-12 13:42:44 +01:00
|
|
|
export async function POST(req: Request) {
|
2025-04-29 18:50:03 +01:00
|
|
|
try {
|
2025-05-13 23:05:14 +01:00
|
|
|
const json = await req.json();
|
|
|
|
|
const { rangeDaysPrev } = json.body;
|
2025-04-29 18:50:03 +01:00
|
|
|
|
2025-05-13 23:05:14 +01:00
|
|
|
const now = new Date();
|
|
|
|
|
const rangeBeginning = new Date();
|
|
|
|
|
rangeBeginning.setDate(rangeBeginning.getDate() - rangeDaysPrev);
|
2025-05-12 13:42:44 +01:00
|
|
|
|
2025-05-13 23:05:14 +01:00
|
|
|
const earthquakes = await prisma.earthquake.findMany({
|
|
|
|
|
where: {
|
|
|
|
|
date: {
|
|
|
|
|
gte: rangeBeginning,
|
|
|
|
|
lte: now,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
2025-04-29 18:50:03 +01:00
|
|
|
|
|
|
|
|
if (earthquakes) {
|
|
|
|
|
return NextResponse.json({ message: "Got earthquakes successfully", earthquakes }, { status: 200 });
|
|
|
|
|
} else {
|
2025-05-12 13:42:44 +01:00
|
|
|
return NextResponse.json({ message: "Got earthquakes successfully", earthquakes }, { status: 200 });
|
2025-04-29 18:50:03 +01:00
|
|
|
// return NextResponse.json({ message: "Failed to get earthquakes" }, { status: 401 });
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error in earthquakes endpoint:", error);
|
|
|
|
|
return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
|
|
|
|
|
} finally {
|
|
|
|
|
if (usingPrisma) await prisma.$disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|