aethex-forge/api/labs/bounties.ts
Builder.io d628272fec Update imports batch 61
cgen-7aa92e30710f470a9e953ab1ae564a55
2025-11-16 05:04:25 +00:00

51 lines
1.3 KiB
TypeScript

import { supabase } from "../_supabase.js";
export default async (req: Request) => {
if (req.method !== "GET") {
return new Response("Method not allowed", { status: 405 });
}
try {
const token = req.headers.get("Authorization")?.replace("Bearer ", "");
if (!token) {
return new Response("Unauthorized", { status: 401 });
}
const { data: userData } = await supabase.auth.getUser(token);
if (!userData.user) {
return new Response("Unauthorized", { status: 401 });
}
const { data: bounties, error } = await supabase
.from("labs_bounties")
.select(
`
id,
title,
description,
reward,
difficulty,
status,
research_track_id,
created_at
`,
)
.eq("status", "available")
.order("reward", { ascending: false });
if (error) {
console.error("Bounties fetch error:", error);
return new Response(JSON.stringify({ error: error.message }), {
status: 500,
});
}
return new Response(JSON.stringify(bounties || []), {
headers: { "Content-Type": "application/json" },
});
} catch (err: any) {
return new Response(JSON.stringify({ error: err.message }), {
status: 500,
});
}
};