Skip to main content

Job Items Status Management API

This document outlines the API endpoints and functionality for managing job item statuses in the AttuneLogic system.

Start Job Item​

Initiates a job item and marks it as "In Progress".

Endpoint​

POST /api/v1/jobs/:id/items/:itemId/start

Authentication​

  • Requires valid JWT token
  • Requires user role
  • Requires parent company verification

Parameters​

URL Parameters​

  • id (string, required): The ID of the job
  • itemId (string, required): The ID of the job item

Request Body​

{
"status": string,
"notes": string (optional),
"appointmentDate": Date (optional)
}

Response​

Success Response (200 OK)​

{
"data": {
"_id": string,
"status": "In Progress",
"startDate": Date,
"performedBy": [string],
// ... other item fields
},
"status": "success",
"code": 200,
"message": "Service started successfully"
}

Implementation Details​

The endpoint performs the following operations:

  1. Validates the job item exists
  2. Updates the parent job status to "In Progress" if needed
  3. Assigns the user to the item if not already assigned
  4. Sets the start date if not already set
  5. Adds the user to the job's assignedTo array
  6. Updates the item status to "In Progress"
  7. Updates the item approval status
  8. Saves both the item and job

Error Handling​

  • 404: Item or job not found
  • 403: Authentication/authorization errors
  • 500: Server errors

Pause Job Item​

POST /api/v1/jobs/:id/items/:itemId/pause

Resume Job Item​

POST /api/v1/jobs/:id/items/:itemId/resume

Complete Job Item​

PUT /api/v1/jobs/:id/items/:itemId/complete

Update Item Status​

PUT /api/v1/jobs/:id/items/:itemId/status

Mobile App Integration​

The mobile app uses RTK Query to interact with these endpoints. The relevant API slice is located in @attunelogic-mobile/store/api/jobs/jobItemsApi.js.

Example Usage in Mobile App​

const [startJobItem] = useStartJobItemMutation();

const handleStart = async (status: string) => {
await startJobItem({
jobId: jobId,
itemId: _id,
data: { status },
});
};

Debugging​

If you're not seeing any logs when calling these endpoints:

  1. Verify the request is reaching the server by checking the logs at the route level
  2. Check the network tab in your mobile dev tools
  3. Verify the base URL configuration in your mobile app
  4. Check for network/firewall issues
  5. Ensure your server is running and accessible
  • Route Definition: routes/api/v1/jobs.js
  • Controller: controllers/jobs/items.js
  • Mobile API Integration: @attunelogic-mobile/store/api/jobs/jobItemsApi.js
  • Mobile Component: @attunelogic-mobile/features/Job/Items/Services/Service/ServiceItem.tsx