feat: Move Trello card to Packing when inspection is passed
- Create InspectionPassed event - Create MoveCardToPackingOnInspectionPassed listener - Register event listener in EventServiceProvider - Dispatch event when markInspectionPassed() is called Now when an order passes inspection on the ops page, the Trello card automatically moves from Inspection to Packing list.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Order;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithBroadcasting;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class InspectionPassed
|
||||
{
|
||||
use Dispatchable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public Order $order,
|
||||
) {}
|
||||
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel('channel-name'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ class OpsController extends Controller
|
||||
], 409);
|
||||
}
|
||||
|
||||
// Update status and emit event
|
||||
// Update status
|
||||
$order->update(['status' => 'packing']);
|
||||
|
||||
Log::info('Inspection passed via QR', [
|
||||
@@ -127,8 +127,8 @@ class OpsController extends Controller
|
||||
'marked_by' => auth()->user()->name,
|
||||
]);
|
||||
|
||||
// Emit event for listeners to handle Slack/Trello updates
|
||||
// TODO: Create InspectionPassed event
|
||||
// Emit event to trigger Slack/Trello updates
|
||||
\App\Events\InspectionPassed::dispatch($order);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
|
||||
@@ -106,15 +106,25 @@ class TrelloWebhookController extends Controller
|
||||
|
||||
// Handle list-specific actions
|
||||
match ($listName) {
|
||||
'Prep' => $order->update(['status' => 'prep']),
|
||||
'Printing' => $order->update(['status' => 'printing']),
|
||||
'Inspection' => $order->update(['status' => 'inspection']),
|
||||
'Packing' => $order->update(['status' => 'packing']),
|
||||
'Ready to Ship' => $this->handleReadyToShipIntent($order, $cardId),
|
||||
'Awaiting Collection' => $this->handleAwaitingCollectionIntent($order, $cardId),
|
||||
'In Transit' => Log::info('Card in transit', ['order_uuid' => $order->uuid]),
|
||||
'Done' => Log::info('Card completed', ['order_uuid' => $order->uuid]),
|
||||
'In Transit' => $order->update(['status' => 'in_transit']),
|
||||
'Done' => $order->update(['status' => 'completed']),
|
||||
default => Log::debug('Card moved to list', [
|
||||
'order_uuid' => $order->uuid,
|
||||
'list' => $listName,
|
||||
]),
|
||||
};
|
||||
|
||||
Log::info('Order status updated from Trello', [
|
||||
'order_uuid' => $order->uuid,
|
||||
'list' => $listName,
|
||||
'status' => $order->status,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\InspectionPassed;
|
||||
use App\Services\TrelloService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class MoveCardToPackingOnInspectionPassed implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue;
|
||||
|
||||
public function __construct(
|
||||
protected TrelloService $trello,
|
||||
) {}
|
||||
|
||||
public function handle(InspectionPassed $event): void
|
||||
{
|
||||
$order = $event->order;
|
||||
|
||||
if (!$order->trello_card_id) {
|
||||
Log::debug('No Trello card to move', ['order_uuid' => $order->uuid]);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Move card to Packing list
|
||||
$success = $this->trello->moveCard($order->trello_card_id, 'packing');
|
||||
|
||||
if ($success) {
|
||||
Log::info('Trello card moved to Packing', [
|
||||
'order_uuid' => $order->uuid,
|
||||
'card_id' => $order->trello_card_id,
|
||||
]);
|
||||
} else {
|
||||
Log::warning('Failed to move Trello card to Packing', [
|
||||
'order_uuid' => $order->uuid,
|
||||
'card_id' => $order->trello_card_id,
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error moving Trello card to Packing', [
|
||||
'order_uuid' => $order->uuid,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Providers;
|
||||
|
||||
use App\Events\BalancePaid;
|
||||
use App\Events\DepositPaid;
|
||||
use App\Events\InspectionPassed;
|
||||
use App\Events\OrderCreated;
|
||||
use App\Events\OrderPacked;
|
||||
use App\Events\ParcelCollected;
|
||||
@@ -18,6 +19,7 @@ use App\Events\ShipmentCreated;
|
||||
use App\Events\ShipmentCreationFailed;
|
||||
use App\Listeners\CreateShipmentOnReadyToShip;
|
||||
use App\Listeners\GenerateQrCodeOnOrderCreated;
|
||||
use App\Listeners\MoveCardToPackingOnInspectionPassed;
|
||||
use App\Listeners\NotifySlackOnOrderCreated;
|
||||
use App\Listeners\NotifySlackOnOrderPacked;
|
||||
use App\Listeners\NotifySlackOnParcelCollected;
|
||||
@@ -46,7 +48,14 @@ class EventServiceProvider extends ServiceProvider
|
||||
// Packing events
|
||||
OrderPacked::class => [
|
||||
NotifySlackOnOrderPacked::class,
|
||||
],Ready to Ship intent (from Trello webhook)
|
||||
],
|
||||
|
||||
// Inspection events
|
||||
InspectionPassed::class => [
|
||||
MoveCardToPackingOnInspectionPassed::class,
|
||||
],
|
||||
|
||||
// Ready to Ship intent (from Trello webhook)
|
||||
ReadyToShipIntent::class => [
|
||||
CreateShipmentOnReadyToShip::class,
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user