diff --git a/web/src/lib/check_db.ts b/web/src/lib/check_db.ts index ea7b691..82cdbab 100644 --- a/web/src/lib/check_db.ts +++ b/web/src/lib/check_db.ts @@ -6,51 +6,22 @@ const supabaseAnonKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYm const supabase = createClient(supabaseUrl, supabaseAnonKey); async function check() { - console.log("Checking insert..."); + console.log("Testing barber insert..."); - // Auth with a test user - const { data: authData, error: authErr } = await supabase.auth.signInWithPassword({ - email: 'test_shop_1773154696588@test.com', - password: 'Password123!' - }); + const shopId = 'e1e871f8-b88f-43c3-88de-e54b7b836ece'; // From previous output - if (authErr && !authData?.user) { - console.error("Login err:", authErr); - return; - } - - const userId = authData.user?.id; - console.log("User id:", userId); - - let { data: shops } = await supabase.from('shops').select('id').eq('owner_id', userId).limit(1); - - if (!shops || shops.length === 0) { - console.log("Creating new shop for user..."); - const res = await supabase.from('shops').insert([{ name: 'Test Shop RLS', owner_id: userId, rating: 5 }]).select(); - console.log("Create shop response:", res); - shops = res.data; - } - - if (!shops || shops.length === 0) { - console.error("Still no shop found!"); - return; - } - - const shopId = shops[0].id; - - console.log("Attempting to insert service to shop:", shopId); - - const { data: svc, error: svcErr } = await supabase.from('services').insert([ - { shop_id: shopId, name: 'Test Service', price: 10, duration: 15 } + // First try standard insert + const { data: b1, error: e1 } = await supabase.from('barbers').insert([ + { shop_id: shopId, name: 'Test Barber Basic' } ]).select(); - console.log("Insert service result:", svcErr || "SUCCESS", svc); + console.log("Insert without specialties:", e1 || "SUCCESS", b1); - const { data: bbr, error: bbrErr } = await supabase.from('barbers').insert([ - { shop_id: shopId, name: 'Test Barber' } + const { data: b2, error: e2 } = await supabase.from('barbers').insert([ + { shop_id: shopId, name: 'Test Barber Complex', specialties: ['corte'] } ]).select(); - console.log("Insert barber result:", bbrErr || "SUCCESS", bbr); + console.log("Insert with specialties:", e2 || "SUCCESS", b2); } check();