# Staff Check-In/Check-Out API - cURL Examples

Quick reference for testing staff check-in/check-out APIs with cURL.

## Base URL
```
http://192.168.1.3:3000
```

## Authentication
Replace `YOUR_ADMIN_JWT_TOKEN` with your actual admin JWT token.

---

## 1. Staff Check-In

### Basic Check-In
```bash
curl -X POST "http://192.168.1.3:3000/admin/staff/check-in" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -d '{}'
```

### Check-In with Location
```bash
curl -X POST "http://192.168.1.3:3000/admin/staff/check-in" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -d '{
    "latitude": 11.3410,
    "longitude": 77.7172,
    "location": "Office, Erode, Tamil Nadu",
    "notes": "Morning check-in"
  }'
```

### Check-In for Specific Staff
```bash
curl -X POST "http://192.168.1.3:3000/admin/staff/check-in" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -d '{
    "staff_id": 1,
    "latitude": 11.3410,
    "longitude": 77.7172,
    "location": "Office, Erode",
    "notes": "Staff check-in"
  }'
```

---

## 2. Staff Check-Out

### Basic Check-Out
```bash
curl -X POST "http://192.168.1.3:3000/admin/staff/check-out" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -d '{}'
```

### Check-Out with Location
```bash
curl -X POST "http://192.168.1.3:3000/admin/staff/check-out" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -d '{
    "latitude": 11.3410,
    "longitude": 77.7172,
    "location": "Office, Erode, Tamil Nadu",
    "notes": "End of day"
  }'
```

### Check-Out for Specific Staff
```bash
curl -X POST "http://192.168.1.3:3000/admin/staff/check-out" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -d '{
    "staff_id": 1,
    "latitude": 11.3410,
    "longitude": 77.7172,
    "location": "Office, Erode",
    "notes": "Staff check-out"
  }'
```

---

## 3. Get Check-In/Check-Out History

### Get All History
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-out/history" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Get History with Date Range
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-out/history?start_date=2025-01-01&end_date=2025-01-31" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Get History for Specific Staff
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/1/check-in-out/history" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Get History for Specific Staff with Date Range
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/1/check-in-out/history?start_date=2025-01-01&end_date=2025-01-31" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Get Only Checked-In Records
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-out/history?status=checked_in" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Get Only Checked-Out Records
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-out/history?status=checked_out" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Get History with Limit
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-out/history?limit=50" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Get Today's History
```bash
TODAY=$(date +%Y-%m-%d)
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-out/history?start_date=${TODAY}&end_date=${TODAY}" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

---

## 4. Get Current Check-In Status

### Get All Currently Checked-In Staff
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-status" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Get Check-In Status for Specific Staff
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-status?staff_id=1" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

---

## Complete Workflow Example

### 1. Check-In
```bash
curl -X POST "http://192.168.1.3:3000/admin/staff/check-in" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -d '{
    "latitude": 11.3410,
    "longitude": 77.7172,
    "location": "Office, Erode",
    "notes": "Morning check-in"
  }'
```

### 2. Check Current Status
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-status" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

### 3. Check-Out
```bash
curl -X POST "http://192.168.1.3:3000/admin/staff/check-out" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -d '{
    "latitude": 11.3410,
    "longitude": 77.7172,
    "location": "Office, Erode",
    "notes": "End of day"
  }'
```

### 4. View Today's History
```bash
TODAY=$(date +%Y-%m-%d)
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-out/history?start_date=${TODAY}&end_date=${TODAY}" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

---

## Pretty Print JSON Response

Add `| python3 -m json.tool` or `| jq` to format the response:

```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-status" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json" | python3 -m json.tool
```

Or with `jq`:
```bash
curl -X GET "http://192.168.1.3:3000/admin/staff/check-in-status" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json" | jq
```

---

## Testing Tips

1. **Get your JWT token** from the admin login response
2. **Test check-in first** before check-out
3. **Use date filters** to narrow down history results
4. **Check current status** to see who's checked in
5. **Use staff_id** to manage other staff members (if you have permission)

---

## Error Handling

If you get authentication errors, make sure:
- The JWT token is valid and not expired
- The token is in the format: `Bearer YOUR_TOKEN`
- You're using the correct admin account

If you get "already checked in" error:
- Check out first before checking in again
- Or use the history endpoint to see existing check-ins

