Skip to main content

Update Tracker Location

The updateTrackerLocation mutation allows administrators to request an immediate update of a tracker's location.

Permissions

This mutation requires admin privileges. The user must have a valid JWT token with the admin role.

You can check if a user has admin privileges by using the currentUser query:

query GetCurrentUser {
currentUser {
id
name
email
roles
}
}

If the roles array in the response includes "admin", the user can use this mutation:

{
"data": {
"currentUser": {
"id": "3",
"name": "Admin User",
"email": "admin@example.com",
"roles": ["admin"]
}
}
}

Input

FieldTypeDescription
trackerIdID!The ID of the tracker to update

Response

FieldTypeDescription
successBoolean!Whether the request was successful
messageString!A message describing the result
trackerIdID!The ID of the tracker that was updated

Example

Request

mutation UpdateTrackerLocation($trackerId: ID!) {
updateTrackerLocation(trackerId: $trackerId) {
success
message
trackerId
}
}

Variables:

{
"trackerId": "123"
}

Response

{
"data": {
"updateTrackerLocation": {
"success": true,
"message": "Tracker location update request sent to fetcher service",
"trackerId": "123"
}
}
}

Error Handling

ErrorDescription
Admin role required for this operationThe user does not have admin privileges
Tracker with ID X not foundThe specified tracker does not exist
Invalid tracker ID formatThe tracker ID is not in the correct format

Implementation Details

When this mutation is called:

  1. The server verifies that the user has admin privileges
  2. The server checks that the tracker exists
  3. The server publishes a message to the Redis channel tracker:update:requests
  4. The fetcher service processes the request and retrieves the latest data
  5. When complete, the fetcher publishes a notification to the Redis channel socket:notifications
  6. Connected clients receive a tracker_location_updated Socket.IO event with the new location data

Socket.IO Integration

After the fetcher service processes the request, it sends a notification through Redis. The Socket.IO server forwards this notification to connected clients, which will receive an event like this:

{
"type": "tracker_location_updated",
"trackerId": "123",
"success": true,
"message": "Successfully updated tracker ABC123, found 5 reports, stored 2 new reports",
"location": {
"id": "456789",
"timestamp": "2025-05-06T12:53:25",
"nearestCity": "London",
"location": {
"latitude": 51.5074,
"longitude": -0.1278
},
"confidence": 3,
"horizontalAccuracy": 10.5
}
}