feat(api): add active-trip endpoint for helper and enable Vite dev server CORS
This commit is contained in:
@@ -81,6 +81,38 @@ class HelperAssignmentController extends ApiController
|
||||
return $this->ok(new TeamMemberResource($assignment->load(['team.driver', 'team.scanner', 'team.truck', 'team.area'])), 'Assignment rejected.');
|
||||
}
|
||||
|
||||
public function activeTrip(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$today = now()->toDateString();
|
||||
|
||||
$assignment = TeamMember::query()
|
||||
->where('user_id', $user->id)
|
||||
->where('role_in_team', TeamMember::ROLE_HELPER)
|
||||
->whereDate('assigned_from', '<=', $today)
|
||||
->where(function ($q) use ($today) {
|
||||
$q->whereNull('assigned_until')->orWhereDate('assigned_until', '>=', $today);
|
||||
})
|
||||
->first();
|
||||
|
||||
if (! $assignment) {
|
||||
return $this->ok(null, 'No active assignment for today.');
|
||||
}
|
||||
|
||||
$trip = \App\Models\Trip::query()
|
||||
->where('team_id', $assignment->team_id)
|
||||
->whereIn('status', [\App\Models\Trip::STATUS_SCHEDULED, \App\Models\Trip::STATUS_IN_PROGRESS, \App\Models\Trip::STATUS_AT_DUMPSITE])
|
||||
->with(['route', 'team.driver', 'team.scanner', 'truck', 'dumpsite', 'stops.dropOffPoint'])
|
||||
->orderBy('scheduled_date')
|
||||
->first();
|
||||
|
||||
if (! $trip) {
|
||||
return $this->ok(null, 'No active trip for assigned team.');
|
||||
}
|
||||
|
||||
return $this->ok(\App\Http\Resources\TripResource::make($trip));
|
||||
}
|
||||
|
||||
public function history(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
Reference in New Issue
Block a user