Foundation Admin - Individual Course Management
cgen-dd6ede011af647da8375af3d5c4f23b6
This commit is contained in:
parent
5f5ff4d920
commit
56cbf1e69e
1 changed files with 47 additions and 0 deletions
47
api/admin/foundation/courses/[id].ts
Normal file
47
api/admin/foundation/courses/[id].ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { createClient } from "@supabase/supabase-js";
|
||||
|
||||
const supabase = createClient(
|
||||
process.env.VITE_SUPABASE_URL!,
|
||||
process.env.SUPABASE_SERVICE_ROLE!
|
||||
);
|
||||
|
||||
export default async function handler(req: any, res: any) {
|
||||
const { id } = req.query;
|
||||
|
||||
if (req.method === "PUT") {
|
||||
try {
|
||||
const { is_published } = req.body;
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from("foundation_courses")
|
||||
.update({ is_published })
|
||||
.eq("id", id)
|
||||
.select();
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
res.status(200).json(data);
|
||||
} catch (error: any) {
|
||||
res
|
||||
.status(500)
|
||||
.json({ error: error.message || "Failed to update course" });
|
||||
}
|
||||
} else if (req.method === "DELETE") {
|
||||
try {
|
||||
const { error } = await supabase
|
||||
.from("foundation_courses")
|
||||
.delete()
|
||||
.eq("id", id);
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
res.status(200).json({ message: "Course deleted" });
|
||||
} catch (error: any) {
|
||||
res
|
||||
.status(500)
|
||||
.json({ error: error.message || "Failed to delete course" });
|
||||
}
|
||||
} else {
|
||||
res.status(405).json({ error: "Method not allowed" });
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue