@fleetbase/fleetops-engine 0.3.6 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/addon/components/admin/navigator-app.hbs +6 -3
  2. package/addon/components/layout/fleet-ops-sidebar/fleet-listing.hbs +5 -1
  3. package/addon/components/layout/fleet-ops-sidebar/fleet-listing.js +98 -1
  4. package/addon/components/layout/fleet-ops-sidebar.hbs +5 -1
  5. package/addon/components/layout/fleet-ops-sidebar.js +1 -0
  6. package/addon/controllers/management/drivers/index/edit.js +0 -26
  7. package/addon/engine.js +4 -4
  8. package/addon/styles/fleetops-engine.css +17 -0
  9. package/addon/templates/operations/service-rates/index/new.hbs +1 -1
  10. package/composer.json +2 -2
  11. package/extension.json +1 -1
  12. package/package.json +1 -1
  13. package/server/config/fleetops.php +4 -1
  14. package/server/src/Casts/MultiPolygon.php +14 -3
  15. package/server/src/Casts/Point.php +12 -2
  16. package/server/src/Casts/Polygon.php +19 -4
  17. package/server/src/Http/Controllers/Api/v1/DriverController.php +34 -18
  18. package/server/src/Http/Controllers/Api/v1/EntityController.php +36 -1
  19. package/server/src/Http/Controllers/Api/v1/LabelController.php +2 -2
  20. package/server/src/Http/Controllers/Api/v1/OrderController.php +139 -59
  21. package/server/src/Http/Controllers/Api/v1/PayloadController.php +20 -12
  22. package/server/src/Http/Controllers/Api/v1/PlaceController.php +25 -3
  23. package/server/src/Http/Controllers/Api/v1/PurchaseRateController.php +1 -1
  24. package/server/src/Http/Controllers/Api/v1/ServiceAreaController.php +71 -3
  25. package/server/src/Http/Controllers/Api/v1/ServiceQuoteController.php +1 -1
  26. package/server/src/Http/Controllers/Api/v1/ServiceRateController.php +3 -2
  27. package/server/src/Http/Controllers/Api/v1/TrackingNumberController.php +2 -2
  28. package/server/src/Http/Controllers/Api/v1/TrackingStatusController.php +2 -2
  29. package/server/src/Http/Controllers/Api/v1/VehicleController.php +22 -2
  30. package/server/src/Http/Controllers/Api/v1/ZoneController.php +59 -3
  31. package/server/src/Http/Controllers/Internal/v1/DriverController.php +148 -0
  32. package/server/src/Http/Controllers/Internal/v1/NavigatorController.php +38 -0
  33. package/server/src/Http/Controllers/Internal/v1/OrderController.php +11 -1
  34. package/server/src/Http/Filter/TrackingStatusFilter.php +10 -0
  35. package/server/src/Http/Requests/CancelOrderRequest.php +1 -2
  36. package/server/src/Http/Requests/CreateContactRequest.php +5 -4
  37. package/server/src/Http/Requests/CreateDriverRequest.php +13 -11
  38. package/server/src/Http/Requests/CreateEntityRequest.php +7 -4
  39. package/server/src/Http/Requests/CreateOrderRequest.php +2 -2
  40. package/server/src/Http/Requests/CreatePayloadRequest.php +1 -1
  41. package/server/src/Http/Requests/CreatePlaceRequest.php +46 -4
  42. package/server/src/Http/Requests/CreatePurchaseRateRequest.php +3 -2
  43. package/server/src/Http/Requests/CreateServiceAreaRequest.php +24 -4
  44. package/server/src/Http/Requests/CreateServiceRateRequest.php +22 -21
  45. package/server/src/Http/Requests/CreateTrackingStatusRequest.php +9 -8
  46. package/server/src/Http/Requests/CreateVehicleRequest.php +6 -4
  47. package/server/src/Http/Requests/CreateZoneRequest.php +24 -5
  48. package/server/src/Http/Requests/QueryServiceQuotesRequest.php +11 -10
  49. package/server/src/Http/Requests/ScheduleOrderRequest.php +32 -0
  50. package/server/src/Http/Requests/UpdateContactRequest.php +0 -13
  51. package/server/src/Http/Requests/UpdateServiceAreaRequest.php +1 -23
  52. package/server/src/Http/Requests/UpdateServiceQuoteRequest.php +1 -23
  53. package/server/src/Http/Requests/UpdateServiceRateRequest.php +1 -23
  54. package/server/src/Http/Requests/UpdateTrackingStatusRequest.php +1 -26
  55. package/server/src/Http/Resources/v1/DeletedResource.php +2 -9
  56. package/server/src/Http/Resources/v1/Entity.php +47 -44
  57. package/server/src/Http/Resources/v1/Order.php +1 -1
  58. package/server/src/Http/Resources/v1/ServiceArea.php +2 -2
  59. package/server/src/Http/Resources/v1/Vehicle.php +1 -3
  60. package/server/src/Http/Resources/v1/Zone.php +2 -4
  61. package/server/src/Models/Entity.php +99 -3
  62. package/server/src/Models/Order.php +75 -7
  63. package/server/src/Models/Payload.php +104 -33
  64. package/server/src/Models/Place.php +56 -17
  65. package/server/src/Models/ServiceArea.php +285 -18
  66. package/server/src/Models/ServiceRate.php +10 -6
  67. package/server/src/Models/TrackingNumber.php +18 -24
  68. package/server/src/Models/TrackingStatus.php +2 -6
  69. package/server/src/Models/Vehicle.php +2 -2
  70. package/server/src/Models/Waypoint.php +0 -10
  71. package/server/src/Models/Zone.php +132 -5
  72. package/server/src/Support/Flow.php +17 -3
  73. package/server/src/Support/Utils.php +143 -9
  74. package/server/src/routes.php +58 -3
