# Mobile API Test Commands

## ✅ Your Database Setup
Based on the logs, you have:
- **Project ID**: 1
- **Database Name**: `treecensus_pune`

---

## 🚀 Test Commands (Copy & Paste)

### 1. Login API
```bash
curl -X POST "http://172.17.46.11:63318/api/mobile/project/1/login" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "email=anilqc" \
  -d "password=40bd001563085fc35165329ea1ff5c5ecbdbbeef"
```

**Expected Response:**
```json
{
  "tag": "login",
  "success": 1,
  "error": 0,
  "uid": 123,
  "email": "anilqc",
  "user": { ... },
  "token": "..."
}
```

---

### 2. Get Tree Details (Master Data)
```bash
curl -X POST "http://172.17.46.11:63318/api/mobile/project/1/treedetails" \
  -H "Content-Type: application/x-www-form-urlencoded"
```

**Expected Response:**
```json
{
  "tag": "treedetails",
  "success": 1,
  "error": 0,
  "treedetails": {
    "treeList": [...],
    "societyList": [...],
    "roadList": [...],
    ...
  }
}
```

---

### 3. Get Enumerators
```bash
curl -X POST "http://172.17.46.11:63318/api/mobile/project/1/getEnumerators" \
  -H "Content-Type: application/x-www-form-urlencoded"
```

**Expected Response:**
```json
{
  "tag": "getEnumerators",
  "success": 1,
  "error": 0,
  "enumerators": [
    {
      "uid": 1,
      "first_name": "John",
      "last_name": "Doe",
      "email": "john@example.com",
      ...
    }
  ]
}
```

---

### 4. Get Nearby Trees
```bash
curl -X POST "http://172.17.46.11:63318/api/mobile/project/1/getNearbyTrees" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "northLat=19.175641943211843" \
  -d "southLat=19.172044656788167" \
  -d "westLon=72.8424557195056" \
  -d "eastLon=72.84626428049437"
```

**Expected Response:**
```json
{
  "tag": "getNearbyTrees",
  "success": 1,
  "error": 0,
  "treedetail": [
    {
      "tree_details_id": 1,
      "latitude": 19.1747,
      "longitude": 72.8446,
      ...
    }
  ]
}
```

---

### 5. Store Tree Details
```bash
curl -X POST "http://172.17.46.11:63318/api/mobile/project/1/storetreedetails" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "user_id=1" \
  -d "sq_id=44" \
  -d "tree_id=11" \
  -d "latitude=19.17478031787302" \
  -d "longitude=72.84467864781618" \
  -d "old_latitude=19.1744846" \
  -d "old_longitude=72.8441885" \
  -d "drag_distance=61.06885" \
  -d "othername=test tree" \
  -d "grith_cm=100" \
  -d "height_mtr=15" \
  -d "canopy_dia_mtr=10" \
  -d "condition_id=1" \
  -d "remarks_id=1" \
  -d "other_remarks=test" \
  -d "dist_frm_prev_tree=10" \
  -d "ownership_id=1" \
  -d "ownership_name=" \
  -d "ownership_contact_no=" \
  -d "balImbalance_id=1" \
  -d "societyname=test society" \
  -d "roadname=test road" \
  -d "birdnest=0" \
  -d "googleAddress=Test Address" \
  -d "entered_date=2025-01-25" \
  -d "entered_time=12:00:00" \
  -d "updated_date=2025-01-25" \
  -d "ward=1" \
  -d "is_within_boundary=1" \
  -d "version=1.0" \
  -d "spatialcomment_id=1" \
  -d "date_of_plantation=" \
  -d "client_name=" \
  -d "contractor_name="
```

**Expected Response:**
```json
{
  "tag": "storetreedetails",
  "success": 1,
  "error": 0
}
```

---

## 🔧 PowerShell Commands (Windows)

If using PowerShell, use `curl.exe` instead of `curl`:

### Login (PowerShell)
```powershell
curl.exe -X POST "http://172.17.46.11:63318/api/mobile/project/1/login" `
  -H "Content-Type: application/x-www-form-urlencoded" `
  -d "email=anilqc&password=40bd001563085fc35165329ea1ff5c5ecbdbbeef"
```

### Tree Details (PowerShell)
```powershell
curl.exe -X POST "http://172.17.46.11:63318/api/mobile/project/1/treedetails" `
  -H "Content-Type: application/x-www-form-urlencoded"
```

---

## ⚠️ Important Notes

1. **Restart your Node.js server** after the code changes:
   ```bash
   cd Backend
   node app.js
   ```

2. **Check your database** has these tables in `treecensus_pune`:
   - `treeusers`
   - `treelist`
   - `treedetailsentered`
   - `condition`
   - `ownership`
   - `remarks`
   - `spacial_comment`
   - `bird_nest`
   - `treebal_imbalance`

3. **Verify user exists** in `treeusers` table with:
   - email: `anilqc`
   - password: (hashed version of the SHA1 hash you're sending)

---

## 🐛 Troubleshooting

### If you get "Project not found":
```sql
-- Check if project exists
SELECT * FROM treelogy WHERE treelogy_id = 1;
```

### If you get "relation does not exist":
```sql
-- Connect to project database
\c treecensus_pune

-- List all tables
\dt

-- If tables are missing, you need to run your migration script
```

### If login fails with "no such user":
```sql
-- Check if user exists
SELECT * FROM treeusers WHERE email = 'anilqc';

-- If not, create a test user:
INSERT INTO treeusers (first_name, last_name, email, password, mobile_no, user_type, enabled, created_at)
VALUES ('Anil', 'QC', 'anilqc', '$2a$10$...', '1234567890', 'QC', 1, NOW());
```

---

## ✅ What Was Fixed

1. **PostgreSQL Syntax**: Changed from MySQL `?` placeholders to PostgreSQL `$1, $2, $3`
2. **Query Results**: Properly handle Sequelize's `[results, metadata]` return format
3. **Response Format**: Added `tag` and `error` fields to match PHP API format
4. **All Endpoints**: Fixed all 20+ API endpoints with correct SQL syntax

---

## 📝 Next Steps

1. Restart server
2. Test login first
3. If login works, test other endpoints
4. Check server logs for any errors
5. Verify database has all required tables

