Переглянути джерело

OrganizationMemberCreationRequest: makes username and phone unrequired

Olivier Massot 9 місяців тому
батько
коміт
23bb8823f6

+ 0 - 27
config/packages/elastica.yaml

@@ -1,27 +0,0 @@
-imports:
-  - { resource: elastica/ }
-
-fos_elastica:
-  clients:
-    default: { host: '%env(resolve:ELASTICSEARCH_HOST)%', port: '%env(resolve:ELASTICSEARCH_PORT)%' }
-  indexes:
-    search:
-      use_alias: true
-      client: default
-      finder: ~
-      settings:
-        index:
-          analysis:
-            analyzer:
-              search_analyzer:
-                type:    custom
-                tokenizer:    standard
-                filter:    [standard, asciifolding ,lowercase]
-              custom_analyzer:
-                type:    custom
-                tokenizer:    standard
-                filter:    [standard, asciifolding ,lowercase]
-              custom_search_analyzer:
-                type:    custom
-                tokenizer:    standard
-                filter:    [standard, asciifolding ,lowercase]

+ 0 - 24
config/packages/elastica/educationNotation.yaml

@@ -1,24 +0,0 @@
-fos_elastica:
-  indexes:
-    search:
-      types:
-        educationNotation:
-          persistence:
-            driver: orm
-            model: 'App\Entity\Education\EducationNotation'
-            listener: ~
-            finder: ~
-            elastica_to_model_transformer:
-              ignore_missing: true
-          mappings:
-            id:
-              index: not_analyzed
-              type: integer
-            note_origine:
-              analyzer: custom_analyzer
-              search_analyzer: custom_search_analyzer
-              property_path: false
-            note_recalcul:
-              analyzer: custom_analyzer
-              search_analyzer: custom_search_analyzer
-              property_path: false

+ 0 - 20
config/packages/elastica/organization.yaml

@@ -1,20 +0,0 @@
-fos_elastica:
-  indexes:
-    search:
-      types:
-        organization:
-          persistence:
-            driver: orm
-            model: 'App\Entity\Organization\Organization'
-            listener: ~
-            finder: ~
-            elastica_to_model_transformer:
-              ignore_missing: true
-            provider: ~
-          mappings:
-            id:
-              index: not_analyzed
-              type: integer
-            name:
-              analyzer: custom_analyzer
-              search_analyzer: custom_search_analyzer

+ 6 - 6
src/ApiResources/Organization/OrganizationMemberCreationRequest.php

@@ -15,7 +15,7 @@ class OrganizationMemberCreationRequest
     private GenderEnum $gender = GenderEnum::MISTER;
 
     #[Assert\Regex(pattern: '/^[a-z0-9\-]{3,}$/')]
-    private string $username;
+    private ?string $username = null;
 
     #[Assert\Length(
         min: 1,
@@ -57,7 +57,7 @@ class OrganizationMemberCreationRequest
         min: 10,
         minMessage: 'Phone number must be at least {{ limit }} characters long',
     )]
-    private string $phone;
+    private ?string $phone = null;
 
     #[Assert\Length(
         min: 10,
@@ -70,12 +70,12 @@ class OrganizationMemberCreationRequest
     )]
     private string $email;
 
-    public function getUsername(): string
+    public function getUsername(): ?string
     {
         return $this->username;
     }
 
-    public function setUsername(string $username): self
+    public function setUsername(?string $username): self
     {
         $this->username = $username;
 
@@ -190,12 +190,12 @@ class OrganizationMemberCreationRequest
         return $this;
     }
 
-    public function getPhone(): string
+    public function getPhone(): ?string
     {
         return $this->phone;
     }
 
-    public function setPhone(string $phone): self
+    public function setPhone(?string $phone): self
     {
         $this->phone = $phone;
 

+ 15 - 4
src/Service/Organization/OrganizationFactory.php

@@ -600,7 +600,10 @@ class OrganizationFactory
         } else {
             $person = new Person();
 
-            if ($this->personRepository->findOneBy(['username' => $creationRequestData->getUsername()])) {
+            if (
+                $creationRequestData->getUsername() !== null &&
+                $this->personRepository->findOneBy(['username' => $creationRequestData->getUsername()])
+            ) {
                 throw new \RuntimeException('Username already in use : '.$creationRequestData->getUsername());
             }
 
@@ -692,21 +695,29 @@ class OrganizationFactory
         \DateTime $creationDate,
         ?int $authorId,
     ): ContactPoint {
-        if (!$this->phoneNumberUtil->isPossibleNumber($organizationMemberCreationRequest->getPhone())) {
+        if (
+            $organizationMemberCreationRequest->getPhone() !== null
+            && !$this->phoneNumberUtil->isPossibleNumber($organizationMemberCreationRequest->getPhone())
+        ) {
             throw new \RuntimeException('Phone number is invalid or missing (person: '.$organizationMemberCreationRequest->getUsername().')');
         }
+
         if (
             $organizationMemberCreationRequest->getMobile() !== null
             && !$this->phoneNumberUtil->isPossibleNumber($organizationMemberCreationRequest->getMobile())) {
             throw new \RuntimeException('Mobile phone number is invalid (person: '.$organizationMemberCreationRequest->getUsername().')');
         }
 
-        $phoneNumber = $this->phoneNumberUtil->parse($organizationMemberCreationRequest->getPhone());
+
 
         $contactPoint = new ContactPoint();
         $contactPoint->setContactType(ContactPointTypeEnum::PRINCIPAL);
         $contactPoint->setEmail($organizationMemberCreationRequest->getEmail());
-        $contactPoint->setTelphone($phoneNumber);
+
+        if ($organizationMemberCreationRequest->getPhone() !== null) {
+            $phoneNumber = $this->phoneNumberUtil->parse($organizationMemberCreationRequest->getPhone());
+            $contactPoint->setTelphone($phoneNumber);
+        }
 
         if ($organizationMemberCreationRequest->getMobile() !== null) {
             $mobileNumber = $this->phoneNumberUtil->parse($organizationMemberCreationRequest->getMobile());