Commit be157e40 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix(service-desk): add try-catch + fix JSON serialization of entry object

The issueTicket response was passing the raw Model object to json(),
which could fail serialization. Now returns entry_id instead, and
wraps recordEntry in try-catch for proper error reporting.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent ec725ab5
...@@ -97,26 +97,30 @@ class ServiceDeskController extends Controller ...@@ -97,26 +97,30 @@ class ServiceDeskController extends Controller
} }
} }
$entry = GuestEntryService::recordEntry([ try {
'carnet_id' => $carnetId, $entry = GuestEntryService::recordEntry([
'member_id' => $memberId, 'carnet_id' => $carnetId,
'guest_name' => $guestName, 'member_id' => $memberId,
'guest_phone' => trim((string) $request->post('guest_phone', '')), 'guest_name' => $guestName,
'guest_national_id' => '', 'guest_phone' => trim((string) $request->post('guest_phone', '')),
'guest_count' => $guestCount, 'guest_national_id' => '',
'entry_date' => date('Y-m-d'), 'guest_count' => $guestCount,
'entry_time' => date('H:i:s'), 'entry_date' => date('Y-m-d'),
'facility_id' => $facilityId, 'entry_time' => date('H:i:s'),
'activity_type' => $activityType, 'facility_id' => $facilityId,
'amount_paid' => $amountPaid, 'activity_type' => $activityType,
'notes' => $notes, 'amount_paid' => $amountPaid,
'recorded_by' => $employee ? (int) $employee->id : null, 'notes' => $notes,
'status' => 'active', 'recorded_by' => $employee ? (int) $employee->id : null,
]); 'status' => 'active',
]);
} catch (\Throwable $e) {
return $this->json(['success' => false, 'error' => 'فشل الإصدار: ' . $e->getMessage()]);
}
return $this->json([ return $this->json([
'success' => true, 'success' => true,
'entry' => $entry, 'entry_id' => (int) $entry->id,
'message' => 'تم إصدار التذكرة بنجاح', 'message' => 'تم إصدار التذكرة بنجاح',
]); ]);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment