forked from anudeep-danne/local-material-mate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-orders.js
More file actions
79 lines (69 loc) · 2.03 KB
/
Copy pathdebug-orders.js
File metadata and controls
79 lines (69 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = 'https://your-project.supabase.co';
const supabaseKey = 'your-anon-key';
const supabase = createClient(supabaseUrl, supabaseKey);
async function debugOrders() {
console.log('🔍 Debugging orders...');
// Check all orders
const { data: allOrders, error: allError } = await supabase
.from('orders')
.select('*')
.order('created_at', { ascending: false });
if (allError) {
console.error('Error fetching all orders:', allError);
return;
}
console.log('📊 All orders in database:', allOrders?.length || 0);
if (allOrders && allOrders.length > 0) {
allOrders.forEach((order, index) => {
console.log(`Order ${index + 1}:`, {
id: order.id,
vendor_id: order.vendor_id,
supplier_id: order.supplier_id,
status: order.status,
created_at: order.created_at
});
});
}
// Check orders with joins
const { data: ordersWithJoins, error: joinsError } = await supabase
.from('orders')
.select(`
*,
vendor:users!orders_vendor_id_fkey(
id,
name,
email,
role,
business_name
),
supplier:users!orders_supplier_id_fkey(
id,
name,
email,
role,
business_name
),
product:products!orders_product_id_fkey(*)
`)
.order('created_at', { ascending: false });
if (joinsError) {
console.error('Error fetching orders with joins:', joinsError);
return;
}
console.log('📊 Orders with joins:', ordersWithJoins?.length || 0);
if (ordersWithJoins && ordersWithJoins.length > 0) {
ordersWithJoins.forEach((order, index) => {
console.log(`Order with joins ${index + 1}:`, {
id: order.id,
vendor_id: order.vendor_id,
supplier_id: order.supplier_id,
status: order.status,
vendor: order.vendor,
supplier: order.supplier,
product: order.product
});
});
}
}
debugOrders().catch(console.error);