# Fix Property Status Validation Error

## The Problem
"Validation error: Invalid status" occurs because:
1. Some properties have `NULL` or empty status
2. Some properties have invalid status values (not in: `upcoming`, `ongoing`, `completed`)
3. The status field is required but has no default value

## Solution Steps

### Step 1: Fix Database (Run on Production Server)

**Option A: Using psql directly**

```bash
# Connect to database
sudo -u postgres psql -d nre
```

Then run:
```sql
-- Check current status values
SELECT DISTINCT status, COUNT(*) 
FROM properties 
GROUP BY status 
ORDER BY status;

-- See invalid statuses
SELECT id, title, slug, status 
FROM properties 
WHERE status IS NULL 
   OR status = '' 
   OR status NOT IN ('upcoming', 'ongoing', 'completed');

-- FIX: Update all invalid statuses
UPDATE properties 
SET status = 'upcoming' 
WHERE status IS NULL 
   OR status = '' 
   OR status NOT IN ('upcoming', 'ongoing', 'completed');

-- Verify
SELECT DISTINCT status FROM properties;
-- Should only show: upcoming, ongoing, completed

\q
```

**Option B: One-line command**

```bash
sudo -u postgres psql -d nre -c "UPDATE properties SET status = 'upcoming' WHERE status IS NULL OR status = '' OR status NOT IN ('upcoming', 'ongoing', 'completed');"
```

### Step 2: Use Node.js Script (Alternative)

```bash
cd /media/nurul/New\ Volume/Nurul/repos/nre/full/nrel-cms

# Stop Strapi
pm2 stop nrel-cms

# Run fix script
NODE_ENV=production node fix-status-strapi.js

# Or use the new script
node scripts/fix-property-status.mjs

# Restart Strapi
pm2 start ecosystem.config.js
```

### Step 3: Manual Fix via Admin Panel

1. Go to: `https://cms.navana-realestate.com/admin`
2. Content Manager → Property
3. For each property with error:
   - Open the property
   - Set **status** to: `upcoming`, `ongoing`, or `completed`
   - Save

## What I Changed

I've added a `default: "upcoming"` to the status field in the schema. This helps, but you still need to fix existing invalid data in the database.

## After Fixing

1. **Refresh your browser** (hard refresh: Ctrl+Shift+R or Cmd+Shift+R)
2. The error should be gone
3. You can now edit properties normally

## Verify Fix

```sql
-- This should return 0 rows
SELECT COUNT(*) 
FROM properties 
WHERE status IS NULL 
   OR status NOT IN ('upcoming', 'ongoing', 'completed');
```

