瀏覽代碼

add the OrganizationIdentification entity and view

Olivier Massot 1 年之前
父節點
當前提交
0fcd62e67d

+ 1 - 0
sql/schema-extensions/003-view_organization_identification.sql

@@ -1,5 +1,6 @@
 CREATE OR REPLACE VIEW view_organization_identification AS
     SELECT o.id, o.name, REGEXP_REPLACE(LOWER(o.name), '[^a-z0-9]+', '+') AS normalizedName,
+       o.identifier, o.siretNumber, o.waldecNumber,
        CONCAT(a.streetAddress, ' ', a.streetAddressSecond, ' ', a.streetAddressThird) AS address,
        a.addressCity AS city, a.postalCode, c.email, c.telphone
     FROM opentalent.Organization o

+ 29 - 0
src/ApiResources/Organization/OrganizationCreationRequest.php

@@ -51,8 +51,15 @@ class OrganizationCreationRequest
      * Matricule (obligatoire dans le réseau CMF)
      * @var string
      */
+    #[Assert\Regex(pattern: '/^|(FR\d{12})$/')]
     private string $identifier = '';
 
+    #[Assert\Regex(pattern: '/^|(\d+)$/')]
+    private string $siretNumber = '';
+
+    #[Assert\Regex(pattern: '/^|(W\d+)$/')]
+    private string $waldecNumber = '';
+
     private ?LegalEnum $legalStatus = null;
 
     private SettingsProductEnum $product;
@@ -188,6 +195,28 @@ class OrganizationCreationRequest
         return $this;
     }
 
+    public function getSiretNumber(): string
+    {
+        return $this->siretNumber;
+    }
+
+    public function setSiretNumber(string $siretNumber): self
+    {
+        $this->siretNumber = $siretNumber;
+        return $this;
+    }
+
+    public function getWaldecNumber(): string
+    {
+        return $this->waldecNumber;
+    }
+
+    public function setWaldecNumber(string $waldecNumber): self
+    {
+        $this->waldecNumber = $waldecNumber;
+        return $this;
+    }
+
     public function getLegalStatus(): LegalEnum
     {
         return $this->legalStatus;

+ 42 - 0
src/Entity/Organization/OrganizationIdentification.php

@@ -36,6 +36,15 @@ class OrganizationIdentification
     #[ORM\Column]
     private string $normalizedName;
 
+    #[ORM\Column]
+    private ?string $identifier;
+
+    #[ORM\Column]
+    private ?string $siretNumber;
+
+    #[ORM\Column]
+    private ?string $waldecNumber;
+
     #[ORM\Column]
     private ?string $address;
 
@@ -84,6 +93,39 @@ class OrganizationIdentification
         return $this;
     }
 
+    public function getIdentifier(): ?string
+    {
+        return $this->identifier;
+    }
+
+    public function setIdentifier(?string $identifier): self
+    {
+        $this->identifier = $identifier;
+        return $this;
+    }
+
+    public function getSiretNumber(): ?string
+    {
+        return $this->siretNumber;
+    }
+
+    public function setSiretNumber(?string $siretNumber): self
+    {
+        $this->siretNumber = $siretNumber;
+        return $this;
+    }
+
+    public function getWaldecNumber(): ?string
+    {
+        return $this->waldecNumber;
+    }
+
+    public function setWaldecNumber(?string $waldecNumber): self
+    {
+        $this->waldecNumber = $waldecNumber;
+        return $this;
+    }
+
     public function getAddress(): ?string
     {
         return $this->address;

+ 36 - 3
src/Service/Organization/OrganizationFactory.php

@@ -88,8 +88,8 @@ class OrganizationFactory
 
         try {
             // On vérifie si cette organisation n'existe pas déjà
-            $this->assertNotExisting($organizationCreationRequest);
-            dd('yo');
+            $this->interruptIfOrganizationExists($organizationCreationRequest);
+
             // On vérifie la validité et la disponibilité du sous domaine
             $this->validateSubdomain($organizationCreationRequest->getSubdomain());
             $this->logger->info("Subdomain is valid and available : '" . $organizationCreationRequest->getSubdomain() . "'");
@@ -167,8 +167,41 @@ class OrganizationFactory
      *
      * @param OrganizationCreationRequest $organizationCreationRequest
      */
-    protected function assertNotExisting(OrganizationCreationRequest $organizationCreationRequest): void
+    protected function interruptIfOrganizationExists(OrganizationCreationRequest $organizationCreationRequest): void
     {
+        if (
+            $organizationCreationRequest->getSiretNumber() &&
+            $this->organizationIdentificationRepository->findOneBy(
+                ['siretNumber' => $organizationCreationRequest->getSiretNumber()]
+            )
+        ) {
+            throw new \RuntimeException(
+                "This siret number is already registered : '" . $organizationCreationRequest->getSiretNumber()
+            );
+        }
+
+        if (
+            $organizationCreationRequest->getWaldecNumber() &&
+            $this->organizationIdentificationRepository->findOneBy(
+                ['waldecNumber' => $organizationCreationRequest->getWaldecNumber()]
+            )
+        ) {
+            throw new \RuntimeException(
+                "This RNA identifier (waldec number) is already registered : '" . $organizationCreationRequest->getWaldecNumber()
+            );
+        }
+
+        if (
+            $organizationCreationRequest->getIdentifier() &&
+            $this->organizationIdentificationRepository->findOneBy(
+                ['identifier' => $organizationCreationRequest->getIdentifier()]
+            )
+        ) {
+            throw new \RuntimeException(
+                "This CMF identifier is already registered : '" . $organizationCreationRequest->getIdentifier()
+            );
+        }
+
         $normalizedName = preg_replace(
             "/[^a-z0-9]+/",
             "+",