Bug Fixed: avoiding item waiting_user across take/return

It happend once: a user asked to be added to the waiting
list at the same time other user was returning the item.

So the user ended up waiting for the user he was already
using.
This commit is contained in:
Bruno F. Fontes 2018-10-21 11:57:23 -03:00
parent 3d6b0dbeca
commit 2bc2792a24
Signed by: brunofontes
GPG Key ID: EE3447CE80048495
3 changed files with 10 additions and 1 deletions

View File

@ -22,6 +22,13 @@ class AlertController extends Controller
public function store(Request $request) public function store(Request $request)
{ {
$item = User::loggedIn()->items()->find(request('item')); $item = User::loggedIn()->items()->find(request('item'));
if (!$item->used_by) {
session()->flash(
FlashMessage::PRIMARY,
__('Oh! This item has just being returned. Take it before anyone else!')
);
return redirect('home');
}
$item->waiting_user_id = Auth::id(); $item->waiting_user_id = Auth::id();
$item->timestamps = false; $item->timestamps = false;
$item->save(); $item->save();

View File

@ -30,6 +30,7 @@ class TakeController extends Controller
); );
} }
$item->used_by = Auth::id(); $item->used_by = Auth::id();
$item->waiting_user_id = null;
$item->save(); $item->save();
return redirect('home'); return redirect('home');
} }

View File

@ -46,5 +46,6 @@
"The item doesn't exist.": "O item não existe.", "The item doesn't exist.": "O item não existe.",
"The product doesn't exist or doesn't belongs to you.": "O produto não existe ou não é seu.", "The product doesn't exist or doesn't belongs to you.": "O produto não existe ou não é seu.",
"This item is already taken": "Esse item já está sendo usado" "This item is already taken": "Esse item já está sendo usado",
"Oh! This item has just being returned. Take it before anyone else!": "Opa! Esse item acabou de ser devolvido. Aproveite!"
} }