@@ -2,7 +2,8 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Models;
4
4
 
5
- use Fleetbase\FleetOps\Casts\Polygon;
5
+ use Fleetbase\FleetOps\Casts\Polygon as PolygonCast;
6
+ use Fleetbase\FleetOps\Support\Utils;
6
7
  use Fleetbase\Models\Model;
7
8
  use Fleetbase\Traits\HasApiModelBehavior;
8
9
  use Fleetbase\Traits\HasPublicId;
@@ -10,6 +11,10 @@ use Fleetbase\Traits\HasUuid;
10
11
  use Fleetbase\Traits\SendsWebhooks;
11
12
  use Fleetbase\Traits\TracksApiCredential;
12
13
  use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;
14
+ use Grimzy\LaravelMysqlSpatial\Types\LineString;
15
+ use Grimzy\LaravelMysqlSpatial\Types\Point;
16
+ use Grimzy\LaravelMysqlSpatial\Types\Polygon;
17
+ use Illuminate\Support\Arr;
13
18
 
14
19
  class Zone extends Model
15
20
  {
@@ -61,7 +66,7 @@ class Zone extends Model
61
66
  * @var array
62
67
  */
63
68
  protected $casts = [
64
- 'border' => Polygon::class,
69
+ 'border' => PolygonCast::class,
65
70
  ];
66
71
 
67
72
  /**
@@ -79,17 +84,139 @@ class Zone extends Model
79
84
  protected $hidden = [];
80
85
 
81
86
  /**
82
- * Service area for rate.
83
- *
84
- * @var Model
87
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
85
88
  */
86
89
  public function serviceArea()
87
90
  {
88
91
  return $this->belongsTo(ServiceArea::class);
89
92
  }
90
93
 
94
+ /**
95
+ * The type of area.
96
+ *
97
+ * @return string
98
+ */
91
99
  public function getTypeAttribute()
92
100
  {
93
101
  return 'zone';
94
102
  }
103
+
104
+ /**
105
+ * Retrieves the location attribute as a point.
106
+ *
107
+ * @return \Grimzy\LaravelMysqlSpatial\Types\Point returns the centroid of the border as a Point object
108
+ */
109
+ public function getLocationAttribute(): Point
110
+ {
111
+ $centroid = $this->getCentroid();
112
+
113
+ return new Point($centroid->x(), $centroid->y());
114
+ }
115
+
116
+ /**
117
+ * Retrieves the latitude component of the location attribute.
118
+ *
119
+ * @return float returns the latitude value
120
+ */
121
+ public function getLatitudeAttribute(): float
122
+ {
123
+ return $this->location->getLat();
124
+ }
125
+
126
+ /**
127
+ * Retrieves the longitude component of the location attribute.
128
+ *
129
+ * @return float returns the longitude value
130
+ */
131
+ public function getLongitudeAttribute(): float
132
+ {
133
+ return $this->location->getLng();
134
+ }
135
+
136
+ /**
137
+ * Calculates the centroid of the border as a \Brick\Geo\Point.
138
+ *
139
+ * @return \Brick\Geo\Point the centroid of the border as a \Brick\Geo\Point object
140
+ */
141
+ public function getCentroid(): \Brick\Geo\Point
142
+ {
143
+ $geometryEngine = new \Brick\Geo\Engine\GEOSEngine();
144
+ $borderAsPolygon = $this->toGeosPolygon();
145
+
146
+ if ($borderAsPolygon instanceof \Brick\Geo\Geometry) {
147
+ return $geometryEngine->centroid($borderAsPolygon);
148
+ }
149
+
150
+ return \Brick\Geo\Point::fromText('POINT (0 0)');
151
+ }
152
+
153
+ /**
154
+ * Converts the border's coordinates to an array of \Brick\Geo\LineString objects.
155
+ *
156
+ * @return \Brick\Geo\LineString[] an array of \Brick\Geo\LineString objects
157
+ */
158
+ public function toGeosLineStrings(): array
159
+ {
160
+ $lineStrings = [];
161
+
162
+ if (is_iterable($this->border)) {
163
+ foreach ($this->border as $lineString) {
164
+ $points = [];
165
+
166
+ foreach ($lineString as $point) {
167
+ $points[] = \Brick\Geo\Point::fromText('POINT (' . $point->getLat() . ' ' . $point->getLng() . ')');
168
+ }
169
+
170
+ if ($points) {
171
+ $lineStrings[] = \Brick\Geo\LineString::of(...$points);
172
+ }
173
+ }
174
+ }
175
+
176
+ return $lineStrings;
177
+ }
178
+
179
+ /**
180
+ * Converts the first LineString from the border into a \Brick\Geo\Polygon.
181
+ *
182
+ * @return \Brick\Geo\Polygon a \Brick\Geo\Polygon object created from the first line string of the border
183
+ */
184
+ public function toGeosPolygon(): ?\Brick\Geo\Polygon
185
+ {
186
+ $lineString = Arr::first($this->toGeosLineStrings());
187
+
188
+ if (empty($lineString)) {
189
+ return null;
190
+ }
191
+
192
+ return \Brick\Geo\Polygon::of($lineString);
193
+ }
194
+
195
+ /**
196
+ * Creates a polygon from a given point and radius.
197
+ *
198
+ * @param \Grimzy\LaravelMysqlSpatial\Types\Point $point the central point from which to create the polygon
199
+ * @param int $meters The radius in meters for the polygon. Default is 500 meters.
200
+ *
201
+ * @return \Grimzy\LaravelMysqlSpatial\Types\Polygon returns a Polygon object
202
+ */
203
+ public static function createPolygonFromPoint(Point $point, int $meters = 500): Polygon
204
+ {
205
+ $coordinates = Utils::coordsToCircle($point->getLat(), $point->getLng(), $meters);
206
+
207
+ // first and last positions should be equivalent
208
+ if (Arr::first($coordinates) !== Arr::last($coordinates)) {
209
+ $coordinates[] = Arr::first($coordinates);
210
+ }
211
+
212
+ // conver the coordinate pairs to points
213
+ $coordinates = array_map(
214
+ function ($coord) {
215
+ return new Point(...$coord);
216
+ },
217
+ $coordinates
218
+ );
219
+
220
+ return new Polygon([new LineString($coordinates)]);
221
+ }
95
222
  }
