From bf5668a42e8e5a98a951ae60236a2697b826c7bd Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 1 Sep 2025 12:23:39 +0100 Subject: [PATCH] Added payload to accessories API Signed-off-by: snipe --- .../Controllers/Api/AccessoriesController.php | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index 90486b40f2..7933b19057 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -288,32 +288,42 @@ class AccessoriesController extends Controller 'note' => $request->input('note'), ]); + $accessory_checkout->created_by = auth()->id(); $accessory_checkout->save(); + + $payload = [ + 'accessory_id' => $accessory->id, + 'assigned_to' => $target->id, + 'assigned_type' => $target::class, + 'note' => $request->input('note'), + 'created_by' => auth()->id(), + 'pivot' => $accessory_checkout->id, + ]; } // Set this value to be able to pass the qty through to the event event(new CheckoutableCheckedOut($accessory, $target, auth()->user(), $request->input('note'))); - return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/accessories/message.checkout.success'))); + return response()->json(Helper::formatStandardApiResponse('success', $payload, trans('admin/accessories/message.checkout.success'))); } /** * Check in the item so that it can be checked out again to someone else * - * @uses Accessory::checkin_email() to determine if an email can and should be sent - * @author [A. Gianotto] [] * @param Request $request * @param int $accessoryUserId * @param string $backto - * @return \Illuminate\Http\RedirectResponse + * @return JsonResponse + * @uses Accessory::checkin_email() to determine if an email can and should be sent + * @author [A. Gianotto] [] * @internal param int $accessoryId */ public function checkin(Request $request, $accessoryUserId = null) { if (is_null($accessory_checkout = AccessoryCheckout::find($accessoryUserId))) { - return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.does_not_exist'))); + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.does_not_exist', ['id' => $accessoryUserId]))); } $accessory = Accessory::find($accessory_checkout->accessory_id); @@ -327,7 +337,14 @@ class AccessoriesController extends Controller $user = User::find($accessory_checkout->assigned_to); } - return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/accessories/message.checkin.success'))); + $payload = [ + 'accessory_id' => $accessory->id, + 'note' => $request->input('note'), + 'created_by' => auth()->id(), + 'pivot' => $accessory_checkout->id, + ]; + + return response()->json(Helper::formatStandardApiResponse('success', $payload, trans('admin/accessories/message.checkin.success'))); } return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.checkin.error')));