Skip to content

Commit

Permalink
Merge pull request #2324 from MTES-MCT/bugfix/2323-oilhi-remove-usele…
Browse files Browse the repository at this point in the history
…ss-fields

[Oilhi] Supprimer champs problématiques à l'enregistrement Airtable
  • Loading branch information
numew authored Mar 8, 2024
2 parents 568ba3f + 3e0b107 commit a7fa2ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/Factory/Interconnection/Oilhi/DossierMessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Entity\Situation;
use App\Factory\Interconnection\DossierMessageFactoryInterface;
use App\Messenger\Message\Oilhi\DossierMessage;
use App\Service\HtmlCleaner;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
Expand Down Expand Up @@ -146,18 +147,17 @@ private function buildDesordresData(Signalement $signalement): array
}

if (!$signalement->getDesordrePrecisions()->isEmpty()) {
$precisions = implode(
', ',
$signalement
->getDesordrePrecisions()
->filter(function (DesordrePrecision $desordrePrecision) {
return ' - ' !== $desordrePrecision->getLabel();
})
->map(function (DesordrePrecision $desordrePrecision) {
return $desordrePrecision->getLabel();
})->toArray()
);
$desordres['precisions'] = str_replace('-', '', $precisions);
$precisionsList = $signalement
->getDesordrePrecisions()
->filter(function (DesordrePrecision $desordrePrecision) {
return ' - ' !== $desordrePrecision->getLabel();
})
->map(function (DesordrePrecision $desordrePrecision) {
if (!empty($desordrePrecision->getLabel())) {
return HtmlCleaner::clean($desordrePrecision->getLabel());
}
})->toArray();
$desordres['precisions'] = implode(',', array_filter($precisionsList));
}

return $desordres;
Expand Down
12 changes: 12 additions & 0 deletions src/Service/Oilhi/HookZapierService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
public function pushDossier(DossierMessage $dossierMessage): ResponseInterface|JsonResponse
{
$payload = $this->normalizer->normalize($dossierMessage);
$payload = $this->removeUselessFields($payload);
$payload['token'] = $this->token;
$options = [
'headers' => [
Expand All @@ -58,4 +59,15 @@ public function pushDossier(DossierMessage $dossierMessage): ResponseInterface|J

return (new JsonResponse($response))->setStatusCode(Response::HTTP_SERVICE_UNAVAILABLE);
}

/**
* Utile pour le traitement interne mais inutile à l'enregistrement dans Airtable.
*/
private function removeUselessFields(array $payload): array
{
unset($payload['signalementId']);
unset($payload['partnerId']);

return $payload;
}
}

0 comments on commit a7fa2ba

Please sign in to comment.