@@ -177,7 +177,7 @@ class Flow
177
177
  {
178
178
  $config = static::getOrderConfig($order);
179
179
  $vars = static::getOrderFlowVars($order);
180
- $code = strtolower($order->status);
180
+ $code = strtolower(data_get($order, 'status'));
181
181
  $status = data_get($config, 'meta.flow.' . $code . '.events');
182
182
 
183
183
  $flow = static::bindVariablesToFlow($status, $vars);
@@ -235,11 +235,21 @@ class Flow
235
235
 
236
236
  /**
237
237
  * Returns a order type configuration by key.
238
+ *
239
+ * @param bool $force - If this method should always return dispatch activity
238
240
  */
239
- public static function getDispatchActivity(Order $order): ?array
241
+ public static function getDispatchActivity(Order $order, bool $force = true): ?array
240
242
  {
241
243
  $flow = static::getOrderFlow($order);
242
244
 
245
+ if ($force === true) {
246
+ return [
247
+ 'status' => 'Order dispatched',
248
+ 'details' => 'Order has been dispatched',
249
+ 'code' => 'dispatched',
250
+ ];
251
+ }
252
+
243
253
  return collect($flow)->first(function ($activity) {
244
254
  return isset($activity['code']) && $activity['code'] === 'dispatched';
245
255
  });
@@ -285,7 +295,7 @@ class Flow
285
295
  public static function getOrderFlowVars(Order $order, Waypoint $currentWaypoint = null): ?array
286
296
  {
287
297
  $vars = [];
288
- $allWaypoints = $order->payload->waypoints ?? collect();
298
+ $allWaypoints = data_get($order, 'payload.waypoints', collect());
289
299
 
290
300
  // set order vars
291
301
  $vars['order'] = ['public_id' => $order->public_id, 'internal_id' => $order->internal_id, 'tracking_number' => $order->tracking, 'meta' => $order->meta];
@@ -316,6 +326,10 @@ class Flow
316
326
  }
317
327
 
318
328
  // // storefront order add store or network about
329
+ // should patch with hook system
330
+ // storefront extension should register hook to add $vars
331
+ // Hook::register('\Fleetbase\FleetOps\Support\Flow@getOrderFlowVars', addStorefrontVars);
332
+ // here we will run Hook::run(__CLASS__ . '@' . __METHOD__);
319
333
  // if ($order->type === 'storefront' && $order->hasMeta('storefront_id')) {
320
334
  // $storefront = Storefront::findAbout($order->getMeta('storefront_id'));
321
335
 
@@ -202,14 +202,29 @@ class Utils extends FleetbaseUtils
202
202
  $latitude = $coordinates->getLat();
203
203
  $longitude = $coordinates->getLng();
204
204
  } elseif (static::isGeoJson($coordinates)) {
205
- $coordinatesJson = null;
205
+ $coordinatesJson = null;
206
+ $coordinatesInGeoJson = null;
207
+ $coordinatesInGeoJsonFeature = null;
206
208
 
207
209
  if (is_array($coordinates) || is_object($coordinates)) {
208
210
  $coordinatesJson = json_encode($coordinates);
209
211
  }
210
212
 
213
+ $coordinatesInGeoJson = data_get($coordinates, 'coordinates');
214
+ $coordinatesInGeoJsonFeature = data_get($coordinates, 'geometry.coordinates');
215
+
211
216
  if (static::isJson($coordinatesJson)) {
212
- $coordinates = \Grimzy\LaravelMysqlSpatial\Types\Point::fromJson($coordinatesJson);
217
+ try {
218
+ $coordinates = \Grimzy\LaravelMysqlSpatial\Types\Point::fromJson($coordinatesJson);
219
+ } catch (\Throwable $e) {
220
+ if ($coordinatesInGeoJson) {
221
+ return static::getPointFromMixed($coordinatesInGeoJson);
222
+ }
223
+
224
+ if ($coordinatesInGeoJsonFeature) {
225
+ return static::getPointFromMixed($coordinatesInGeoJsonFeature);
226
+ }
227
+ }
213
228
  }
214
229
  } elseif (is_array($coordinates) || is_object($coordinates)) {
215
230
  // if known location based record
@@ -997,27 +1012,121 @@ class Utils extends FleetbaseUtils
997
1012
  $coords->push([rad2deg($lat_rad), rad2deg($lon_rad)]);
998
1013
  }
999
1014
 
1015
+ // first and last positions should be equivalent
1016
+ if ($coords->first() !== $coords->last()) {
1017
+ $coords->push($coords->first());
1018
+ }
1019
+
1000
1020
  return $coords->toArray();
1001
1021
  }
