Skip to content

Commit

Permalink
Merge pull request #132 from fleetbase/dev-v0.5.15
Browse files Browse the repository at this point in the history
🎅🏾 v0.5.15 - API Updates and Patches
  • Loading branch information
roncodes authored Dec 24, 2024
2 parents d84cfb9 + ef089fa commit 3ff100f
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 30 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fleetbase/fleetops-api",
"version": "0.5.14",
"version": "0.5.15",
"description": "Fleet & Transport Management Extension for Fleetbase",
"keywords": [
"fleetbase-extension",
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Fleet-Ops",
"version": "0.5.14",
"version": "0.5.15",
"description": "Fleet & Transport Management Extension for Fleetbase",
"repository": "https://github.com/fleetbase/fleetops",
"license": "AGPL-3.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/fleetops-engine",
"version": "0.5.14",
"version": "0.5.15",
"description": "Fleet & Transport Management Extension for Fleetbase",
"fleetbase": {
"route": "fleet-ops"
Expand Down
9 changes: 6 additions & 3 deletions server/src/Console/Commands/SimulateOrderRouteNavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function handle()

$orderId = $this->argument('order');
$order = Order::where('public_id', $orderId)->orWhere('uuid', $orderId)->first();
$driver = null;
if (!$order) {
return $this->error('Order not found to simulate driving for.');
}
Expand All @@ -51,10 +52,12 @@ public function handle()
}

// Get the order driver
$order->loadAssignedDriver();
$driver = $order->driverAssigned;
if (!$driver) {
return $this->error('No driver found to simulate the order.');
$order->loadAssignedDriver();
$driver = $order->driverAssigned;
if (!$driver) {
return $this->error('No driver found to simulate the order.');
}
}

// Inform
Expand Down
9 changes: 9 additions & 0 deletions server/src/Http/Controllers/Api/v1/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Fleetbase\FleetOps\Http\Resources\v1\DeletedResource;
use Fleetbase\FleetOps\Models\Contact;
use Fleetbase\Http\Controllers\Controller;
use Fleetbase\Support\Utils;
use Illuminate\Http\Request;

class ContactController extends Controller
Expand Down Expand Up @@ -66,6 +67,14 @@ public function update($id, UpdateContactRequest $request)
// get request input
$input = $request->only(['name', 'type', 'title', 'email', 'phone', 'meta']);

// If setting a default location for the contact
if ($request->has('place')) {
$input['place_uuid'] = Utils::getUuid('places', [
'public_id' => $request->input('place'),
'company_uuid' => session('company'),
]);
}

// update the contact
$contact->update($input);
$contact->flushAttributesCache();
Expand Down
1 change: 1 addition & 0 deletions server/src/Http/Controllers/Api/v1/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ public function updateActivity($id, Request $request)
// also update for each order entities if not multiple drop order
// all entities will share the same activity status as is one drop order
if (!$order->payload->isMultipleDropOrder) {
// Only update entities belonging to the waypoint
foreach ($order->payload->entities as $entity) {
$entity->insertActivity($activity, $location, $proof);
}
Expand Down
41 changes: 26 additions & 15 deletions server/src/Http/Controllers/Api/v1/PlaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public function create(CreatePlaceRequest $request)
[
'public_id' => $id,
'company_uuid' => session('company'),
]
],
['full' => true]
);

