From 747d15f1c35a2764c2027e0050a7d9d6ee3cf3d0 Mon Sep 17 00:00:00 2001 From: DaX Date: Fri, 29 Aug 2025 12:44:00 +0200 Subject: [PATCH] Make email and phone fields required in color requests --- api/server.js | 7 ++++++ .../018_make_contact_fields_required.sql | 22 +++++++++++++++++++ src/components/ColorRequestModal.tsx | 6 +++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 database/migrations/018_make_contact_fields_required.sql diff --git a/api/server.js b/api/server.js index 87be374..0afbaea 100644 --- a/api/server.js +++ b/api/server.js @@ -265,6 +265,13 @@ app.post('/api/color-requests', async (req, res) => { reference_url } = req.body; + // Validate required fields + if (!color_name || !material_type || !user_email || !user_phone) { + return res.status(400).json({ + error: 'Color name, material type, email, and phone are required' + }); + } + // Check if similar request already exists const existingRequest = await pool.query( `SELECT id, request_count FROM color_requests diff --git a/database/migrations/018_make_contact_fields_required.sql b/database/migrations/018_make_contact_fields_required.sql new file mode 100644 index 0000000..c31d46d --- /dev/null +++ b/database/migrations/018_make_contact_fields_required.sql @@ -0,0 +1,22 @@ +-- Migration: Make email and phone fields required in color_requests table +-- These fields are now mandatory for all color requests + +-- First, update any existing NULL values to prevent constraint violation +UPDATE color_requests +SET user_email = 'unknown@example.com' +WHERE user_email IS NULL; + +UPDATE color_requests +SET user_phone = 'unknown' +WHERE user_phone IS NULL; + +-- Now add NOT NULL constraints +ALTER TABLE color_requests +ALTER COLUMN user_email SET NOT NULL; + +ALTER TABLE color_requests +ALTER COLUMN user_phone SET NOT NULL; + +-- Update comments to reflect the requirement +COMMENT ON COLUMN color_requests.user_email IS 'User email address for contact (required)'; +COMMENT ON COLUMN color_requests.user_phone IS 'User phone number for contact (required)'; \ No newline at end of file diff --git a/src/components/ColorRequestModal.tsx b/src/components/ColorRequestModal.tsx index 1a30c17..3143faa 100644 --- a/src/components/ColorRequestModal.tsx +++ b/src/components/ColorRequestModal.tsx @@ -173,12 +173,13 @@ export default function ColorRequestModal({ isOpen, onClose }: ColorRequestModal