bourse fix dep search

This commit is contained in:
Jérémy Munsch 2024-07-18 16:25:46 +02:00
parent 33931707de
commit 80791b62ac
2 changed files with 13 additions and 11 deletions

View file

@ -11,6 +11,7 @@ use App\Http\Requests\Club\Bourse\SearchCustomerCollectionRequest;
use App\Lib\Utils;
use App\Models\BlockList;
use App\Models\DepartaimantsCollection;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
@ -86,8 +87,8 @@ class DepartaimantController extends Controller
{
$output = collect();
$state = DepartaimantStatus::make((int)$request->input('state'));
$pseudo = $request->pseudo;
$departaimant = str_replace(['-', ' ', '\''], '', strtolower($request->departaimant ?? ''));
$pseudo = $request->string('pseudo', '');
$departaimant = str_replace(['-', ' ', '\''], '', strtolower($request->string('departaimant', '')));
$departaimant = Utils::replaceSpecChar($departaimant);
if ($state->equals(DepartaimantStatus::gives)) {
@ -104,9 +105,10 @@ class DepartaimantController extends Controller
/** @var \App\Models\Customer */
$customer = Auth::guard('club')->user();
$ids = collect(BlockList::query()->select('customer_id', 'blocked_id')
->where('customer_id', $customer->id)
->orWhere('blocked_id', $customer->id)->get()->toArray());
$ids = $ids->flatten()->unique()->all();
->whereHas('customer', fn (Builder $q) => $q->where('id', $customer->id))
->orWhereHas('blocked', fn (Builder $q) => $q->where('id', $customer->id))
->get()->toArray());
$ids = $ids->flatten()->unique();
$userDep = $customer->departaimantsCollections()->where('type', $collectiontype->value)->first();
$userDepStatus = [];
foreach ($userDep->getAllDepartaimants() as $dep) {
@ -119,14 +121,14 @@ class DepartaimantController extends Controller
$req = DepartaimantsCollection::getDepartaimantsCollectionWithStatus($userDepStatus, $status, $collectiontype)
->with('customer');
$req->whereHas('customer', function ($query) use ($pseudo, $ids) {
$req->whereHas('customer', function (Builder $query) use ($pseudo, $ids) {
// * handle blocked ids
if (count($ids)) {
$query->where('id', 'NOT IN', implode(',', $ids));
if ($ids->count()) {
$query->whereNotIn('id', $ids);
}
// * Filter with Pseudo
if ($pseudo !== null) {
$query->where('username', 'LIKE', "%$pseudo%");
if (strlen($pseudo)) {
$query->where('username', 'LIKE', "%{$pseudo}%");
}
});
$req->orderBy('updated_at', 'DESC');

View file

@ -13,7 +13,7 @@ class SearchCustomerCollectionRequest extends CustomerCollectionRequest
{
$this->merge([
'pseudo' => $this->string('pseudo'),
'departaimant' => $this->string('pseudo')
'departaimant' => $this->string('departaimant')
]);
parent::prepareForValidation();
}