if (is_array($owner)) {
Expand All @@ -125,6 +126,7 @@ public function create(CreatePlaceRequest $request)
/** @var \Fleetbase\Models\Place */
$place = Place::firstOrNew([
'company_uuid' => session('company'),
'owner_uuid' => data_get($input, 'owner_uuid'),
'name' => strtoupper(Utils::or($input, ['name', 'street1'])),
'street1' => strtoupper($input['street1']),
]);
Expand Down Expand Up @@ -200,24 +202,33 @@ public function update($id, UpdatePlaceRequest $request)

// owner assignment
if ($request->has('owner')) {
$id = $request->input('owner');
$owner = $request->input('owner');

// check if customer_ based contact
if (Str::startsWith($id, 'customer')) {
$id = Str::replaceFirst('customer', 'contact', $id);
// Handle if owner is an object
if (is_array($owner) || is_object($owner)) {
$id = data_get($owner, 'id', data_get($owner, 'customer_id'));
} elseif (is_string($owner)) {
$id = $owner;
}

$owner = Utils::getUuid(
['contacts', 'vendors'],
[
'public_id' => $id,
'company_uuid' => session('company'),
]
);
if ($id) {
// check if customer_ based contact
if (Str::startsWith($id, 'customer')) {
$id = Str::replaceFirst('customer', 'contact', $id);
}

if (is_array($owner)) {
$input['owner_uuid'] = Utils::get($owner, 'uuid');
$input['owner_type'] = Utils::getModelClassName(Utils::get($owner, 'table'));
$owner = Utils::getUuid(
['contacts', 'vendors'],
[
'public_id' => $id,
'company_uuid' => session('company'),
]
);

if (is_array($owner)) {
$input['owner_uuid'] = Utils::get($owner, 'uuid');
$input['owner_type'] = Utils::getModelClassName(Utils::get($owner, 'table'));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/Http/Requests/CreateContactRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function authorize()
public function rules()
{
return [
'name' => ['required'],
'name' => [new RequiredIf($this->isMethod('POST'))],
'type' => [new RequiredIf($this->isMethod('POST'))],
'email' => ['nullable', 'email'],
'phone' => ['nullable'],
Expand Down
2 changes: 2 additions & 0 deletions server/src/Http/Resources/v1/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Fleetbase\Http\Resources\FleetbaseResource;
use Fleetbase\Http\Resources\User;
use Fleetbase\Support\Http;
use Illuminate\Support\Str;

class Contact extends FleetbaseResource
{
Expand All @@ -19,6 +20,7 @@ public function toArray($request)
{
return [
'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
'customer_id' => $this->when($this->type === 'customer' && Http::isPublicRequest(), Str::replace('contact', 'customer', $this->public_id)),
'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
'user_uuid' => $this->when(Http::isInternalRequest(), $this->user_uuid),
Expand Down
8 changes: 5 additions & 3 deletions server/src/Http/Resources/v1/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Fleetbase\FleetOps\Http\Resources\v1;

use Fleetbase\FleetOps\Support\Utils;
use Fleetbase\Http\Resources\FleetbaseResource;
use Fleetbase\LaravelMysqlSpatial\Types\Point;
use Fleetbase\Support\Http;
use Fleetbase\Support\Resolve;

Expand All @@ -18,6 +18,8 @@ class Place extends FleetbaseResource
*/
public function toArray($request)
{
$this->loadMissing('owner');

return [
'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
Expand All @@ -26,7 +28,7 @@ public function toArray($request)
'owner_uuid' => $this->when(Http::isInternalRequest(), $this->owner_uuid),
'owner_type' => $this->when(Http::isInternalRequest(), $this->owner_type),
'name' => $this->name,
'location' => data_get($this, 'location', new Point(0, 0)),
'location' => Utils::getPointFromMixed($this->location),
'address' => $this->address,
'address_html' => $this->when(Http::isInternalRequest(), $this->address_html),
'avatar_url' => $this->avatar_url,
Expand All @@ -43,7 +45,7 @@ public function toArray($request)
'country' => $this->country ?? null,
'country_name' => $this->when(Http::isInternalRequest(), $this->country_name),
'phone' => $this->phone ?? null,
'owner' => $this->whenLoaded('owner', Resolve::resourceForMorph($this->owner_type, $this->owner_uuid)),
'owner' => Resolve::resourceForMorph($this->owner_type, $this->owner_uuid),
'tracking_number' => $this->whenLoaded('trackingNumber', fn () => $this->trackingNumber),
'type' => $this->type,
'meta' => data_get($this, 'meta', []),
Expand Down
6 changes: 1 addition & 5 deletions server/src/Models/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ class Place extends Model
*/
public function owner()
{
return $this->morphTo(__FILE__, 'owner_type', 'owner_uuid')->withDefault(
[
'name' => 'N/A',
]
);
return $this->morphTo(__FILE__, 'owner_type', 'owner_uuid');
}

/**
Expand Down

0 comments on commit 3ff100f

Please sign in to comment.