fix: 🔥 move claim customer association into server side

This commit is contained in:
Alexis Gousseau 2026-03-31 14:59:48 +02:00
parent e170cf351e
commit 2a56bf4c67
No known key found for this signature in database
GPG key ID: 7F3C786EE12DBB72
2 changed files with 12 additions and 2 deletions

View file

@ -6,6 +6,7 @@ use App\Exceptions\Api\V4\CrmException;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\V4\SendClaimRequest;
use App\Models\Claim;
use App\Models\CustomerInfo;
use App\Models\Service;
use Illuminate\Support\Arr;
use Uwil\LaravelCommon\Helpers\FileHelper;
@ -24,7 +25,17 @@ class ClaimController extends Controller
{
$claimModel = (new Claim())->fill(Arr::except($request->validated(), 'file'));
if ($request->filled('file')) {
$claimModel->file = FileHelper::storeBase64File('claim', $request->file, private: true);
$claimModel->file = FileHelper::storeBase64File(
tableName: 'claim',
fileBase64: $request->file,
private: true,
);
}
// Add customer relation if exist.
$crmCustomer = CustomerInfo::getFromEmail($claimModel->brand, $claimModel->email)->first();
if (!is_null($crmCustomer)) {
$claimModel->hashcode = $crmCustomer->hashcode;
}
if (!$claimModel->saveOrFail()) {

View file

@ -82,7 +82,6 @@ class SendClaimRequest extends BaseApiRequest
'message' => 'required|string|min:3',
'brand_id' => 'required|integer|exists:brands,id',
'subject_id' => 'required|integer|exists:claim_subjects,id',
'hashcode' => 'sometimes|nullable|string|size:36',
];
}
}