Fix leads API null handling
This commit is contained in:
@@ -23,12 +23,12 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const lead = {
|
||||
name: body.name,
|
||||
business_name: body.businessName || body.business_name,
|
||||
phone: body.phone,
|
||||
email: body.email,
|
||||
source: body.source,
|
||||
business_name: body.businessName || body.business_name || null,
|
||||
phone: body.phone || null,
|
||||
email: body.email || null,
|
||||
source: body.source || null,
|
||||
status: body.status || 'new',
|
||||
notes: body.notes,
|
||||
notes: body.notes || null,
|
||||
}
|
||||
|
||||
const { data, error } = await supabase
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
-- Add missing columns to existing leads table
|
||||
ALTER TABLE leads ADD COLUMN IF NOT EXISTS source TEXT;
|
||||
ALTER TABLE leads ADD COLUMN IF NOT EXISTS email TEXT;
|
||||
|
||||
-- Add sample leads
|
||||
INSERT INTO leads (name, business_name, phone, status, source) VALUES
|
||||
('Juan', 'Restaurante La Niña', '+34 952 449 193', 'new', 'cold_call'),
|
||||
('Maria', 'Restaurante Trocadero', '+34 681 142 944', 'new', 'cold_call'),
|
||||
('Carlos', 'Restaurant No7', '+34 655 036 827', 'new', 'cold_call');
|
||||
+9
-14
@@ -1,6 +1,4 @@
|
||||
-- Leads Table for Supabase
|
||||
-- Run in SQL Editor
|
||||
|
||||
-- Create leads table
|
||||
CREATE TABLE IF NOT EXISTS leads (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
user_id TEXT DEFAULT 'default',
|
||||
@@ -9,19 +7,16 @@ CREATE TABLE IF NOT EXISTS leads (
|
||||
phone TEXT,
|
||||
email TEXT,
|
||||
source TEXT,
|
||||
status TEXT DEFAULT 'new' CHECK (status IN ('new', 'contacted', 'qualified', 'won', 'lost')),
|
||||
status TEXT DEFAULT 'new',
|
||||
notes TEXT,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_leads_user ON leads(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_leads_status ON leads(status);
|
||||
|
||||
-- Sample leads
|
||||
INSERT INTO leads (name, business_name, phone, status, source) VALUES
|
||||
('Juan García', 'Restaurante La Niña', '+34 952 449 193', 'new', 'cold_call'),
|
||||
('María López', 'Clínica Dental Málaga', '+34 951 123 456', 'contacted', 'website'),
|
||||
('Carlos Ruiz', 'Inmobiliaria Costa', '+34 600 123 456', 'qualified', 'referral');
|
||||
|
||||
-- Disable RLS for now
|
||||
-- Disable RLS
|
||||
ALTER TABLE leads DISABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Add sample leads
|
||||
INSERT INTO leads (name, business_name, phone, status, source) VALUES
|
||||
('Juan', 'Restaurante La Niña', '+34 952 449 193', 'new', 'cold_call'),
|
||||
('Maria', 'Restaurante Trocadero', '+34 681 142 944', 'new', 'cold_call'),
|
||||
('Carlos', 'Restaurant No7', '+34 655 036 827', 'new', 'cold_call');
|
||||
|
||||
Reference in New Issue
Block a user