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

Quick reference for staff members to check themselves in/out using cURL.

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

## Authentication
Replace `YOUR_STAFF_JWT_TOKEN` with your actual staff JWT token (from login response).

---

## 1. Staff Check-In (Self-Service)

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

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

### Success Response
```json
{
  "status": "success",
  "message": "Check-in successful",
  "data": {
    "check_in_id": 123,
    "staff_id": 1,
    "staff_name": "John Doe",
    "check_in_time": "2025-01-15T09:00:00.000Z",
    "check_in_location": "Office, Erode",
    "check_in_latitude": 11.3410,
    "check_in_longitude": 77.7172,
    "status": "checked_in",
    "notes": "Morning check-in"
  }
}
```

---

## 2. Staff Check-Out (Self-Service)

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

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

### Success Response
```json
{
  "status": "success",
  "message": "Check-out successful",
  "data": {
    "check_in_id": 123,
    "staff_id": 1,
    "staff_name": "John Doe",
    "check_in_time": "2025-01-15T09:00:00.000Z",
    "check_out_time": "2025-01-15T18:00:00.000Z",
    "check_in_location": "Office, Erode",
    "check_out_location": "Office, Erode",
    "duration": {
      "hours": 9,
      "minutes": 0,
      "total_minutes": 540,
      "total_seconds": 32400
    },
    "status": "checked_out",
    "notes": "End of day"
  }
}
```

---

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

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

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

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

### Get Only Checked-Out Records
```bash
curl -X GET "http://192.168.1.3:3000/staff/check-in-out/history?status=checked_out" \
  -H "Authorization: Bearer YOUR_STAFF_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/staff/check-in-out/history?start_date=${TODAY}&end_date=${TODAY}" \
  -H "Authorization: Bearer YOUR_STAFF_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Success Response
```json
{
  "status": "success",
  "message": "Your check-in/out history retrieved successfully",
  "data": {
    "staff": {
      "id": 1,
      "name": "John Doe",
      "username": "johndoe"
    },
    "filters": {
      "start_date": "2025-01-01",
      "end_date": "2025-01-31",
      "status": null,
      "limit": null
    },
    "summary": {
      "total_records": 20,
      "checked_in": 1,
      "checked_out": 19,
      "total_duration_minutes": 10800,
      "average_duration_minutes": 568
    },
    "records": [
      {
        "id": 123,
        "staff_id": 1,
        "staff_name": "John Doe",
        "check_in_time": "2025-01-15T09:00:00.000Z",
        "check_out_time": "2025-01-15T18:00:00.000Z",
        "check_in_location": "Office, Erode",
        "check_out_location": "Office, Erode",
        "status": "checked_out",
        "duration": {
          "hours": 9,
          "minutes": 0,
          "total_minutes": 540,
          "total_seconds": 32400
        },
        "notes": "End of day"
      }
    ]
  }
}
```

---

## 4. Get Your Current Check-In Status

### Check If You're Currently Checked In
```bash
curl -X GET "http://192.168.1.3:3000/staff/check-in-status" \
  -H "Authorization: Bearer YOUR_STAFF_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Success Response (Checked In)
```json
{
  "status": "success",
  "message": "Current check-in status retrieved successfully",
  "data": {
    "is_checked_in": true,
    "check_in": {
      "check_in_id": 123,
      "check_in_time": "2025-01-15T09:00:00.000Z",
      "check_in_location": "Office, Erode",
      "check_in_latitude": 11.3410,
      "check_in_longitude": 77.7172,
      "current_duration": {
        "hours": 5,
        "minutes": 30,
        "total_minutes": 330,
        "total_seconds": 19800
      },
      "notes": "Morning check-in"
    },
    "timestamp": "2025-01-15T14:30:00.000Z"
  }
}
```

### Success Response (Not Checked In)
```json
{
  "status": "success",
  "message": "No active check-in found",
  "data": {
    "is_checked_in": false,
    "check_in": null
  }
}
```

---

## Complete Daily Workflow

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

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

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

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

---

## Pretty Print JSON Response

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

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

---

## 5. Check Already Checked-In Status (Self-Service)

Checks if the staff member is already checked in for today, and optionally compares with a `device_id`.

### cURL (Without Device ID)
```bash
curl -X GET "http://192.168.1.3:3000/staff/check-already-checkin" \
  -H "Authorization: Bearer YOUR_STAFF_JWT_TOKEN" \
  -H "Accept: application/json"
```

### cURL (With Device ID query parameter)
```bash
curl -X GET "http://192.168.1.3:3000/staff/check-already-checkin?device_id=device_123" \
  -H "Authorization: Bearer YOUR_STAFF_JWT_TOKEN" \
  -H "Accept: application/json"
```

### Response (Checked In - Same Device)
```json
{
  "status": "success",
  "is_checked_in": true,
  "data": {
    "check_in_id": 224,
    "check_in_time": "2026-07-19T06:06:21.000Z",
    "check_in_location": "Lat: 11.09590, Lng: 77.36740",
    "check_in_latitude": "11.09590000",
    "check_in_longitude": "77.36740000",
    "device_id": "device_123",
    "is_same_device": true,
    "current_duration": {
      "hours": 1,
      "minutes": 53,
      "total_minutes": 113,
      "total_seconds": 6811
    },
    "notes": null
  }
}
```

### Response (Not Checked In)
```json
{
  "status": "success",
  "is_checked_in": false,
  "data": null
}
```

---

## Key Differences from Admin Endpoints

| Feature | Staff Endpoints (`/staff/*`) | Admin Endpoints (`/admin/staff/*`) |
|--------|------------------------------|-----------------------------------|
| **Authentication** | Staff JWT token (any staff member) | Admin JWT token (admin only) |
| **Check-In/Out** | Self-service only | Can manage any staff member |
| **History** | Own history only | All staff history |
| **Status** | Own status only | All staff status |
| **Use Case** | Staff checking themselves in/out | Admin managing staff attendance |

---

## Notes

1. **Staff endpoints** (`/staff/*`) are for staff members to manage their own check-in/out
2. **Admin endpoints** (`/admin/staff/*`) are for admins to manage any staff member
3. You can only check yourself in/out using staff endpoints
4. Location tracking is optional but recommended
5. You must check in before checking out
6. You cannot check in twice without checking out first

---

## Error Handling

### Already Checked In
```json
{
  "status": "error",
  "message": "You are already checked in",
  "data": {
    "check_in_id": 122,
    "check_in_time": "2025-01-15T08:30:00.000Z",
    "check_in_location": "Office, Erode"
  }
}
```

### No Active Check-In (for check-out)
```json
{
  "status": "error",
  "message": "No active check-in found. Please check in first."
}
```

### Authentication Error
```json
{
  "status": "error",
  "message": "Invalid or expired token"
}
```

