Merge branch 'answers' into 'develop'

fix: 🐛 update the saving of answers

Closes #25

See merge request ldc-web/projets/crm!15
This commit is contained in:
noah.lancien 2024-08-05 11:07:52 +00:00
commit 3c1958ea75
3 changed files with 4 additions and 17 deletions

View file

@ -4,9 +4,7 @@ namespace App\Http\Controllers\Api\V2;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\V2\StoreCustomerAnswers;
use App\Models\Answer;
use App\Models\Customer;
use App\Models\Service;
use Illuminate\Http\JsonResponse;
class AnswerController extends Controller
@ -15,21 +13,17 @@ class AnswerController extends Controller
* Store the customer answers.
*
* @param \App\Http\Requests\Api\V2\StoreCustomerAnswers $request
* @param \App\Models\Service $service
* @param \App\Models\Customer $customer
* @return \Illuminate\Http\JsonResponse
*/
public function storeCustomerAnswers(
StoreCustomerAnswers $request,
Service $service,
Customer $customer
): JsonResponse {
// * Make sure we are accessing a customer that belongs to our service.
$this->authorize('customerBelongsToService', $customer);
$existingAnswerIds = $customer->getAnswers($service)->pluck('id');
$answersID = Answer::query()->whereIn('id', $request->answers)->pluck('id');
$customer->answers()->sync($answersID->merge($existingAnswerIds));
$customer->answers()->sync($request->validated('answers'));
return response()->json();
}
}

View file

@ -4,9 +4,7 @@ namespace App\Http\Controllers\Api\V4;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\V4\StoreCustomerAnswers;
use App\Models\Answer;
use App\Models\Customer;
use App\Models\Service;
use Illuminate\Http\JsonResponse;
class AnswerController extends Controller
@ -15,21 +13,17 @@ class AnswerController extends Controller
* Store the customer answers.
*
* @param \App\Http\Requests\Api\V4\StoreCustomerAnswers $request
* @param \App\Models\Service $service
* @param \App\Models\Customer $customer
* @return \Illuminate\Http\JsonResponse
*/
public function storeCustomerAnswers(
StoreCustomerAnswers $request,
Service $service,
Customer $customer
): JsonResponse {
// * Make sure we are accessing a customer that belongs to our service.
$this->authorize('customerBelongsToService', $customer);
$existingAnswerIds = $customer->getAnswers($service)->pluck('id');
$answersID = Answer::query()->whereIn('id', $request->answers)->pluck('id');
$customer->answers()->sync($answersID->merge($existingAnswerIds));
$customer->answers()->sync($request->validated('answers'));
return response()->json();
}
}

View file

@ -3,8 +3,7 @@
@section('title', sprintf('%s - %s', __('models.classes.answers'), Str::ucfirst(__('liste'))))
@section('description', __('Listage de toutes les :model', ['model' => __('models.classes.answers')]))
@section('metaIndex', 'noindex,nofollow')
@section('breadcrumb',
request()->route()->getName())
@section('breadcrumb', request()->route()->getName())
@section('content')
<div class="row w-100 mx-auto">
@ -18,7 +17,7 @@
title="{{ __('Retourner sur la liste des :model', ['model' => __('models.classes.questions')]) }}">
<i class="fa-solid fa-arrow-left"></i>
</a>
@include('breadcrumbs.breadcrumb-body', ['brParam' => $questionModel])
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $questionModel])
</div>
@can('create', \App\Models\Answer::class)
<div class="col-md-3 d-flex align-items-center p-0">