Make email and phone fields required in color requests
This commit is contained in:
@@ -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
|
||||
|
||||
22
database/migrations/018_make_contact_fields_required.sql
Normal file
22
database/migrations/018_make_contact_fields_required.sql
Normal file
@@ -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)';
|
||||
@@ -173,12 +173,13 @@ export default function ColorRequestModal({ isOpen, onClose }: ColorRequestModal
|
||||
|
||||
<div>
|
||||
<label htmlFor="user_email" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Email (opciono)
|
||||
Email *
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
id="user_email"
|
||||
name="user_email"
|
||||
required
|
||||
value={formData.user_email}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500 appearance-none"
|
||||
@@ -188,12 +189,13 @@ export default function ColorRequestModal({ isOpen, onClose }: ColorRequestModal
|
||||
|
||||
<div>
|
||||
<label htmlFor="user_phone" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Telefon (opciono)
|
||||
Telefon *
|
||||
</label>
|
||||
<input
|
||||
type="tel"
|
||||
id="user_phone"
|
||||
name="user_phone"
|
||||
required
|
||||
value={formData.user_phone}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500 appearance-none"
|
||||
|
||||
Reference in New Issue
Block a user