Skip to content

Staff API

API for managing staff information and work schedules

GET /staff

Get all staff members

Query Parameters

ParameterTypeDescriptionDefault
pagenumberCurrent page1
limitnumberItems per page20
rolestringFilter by role-
activebooleanShow only activetrue

Response

json
{
  "success": true,
  "data": [
    {
      "id": "staff_123456",
      "name": "Daeng",
      "email": "daeng@salon.com",
      "phone": "081-234-5678",
      "role": "staff",
      "avatar": "https://example.com/avatar/daeng.jpg",
      "services": ["svc_456", "svc_789"],
      "isActive": true,
      "totalBookings": 200,
      "rating": 4.9,
      "createdAt": "2023-01-15T08:30:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 10,
    "totalPages": 1
  }
}

GET /staff/:id

Get staff details by ID

Path Parameters

ParameterTypeDescription
idstringStaff ID (e.g., staff_123456)

Response

json
{
  "success": true,
  "data": {
    "id": "staff_123456",
    "name": "Daeng",
    "email": "daeng@salon.com",
    "phone": "081-234-5678",
    "role": "staff",
    "avatar": "https://example.com/avatar/daeng.jpg",
    "bio": "10 years of experience",
    "services": [
      {
        "id": "svc_456",
        "name": "Haircut",
        "price": 350
      }
    ],
    "schedule": {
      "monday": { "start": "09:00", "end": "18:00" },
      "tuesday": { "start": "09:00", "end": "18:00" },
      "wednesday": { "start": "09:00", "end": "18:00" },
      "thursday": { "start": "09:00", "end": "18:00" },
      "friday": { "start": "09:00", "end": "18:00" },
      "saturday": { "start": "10:00", "end": "16:00" },
      "sunday": null
    },
    "isActive": true,
    "stats": {
      "totalBookings": 200,
      "thisMonth": 35,
      "averageRating": 4.9,
      "completedBookings": 198,
      "cancelledBookings": 2
    },
    "createdAt": "2023-01-15T08:30:00Z",
    "updatedAt": "2024-01-10T12:00:00Z"
  }
}

GET /staff/:id/schedule

Get staff work schedule

Query Parameters

ParameterTypeDescriptionDefault
fromstringStart date (ISO 8601)Today
tostringEnd date (ISO 8601)+7 days

Response

json
{
  "success": true,
  "data": {
    "staffId": "staff_123456",
    "schedule": [
      {
        "date": "2024-01-15",
        "slots": [
          { "time": "09:00", "available": false, "bookingId": "bk_123" },
          { "time": "10:00", "available": true },
          { "time": "11:00", "available": true },
          { "time": "12:00", "available": false, "break": true },
          { "time": "13:00", "available": true }
        ]
      }
    ]
  }
}

POST /staff

Create a new staff member

Request Body

json
{
  "name": "Daeng",
  "email": "daeng@salon.com",
  "phone": "081-234-5678",
  "role": "staff",
  "password": "secure_password",
  "services": ["svc_456", "svc_789"],
  "schedule": {
    "monday": { "start": "09:00", "end": "18:00" },
    "tuesday": { "start": "09:00", "end": "18:00" },
    "wednesday": { "start": "09:00", "end": "18:00" },
    "thursday": { "start": "09:00", "end": "18:00" },
    "friday": { "start": "09:00", "end": "18:00" },
    "saturday": { "start": "10:00", "end": "16:00" },
    "sunday": null
  }
}
FieldTypeRequiredDescription
namestringFull name
emailstringEmail (must be unique)
phonestringPhone number
rolestringstaff, manager, admin
passwordstringPassword
servicesstring[]Services the staff handles
scheduleobjectWork schedule

Response

json
{
  "success": true,
  "data": {
    "id": "staff_789012",
    "name": "Daeng",
    "email": "daeng@salon.com",
    "role": "staff",
    "createdAt": "2024-01-15T09:00:00Z"
  },
  "message": "Staff member created successfully"
}

PATCH /staff/:id

Update staff information

Request Body

json
{
  "name": "Daeng Smith",
  "phone": "089-123-4567",
  "services": ["svc_456", "svc_789", "svc_012"],
  "isActive": true
}

Response

json
{
  "success": true,
  "data": {
    "id": "staff_123456",
    "name": "Daeng Smith",
    "updatedAt": "2024-01-15T09:30:00Z"
  },
  "message": "Staff updated successfully"
}

DELETE /staff/:id

Delete a staff member (Soft delete)

Query Parameters

ParameterTypeRequiredDescription
transferBookingsstringTransfer bookings to another staff member

Response

json
{
  "success": true,
  "message": "Staff member deleted successfully"
}

Example Code

Get Available Slots for Staff

typescript
async function getAvailableSlots(staffId: string, date: string) {
  const response = await fetch(
    `https://api.booking-platform.com/v1/staff/${staffId}/schedule?from=${date}&to=${date}`,
    {
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
      },
    }
  );

  const { data } = await response.json();
  
  // Filter only available slots
  const availableSlots = data.schedule[0].slots
    .filter(slot => slot.available)
    .map(slot => slot.time);
    
  return availableSlots;
}

// Usage
const slots = await getAvailableSlots('staff_123456', '2024-01-15');
console.log('Available times:', slots);

Update Work Schedule

typescript
async function updateStaffSchedule(staffId: string, schedule: {
  [key: string]: { start: string; end: string } | null;
}) {
  const response = await fetch(
    `https://api.booking-platform.com/v1/staff/${staffId}`,
    {
      method: 'PATCH',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ schedule }),
    }
  );

  return response.json();
}

// Usage
await updateStaffSchedule('staff_123456', {
  monday: { start: '10:00', end: '19:00' },
  tuesday: { start: '10:00', end: '19:00' },
  wednesday: null, // Day off
  thursday: { start: '10:00', end: '19:00' },
  friday: { start: '10:00', end: '19:00' },
  saturday: { start: '10:00', end: '17:00' },
  sunday: null,
});

Get Staff Statistics

typescript
async function getStaffStats(staffId: string) {
  const response = await fetch(
    `https://api.booking-platform.com/v1/staff/${staffId}`,
    {
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
      },
    }
  );

  const { data } = await response.json();
  
  return {
    totalBookings: data.stats.totalBookings,
    thisMonth: data.stats.thisMonth,
    rating: data.stats.averageRating,
    completionRate: (data.stats.completedBookings / data.stats.totalBookings * 100).toFixed(1),
  };
}

Next Steps

Released under the MIT License.