Fix consulting order processing and display

- Fix consulting history to show continuous time range (09:00 - 11:00) instead of listing individual slots
- Add foreign key relationships for consulting_slots (order_id and user_id)
- Fix handle-order-paid to query profiles(email, name) instead of full_name
- Add completed consulting sessions with recordings to Member Access page
- Add user_id foreign key constraint to consulting_slots table
- Add orders foreign key constraint for consulting_slots relationship

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
dwindown
2025-12-27 01:17:47 +07:00
parent 73c03285ea
commit 17440cdf89
10 changed files with 404 additions and 79 deletions

View File

@@ -24,17 +24,19 @@ serve(async (req: Request): Promise<Response> => {
const { order_id } = body;
console.log("[HANDLE-PAID] Processing paid order:", order_id);
console.log("[HANDLE-PAID] Request body:", JSON.stringify(body));
const supabaseUrl = Deno.env.get("SUPABASE_URL")!;
const supabaseServiceKey = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!;
const supabase = createClient(supabaseUrl, supabaseServiceKey);
// Get full order details with items AND consulting slots
// Use maybeSingle() in case there are no related records
const { data: order, error: orderError } = await supabase
.from("orders")
.select(`
*,
profiles(email, full_name),
profiles(email, name),
order_items (
product_id,
product:products (title, type)
@@ -48,12 +50,20 @@ serve(async (req: Request): Promise<Response> => {
)
`)
.eq("id", order_id)
.single();
.maybeSingle();
if (orderError || !order) {
console.error("[HANDLE-PAID] Order not found:", order_id, orderError);
if (orderError) {
console.error("[HANDLE-PAID] Database error:", orderError);
return new Response(
JSON.stringify({ success: false, error: "Order not found" }),
JSON.stringify({ success: false, error: "Database error", details: orderError.message }),
{ status: 500, headers: { ...corsHeaders, "Content-Type": "application/json" } }
);
}
if (!order) {
console.error("[HANDLE-PAID] Order not found:", order_id);
return new Response(
JSON.stringify({ success: false, error: "Order not found", order_id }),
{ status: 404, headers: { ...corsHeaders, "Content-Type": "application/json" } }
);
}
@@ -67,7 +77,7 @@ serve(async (req: Request): Promise<Response> => {
}));
const userEmail = order.profiles?.email || "";
const userName = order.profiles?.full_name || "Pelanggan";
const userName = order.profiles?.name || userEmail.split('@')[0] || "Pelanggan";
const orderItems = order.order_items as Array<{
product_id: string;
product: { title: string; type: string };
@@ -140,12 +150,13 @@ serve(async (req: Request): Promise<Response> => {
// Don't fail the entire process
}
}
}
// Send consulting notification with the consultingSlots data
await sendNotification(supabase, "consulting_scheduled", {
nama: userName,
email: userEmail,
order_id: order_id.substring(0, 8),
order_id_short: order_id.substring(0, 8),
tanggal_pesanan: new Date().toLocaleDateString("id-ID"),
total: `Rp ${order.total_amount.toLocaleString("id-ID")}`,
metode_pembayaran: order.payment_method || "Unknown",
@@ -188,7 +199,7 @@ serve(async (req: Request): Promise<Response> => {
await sendNotification(supabase, "payment_success", {
nama: userName,
email: userEmail,
order_id: order_id.substring(0, 8),
order_id_short: order_id.substring(0, 8),
tanggal_pesanan: new Date().toLocaleDateString("id-ID"),
total: `Rp ${order.total_amount.toLocaleString("id-ID")}`,
metode_pembayaran: order.payment_method || "Unknown",

View File

@@ -65,7 +65,7 @@ serve(async (req) => {
// Find the order by payment_reference or id
const { data: order, error: orderError } = await supabase
.from("orders")
.select("id, payment_status")
.select("id, payment_status, user_id, total_amount")
.or(`payment_reference.eq.${payload.order_id},id.eq.${payload.order_id}`)
.single();