Fix leads API null handling
This commit is contained in:
@@ -23,12 +23,12 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
const lead = {
|
const lead = {
|
||||||
name: body.name,
|
name: body.name,
|
||||||
business_name: body.businessName || body.business_name,
|
business_name: body.businessName || body.business_name || null,
|
||||||
phone: body.phone,
|
phone: body.phone || null,
|
||||||
email: body.email,
|
email: body.email || null,
|
||||||
source: body.source,
|
source: body.source || null,
|
||||||
status: body.status || 'new',
|
status: body.status || 'new',
|
||||||
notes: body.notes,
|
notes: body.notes || null,
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data, error } = await supabase
|
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
|
-- Create leads table
|
||||||
-- Run in SQL Editor
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS leads (
|
CREATE TABLE IF NOT EXISTS leads (
|
||||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
user_id TEXT DEFAULT 'default',
|
user_id TEXT DEFAULT 'default',
|
||||||
@@ -9,19 +7,16 @@ CREATE TABLE IF NOT EXISTS leads (
|
|||||||
phone TEXT,
|
phone TEXT,
|
||||||
email TEXT,
|
email TEXT,
|
||||||
source TEXT,
|
source TEXT,
|
||||||
status TEXT DEFAULT 'new' CHECK (status IN ('new', 'contacted', 'qualified', 'won', 'lost')),
|
status TEXT DEFAULT 'new',
|
||||||
notes TEXT,
|
notes TEXT,
|
||||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_leads_user ON leads(user_id);
|
-- Disable RLS
|
||||||
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
|
|
||||||
ALTER TABLE leads DISABLE ROW LEVEL SECURITY;
|
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