completionId: cgen-5828f4bc911640c7ab9888129e0d788e
cgen-5828f4bc911640c7ab9888129e0d788e
This commit is contained in:
parent
6977313a86
commit
a30933cae8
1 changed files with 26 additions and 11 deletions
|
|
@ -44,21 +44,36 @@ export default async function handler(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Validate Supabase is initialized
|
||||||
|
if (!supabase) {
|
||||||
|
console.error("Supabase client not initialized");
|
||||||
|
return res.status(500).json({
|
||||||
|
error: "Server configuration error: Missing Supabase credentials",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// GET - Fetch all role mappings
|
// GET - Fetch all role mappings
|
||||||
if (req.method === "GET") {
|
if (req.method === "GET") {
|
||||||
const { data, error } = await supabase
|
try {
|
||||||
.from("discord_role_mappings")
|
const { data, error } = await supabase
|
||||||
.select("*")
|
.from("discord_role_mappings")
|
||||||
.order("created_at", { ascending: false });
|
.select("*")
|
||||||
|
.order("created_at", { ascending: false });
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("Supabase error:", error);
|
console.error("Supabase error:", error);
|
||||||
return res
|
return res.status(500).json({
|
||||||
.status(500)
|
error: `Failed to fetch role mappings: ${error.message}`,
|
||||||
.json({ error: "Failed to fetch role mappings" });
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json(data || []);
|
||||||
|
} catch (queryErr: any) {
|
||||||
|
console.error("Query error:", queryErr);
|
||||||
|
return res.status(500).json({
|
||||||
|
error: `Database query error: ${queryErr?.message || "Unknown error"}`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).json(data || []);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST - Create new role mapping
|
// POST - Create new role mapping
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue