diff --git a/src/hooks/useOFsAtivas.tsx b/src/hooks/useOFsAtivas.tsx index 5bc6bc3..0d48ed1 100644 --- a/src/hooks/useOFsAtivas.tsx +++ b/src/hooks/useOFsAtivas.tsx @@ -14,17 +14,29 @@ export const useOFsAtivas = () => { queryKey: ['ofs-ativas'], queryFn: async () => { const { data, error } = await supabase - .from('ficha_tecnica_contratos') - .select('of_number, descricao_resumida, cliente, gestor') - .not('of_number', 'is', null) - .order('of_number'); + .from('ordens_fabricacao') + .select(` + num_of, + descritivo, + gestor, + ficha_tecnica_contratos ( + cliente + ) + `) + .eq('status', 'ativa') + .order('num_of'); if (error) { console.error('Erro ao buscar OFs ativas:', error); throw error; } - return data as OFAtiva[]; + return data.map((of: any) => ({ + of_number: of.num_of, + descricao_resumida: of.descritivo, + gestor: of.gestor, + cliente: of.ficha_tecnica_contratos?.cliente + })) as OFAtiva[]; }, }); diff --git a/src/hooks/useTasks.tsx b/src/hooks/useTasks.tsx index 5f028c0..40db222 100644 --- a/src/hooks/useTasks.tsx +++ b/src/hooks/useTasks.tsx @@ -182,17 +182,28 @@ export const useTasks = () => { queryFn: async () => { console.log('🔍 Fetching available OFs...'); const { data, error } = await supabase - .from('ficha_tecnica_contratos') - .select('of_number, cliente') - .order('of_number'); + .from('ordens_fabricacao') + .select(` + num_of, + ficha_tecnica_contratos ( + cliente + ) + `) + .eq('status', 'ativa') + .order('num_of'); if (error) { console.error('❌ Error fetching OFs:', error); throw error; } - console.log('✅ Available OFs fetched:', data?.length || 0); - return data || []; + const mappedData = data?.map((of: any) => ({ + of_number: of.num_of, + cliente: of.ficha_tecnica_contratos?.cliente + })); + + console.log('✅ Available OFs fetched:', mappedData?.length || 0); + return mappedData || []; }, }); diff --git a/src/hooks/useTasksEnhanced.tsx b/src/hooks/useTasksEnhanced.tsx index cbd58f0..aa8e4ed 100644 --- a/src/hooks/useTasksEnhanced.tsx +++ b/src/hooks/useTasksEnhanced.tsx @@ -316,17 +316,28 @@ export const useTasksEnhanced = () => { if (!user) throw new Error('Usuário não autenticado'); const { data, error } = await supabase - .from('ficha_tecnica_contratos') - .select('of_number, cliente') - .order('of_number'); + .from('ordens_fabricacao') + .select(` + num_of, + ficha_tecnica_contratos ( + cliente + ) + `) + .eq('status', 'ativa') + .order('num_of'); if (error) { console.error('❌ Error fetching OFs:', error); throw error; } - console.log('✅ Available OFs fetched:', data?.length || 0); - return data || []; + const mappedData = data?.map((of: any) => ({ + of_number: of.num_of, + cliente: of.ficha_tecnica_contratos?.cliente + })); + + console.log('✅ Available OFs fetched:', mappedData?.length || 0); + return mappedData || []; }, enabled: !!user, });