export default async function(req: Request): Promise<Response> {
const url =
"https://script.google.com/macros/s/AKfycbwzkp9Nr29pws2ShKq9ZlI1W-DaLmKBJbGBk8kYuw4bOkmyWvgdE7E6M5d6YwUITekf/exec";
try {
const response = await fetch(url);
const jsonData = await response.json();
const dataArray = jsonData.data;
const email = new URL(req.url).searchParams.get("email");
if (!email) {
const result = dataArray
.map((item: { date: string; email: string }) => JSON.stringify(item))
.join("");
return new Response(result, {
headers: { "Content-Type": "application/json" },
});
}
const record = dataArray.find((item: { email: string }) => item.email === email);
if (!record) {
return new Response("No record found for the provided email", { status: 404 });
}
return new Response(JSON.stringify({ date: record.date }), {
headers: { "Content-Type": "application/json" },
});
} catch (error) {
return new Response("Failed to fetch data", { status: 500 });
}
}