1002
1022
 
1003
1023
  /**
1004
1024
  * Calculates the centroid (geometric center) of the provided coordinates.
1005
1025
  *
1006
- * @param array $coord an array of coordinates
1026
+ * @param array $coordinates an array of coordinates
1007
1027
  *
1008
1028
  * @return array the centroid of the coordinates as an array [latitude, longitude]
1009
1029
  */
1010
- public static function getCentroid($coord)
1030
+ public static function getCentroid(array $coordinates = []): array
1031
+ {
1032
+ // Check if the coordinates array is empty
1033
+ if (count($coordinates) === 0) {
1034
+ return [0, 0];
1035
+ }
1036
+
1037
+ $sumX = 0;
1038
+ $sumY = 0;
1039
+ $validCoordsCount = 0;
1040
+
1041
+ foreach ($coordinates as $coord) {
1042
+ // Ensure the coordinate has at least two elements and they are numeric
1043
+ if (is_array($coord) && count($coord) >= 2 && is_numeric($coord[0]) && is_numeric($coord[1])) {
1044
+ $sumX += $coord[0];
1045
+ $sumY += $coord[1];
1046
+ $validCoordsCount++;
1047
+ }
1048
+ }
1049
+
1050
+ // If no valid coordinates were found, return a default value
1051
+ if ($validCoordsCount === 0) {
1052
+ return [0, 0];
1053
+ }
1054
+
1055
+ // Calculate the average for X and Y
1056
+ return [$sumX / $validCoordsCount, $sumY / $validCoordsCount];
1057
+ }
1058
+
1059
+ /**
1060
+ * Calculates the centroid of a given GEOS polygon.
1061
+ *
1062
+ * @param \Brick\Geo\Polygon $polygon the GEOS Polygon from which to calculate the centroid
1063
+ *
1064
+ * @return \Brick\Geo\Point returns the centroid of the polygon as a GEOS Point object
1065
+ */
1066
+ public static function getCentroidFromGeosPolygon(\Brick\Geo\Polygon $polygon): \Brick\Geo\Point
1067
+ {
1068
+ $geometryEngine = new \Brick\Geo\Engine\GEOSEngine();
1069
+
1070
+ return $geometryEngine->centroid($polygon);
1071
+ }
1072
+
1073
+ /**
1074
+ * Calculates the centroid of a given GEOS multi-polygon.
1075
+ *
1076
+ * @param \Brick\Geo\MultiPolygon $multiPolygon the GEOS MultiPolygon from which to calculate the centroid
1077
+ *
1078
+ * @return \Brick\Geo\Point returns the centroid of the multi-polygon as a GEOS Point object
1079
+ */
1080
+ public static function getCentroidFromGeosMultiPolygon(\Brick\Geo\MultiPolygon $multiPolygon): \Brick\Geo\Point
1081
+ {
1082
+ $geometryEngine = new \Brick\Geo\Engine\GEOSEngine();
1083
+
1084
+ return $geometryEngine->centroid($multiPolygon);
1085
+ }
1086
+
1087
+ /**
1088
+ * Calculates the centroid of a polygon using the Grimzy Laravel MySQL spatial type.
1089
+ *
1090
+ * @param \Grimzy\LaravelMysqlSpatial\Types\Polygon $polygon the Polygon object from which to calculate the centroid
1091
+ *
1092
+ * @return array returns the centroid of the polygon as an array of coordinates
1093
+ */
1094
+ public static function getPolygonCentroid(\Grimzy\LaravelMysqlSpatial\Types\Polygon $polygon)
1011
1095
  {
1012
- $centroid = array_reduce($coord, function ($x, $y) use ($coord) {
1013
- $len = count($coord);
1096
+ $polygonArray = $polygon->jsonSerialize()->getCoordinates();
1097
+ $coordinates = array_merge(...$polygonArray);
1014
1098
 
1015
- return [$x[0] + $y[0] / $len, $x[1] + $y[1] / $len];
1016
- }, [0, 0]);
1099
+ return static::getCentroid($coordinates);
1100
+ }
1101
+
1102
+ /**
1103
+ * Calculates the centroid of a multi-polygon using the Grimzy Laravel MySQL spatial type.
1104
+ *
1105
+ * @param \Grimzy\LaravelMysqlSpatial\Types\MultiPolygon $multiPolygon the MultiPolygon object from which to calculate the centroid
1106
+ *
1107
+ * @return array returns the centroid of the multi-polygon as an array of coordinates
1108
+ */
1109
+ public static function getMultiPolygonCentroid(\Grimzy\LaravelMysqlSpatial\Types\MultiPolygon $multiPolygon)
1110
+ {
1111
+ $multiPolygonArray = $multiPolygon->jsonSerialize()->getCoordinates();
1112
+ $coordinates = [];
1113
+
1114
+ foreach ($multiPolygonArray as $polygonArray) {
1115
+ foreach ($polygonArray as $lineStringArray) {
1116
+ $coordinates = array_merge($coordinates, $lineStringArray);
1117
+ }
1118
+ }
1017
1119
 
1018
- return $centroid;
1120
+ return static::getCentroid($coordinates);
1019
1121
  }
