5764d8f472
- Prestataire : entité/repo + ressource API Platform (RBAC directory.providers.*), ownership prestataire sur contacts/adresses/comptes-rendus (CHECK XOR à 3), DTO/service/drawer/fiche détail + onglet dédié dans le répertoire. - Prospect : société uniquement (suppression du champ name, company requis) ; migration de backfill, conversion prospect→client et MCP adaptés. - Champ site web sur client/prospect/prestataire (entités, DTO, onglet Information, MCP). - Validateurs front email / téléphone FR (0549200910) / URL sur Information et Contacts, enregistrement bloqué tant qu'un champ est invalide. - Autocomplete adresse branché sur la Base Adresse Nationale (api-adresse.data.gouv.fr) avec mode dégradé en saisie libre. - Administration : retrait de l'onglet Clients.
77 lines
2.4 KiB
PHP
77 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Module\Directory\Infrastructure\Mcp\Tool;
|
|
|
|
use App\Module\Directory\Domain\Enum\ProspectStatus;
|
|
use App\Module\Directory\Domain\Repository\ProspectRepositoryInterface;
|
|
use App\Shared\Infrastructure\Mcp\Serializer;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use InvalidArgumentException;
|
|
use Mcp\Capability\Attribute\McpTool;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|
|
|
use function sprintf;
|
|
|
|
#[McpTool(name: 'update-prospect', description: 'Update a prospect (admin). Only provided fields change.')]
|
|
class UpdateProspectTool
|
|
{
|
|
public function __construct(
|
|
private readonly ProspectRepositoryInterface $prospectRepository,
|
|
private readonly EntityManagerInterface $entityManager,
|
|
private readonly Security $security,
|
|
) {}
|
|
|
|
public function __invoke(
|
|
int $id,
|
|
?string $company = null,
|
|
?string $email = null,
|
|
?string $phone = null,
|
|
?string $website = null,
|
|
?string $status = null,
|
|
?string $source = null,
|
|
?string $notes = null,
|
|
): string {
|
|
if (!$this->security->isGranted('ROLE_ADMIN')) {
|
|
throw new AccessDeniedException('Access denied: ROLE_ADMIN required.');
|
|
}
|
|
|
|
$prospect = $this->prospectRepository->findById($id);
|
|
if (null === $prospect) {
|
|
throw new InvalidArgumentException(sprintf('Prospect with ID %d not found.', $id));
|
|
}
|
|
|
|
if (null !== $company) {
|
|
$prospect->setCompany($company);
|
|
}
|
|
if (null !== $email) {
|
|
$prospect->setEmail($email);
|
|
}
|
|
if (null !== $phone) {
|
|
$prospect->setPhone($phone);
|
|
}
|
|
if (null !== $website) {
|
|
$prospect->setWebsite($website);
|
|
}
|
|
if (null !== $status) {
|
|
$statusEnum = ProspectStatus::tryFrom($status);
|
|
if (null === $statusEnum) {
|
|
throw new InvalidArgumentException(sprintf('Invalid status "%s". Allowed: new, contacted, qualified, won, lost.', $status));
|
|
}
|
|
$prospect->setStatus($statusEnum);
|
|
}
|
|
if (null !== $source) {
|
|
$prospect->setSource($source);
|
|
}
|
|
if (null !== $notes) {
|
|
$prospect->setNotes($notes);
|
|
}
|
|
|
|
$this->entityManager->flush();
|
|
|
|
return json_encode(Serializer::prospect($prospect));
|
|
}
|
|
}
|