Fix CreateInstanceForm and userOperations errors
Fixed type errors in CreateInstanceForm.tsx and userOperations.ts related to argument counts, property definitions, and Supabase update calls. Corrected the WhatsAppInstance type definition and ensured correct data passing to Supabase.
This commit is contained in:
parent
7bf6cdd8ce
commit
3e3b931ca7
@ -9,7 +9,7 @@ import { Loader2, Plus, AlertCircle } from 'lucide-react';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { restartInstance } from '@/services/whatsAppService';
|
||||
import { WhatsAppInstance } from '@/types/whatsAppTypes';
|
||||
import { updateUserWhatsAppInstance } from '@/services/whatsAppInstanceService';
|
||||
import { updateUserWhatsAppInstance } from '@/services/whatsAppInstance/userOperations';
|
||||
import { createEvolutionWebhook } from '@/services/whatsApp/webhookService';
|
||||
|
||||
interface CreateInstanceFormProps {
|
||||
@ -77,13 +77,14 @@ const CreateInstanceForm = ({ onInstanceCreated, initialInstanceName = '' }: Cre
|
||||
qrcode: response.qrcode || null,
|
||||
status: response.instance.state === 'open' ? 'connected' : 'disconnected',
|
||||
lastSeen: new Date().toISOString(),
|
||||
presence: 'offline'
|
||||
presence: 'offline',
|
||||
userId: normalizedEmail
|
||||
};
|
||||
|
||||
console.log('✅ Instância criada:', instanceData);
|
||||
|
||||
// Atualizar no banco de dados local
|
||||
await updateUserWhatsAppInstance(normalizedEmail, normalizedEmail, 'conectado');
|
||||
// Atualizar no banco de dados local com o número de telefone
|
||||
await updateUserWhatsAppInstance(normalizedEmail, normalizedEmail, 'conectado', fullPhoneNumber);
|
||||
|
||||
// Criar webhook na Evolution API
|
||||
await createEvolutionWebhook(normalizedEmail);
|
||||
|
||||
@ -7,7 +7,8 @@ import { supabase } from "@/integrations/supabase/client";
|
||||
export async function updateUserWhatsAppInstance(
|
||||
userEmail: string,
|
||||
instanceName: string,
|
||||
status: string
|
||||
status: string,
|
||||
phoneNumber?: string
|
||||
): Promise<void> {
|
||||
try {
|
||||
// ⚠️ PADRONIZAÇÃO CRÍTICA: Converter email para lowercase
|
||||
@ -30,12 +31,19 @@ export async function updateUserWhatsAppInstance(
|
||||
|
||||
if (existingUser) {
|
||||
// Atualizar registro existente
|
||||
const updateData: any = {
|
||||
instancia_zap: normalizedInstanceName,
|
||||
status_instancia: status
|
||||
};
|
||||
|
||||
// Adicionar telefone se fornecido
|
||||
if (phoneNumber) {
|
||||
updateData.whatsapp = phoneNumber;
|
||||
}
|
||||
|
||||
const { error: updateError } = await supabase
|
||||
.from('usuarios')
|
||||
.update({
|
||||
instancia_zap: normalizedInstanceName,
|
||||
status_instancia: status
|
||||
})
|
||||
.update(updateData)
|
||||
.eq('email', normalizedEmail);
|
||||
|
||||
if (updateError) {
|
||||
@ -45,14 +53,17 @@ export async function updateUserWhatsAppInstance(
|
||||
|
||||
console.log(`✅ Instância WhatsApp atualizada para ${normalizedEmail}: ${normalizedInstanceName} (${status})`);
|
||||
} else {
|
||||
// Criar novo registro
|
||||
// Criar novo registro - whatsapp é obrigatório na inserção
|
||||
const insertData = {
|
||||
email: normalizedEmail,
|
||||
instancia_zap: normalizedInstanceName,
|
||||
status_instancia: status,
|
||||
whatsapp: phoneNumber || '00000000000' // Valor padrão se não fornecido
|
||||
};
|
||||
|
||||
const { error: insertError } = await supabase
|
||||
.from('usuarios')
|
||||
.insert({
|
||||
email: normalizedEmail,
|
||||
instancia_zap: normalizedInstanceName,
|
||||
status_instancia: status
|
||||
});
|
||||
.insert(insertData);
|
||||
|
||||
if (insertError) {
|
||||
console.error('Erro ao criar registro de instância WhatsApp:', insertError);
|
||||
|
||||
@ -8,4 +8,5 @@ export interface WhatsAppInstance {
|
||||
qrcode?: string | null;
|
||||
connectionState?: 'open' | 'closed' | 'connecting' | string;
|
||||
presence?: 'online' | 'offline';
|
||||
lastSeen?: string;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user