1020
1122
 
1123
+ /**
1124
+ * Extracts and returns the first set of coordinates from a given polygon.
1125
+ *
1126
+ * @param \Grimzy\LaravelMysqlSpatial\Types\Polygon|null $polygon the Polygon object from which to extract coordinates
1127
+ *
1128
+ * @return array Returns an array of the first set of coordinates in the polygon. Returns an empty array if the polygon is null.
1129
+ */
1021
1130
  public static function getCoordinatesFromPolygon(?\Grimzy\LaravelMysqlSpatial\Types\Polygon $polygon): array
1022
1131
  {
1023
1132
  return Arr::first($polygon->jsonSerialize()->getCoordinates());
@@ -1106,6 +1215,31 @@ class Utils extends FleetbaseUtils
1106
1215
  return new \Grimzy\LaravelMysqlSpatial\Eloquent\SpatialExpression($geo);
1107
1216
  }
1108
1217
 
1218
+ /**
1219
+ * Creates a SpatialExpression object from a valid GeoJSON input.
1220
+ *
1221
+ * @param mixed $geoJson the GeoJSON input, which can be an array, object, or JSON string representing a valid GeoJSON object
1222
+ *
1223
+ * @return \Grimzy\LaravelMysqlSpatial\Eloquent\SpatialExpression|null returns a SpatialExpression object if the input is a valid GeoJSON, or null if the input is not valid
1224
+ *
1225
+ * @throws \InvalidArgumentException if the input is not a valid GeoJSON object
1226
+ */
1227
+ public static function createGeometryObjectFromGeoJson($geoJson): ?\Grimzy\LaravelMysqlSpatial\Types\Geometry
1228
+ {
1229
+ if (!static::isGeoJson($geoJson)) {
1230
+ return null;
1231
+ }
1232
+
1233
+ if (is_string($geoJson) && static::isJson($geoJson)) {
1234
+ $geoJson = json_decode($geoJson, true);
1235
+ }
1236
+
1237
+ // Convert the value to JSON and create a Geometry object
1238
+ $json = json_encode($geoJson);
1239
+
1240
+ return \Grimzy\LaravelMysqlSpatial\Types\Geometry::fromJson($json);
1241
+ }
1242
+
1109
1243
  /**
1110
1244
  * Calculate the heading between two geographical points.
1111
1245
  *
@@ -65,13 +65,14 @@ Route::prefix(config('fleetops.api.routing.prefix', null))->namespace('Fleetbase
65
65
  $router->get('/', 'OrderController@query');
66
66
  $router->get('{id}', 'OrderController@find');
67
67
  $router->get('{id}/distance-and-time', 'OrderController@getDistanceMatrix');
68
- $router->post('{id}/dispatch', 'OrderController@dispatchOrder');
68
+ $router->match(['post', 'patch'], '{id}/schedule', 'OrderController@scheduleOrder');
69
+ $router->match(['post', 'patch'], '{id}/dispatch', 'OrderController@dispatchOrder');
69
70
  $router->post('{id}/start', 'OrderController@startOrder');
70
71
  $router->delete('{id}/cancel', 'OrderController@cancelOrder');
71
- $router->post('{id}/update-activity', 'OrderController@updateActivity');
72
+ $router->match(['post', 'patch'], '{id}/update-activity', 'OrderController@updateActivity');
72
73
  $router->post('{id}/complete', 'OrderController@completeOrder');
73
74
  $router->get('{id}/next-activity', 'OrderController@getNextActivity');
74
- $router->post('{id}/set-destination/{placeId}', 'OrderController@setDestination');
75
+ $router->match(['post', 'patch'], '{id}/set-destination/{placeId}', 'OrderController@setDestination');
75
76
  $router->post('{id}/capture-signature/{subjectId?}', 'OrderController@captureSignature');
76
77
  $router->post('{id}/capture-qr/{subjectId?}', 'OrderController@captureQrScan');
77
78
  $router->put('{id}', 'OrderController@update');
@@ -175,6 +176,60 @@ Route::prefix(config('fleetops.api.routing.prefix', null))->namespace('Fleetbase
175
176
  });
176
177
  });
177
178
 
179
+ /*
180
+ |--------------------------------------------------------------------------
181
+ | Navigator App API
182
+ |--------------------------------------------------------------------------
183
+ |
184
+ | Internal routes specific for instance wide authentication/use for navigator app
185
+ */
186
+ Route::prefix('navigator/v1')
187
+ ->group(function ($router) {
188
+ // driver/auth routes
189
+ $router->group(['prefix' => 'drivers', 'namespace' => 'Internal\v1'], function () use ($router) {
190
+ $router->post('login-with-sms', 'DriverController@loginWithPhone');
191
+ $router->post('verify-code', 'DriverController@verifyCode');
192
+ $router->post('login', 'DriverController@login');
193
+ });
194
+
195
+ // auth:sanctum
196
+ $router->group(['middleware' => ['fleetbase.protected', \Fleetbase\FleetOps\Http\Middleware\TransformLocationMiddleware::class]], function () use ($router) {
197
+ $router->group(['prefix' => 'orders'], function () use ($router) {
198
+ $router->post('/', 'Api\v1\OrderController@create');
199
+ $router->get('/', 'Api\v1\OrderController@query');
200
+ $router->get('{id}', 'Api\v1\OrderController@find');
201
+ $router->get('{id}/distance-and-time', 'Api\v1\OrderController@getDistanceMatrix');
202
+ $router->post('{id}/dispatch', 'Api\v1\OrderController@dispatchOrder');
203
+ $router->post('{id}/start', 'Api\v1\OrderController@startOrder');
204
+ $router->delete('{id}/cancel', 'Api\v1\OrderController@cancelOrder');
205
+ $router->post('{id}/update-activity', 'Api\v1\OrderController@updateActivity');
206
+ $router->post('{id}/complete', 'Api\v1\OrderController@completeOrder');
207
+ $router->get('{id}/next-activity', 'Api\v1\OrderController@getNextActivity');
208
+ $router->post('{id}/set-destination/{placeId}', 'Api\v1\OrderController@setDestination');
209
+ $router->post('{id}/capture-signature/{subjectId?}', 'Api\v1\OrderController@captureSignature');
210
+ $router->post('{id}/capture-qr/{subjectId?}', 'Api\v1\OrderController@captureQrScan');
211
+ $router->put('{id}', 'Api\v1\OrderController@update');
212
+ $router->delete('{id}', 'Api\v1\OrderController@delete');
213
+ });
214
+
215
+ $router->group(['prefix' => 'drivers'], function () use ($router) {
216
+ $router->post('{id}/register-device', 'Api\v1\DriverController@registerDevice');
217
+ $router->post('{id}/track', 'Api\v1\DriverController@track');
218
+ $router->post('{id}/switch-organization', 'Api\v1\DriverController@switchOrganization');
219
+ $router->post('/', 'Api\v1\DriverController@create');
220
+ $router->get('/', 'Api\v1\DriverController@query');
221
+ $router->get('{id}', 'Api\v1\DriverController@find');
222
+ $router->get('{id}/organizations', 'Api\v1\DriverController@listOrganizations');
223
+ $router->put('{id}', 'Api\v1\DriverController@update');
224
+ $router->delete('{id}', 'Api\v1\DriverController@delete');
225
+ });
226
+
227
+ $router->group(['prefix' => 'organizations'], function ($router) {
228
+ $router->get('current', 'Internal\v1\NavigatorController@getCurrentOrganization');
229
+ });
230
+ });
231
+ });
232
+
178
233
  /*
179
234
  |--------------------------------------------------------------------------
180
235
  | Internal FleetOps API Routes