Add organization entity to db
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\ApiResource\User;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\State\Options;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\Entity\User\Organization;
|
||||
use App\State\ApiResourceStateProcessor;
|
||||
use App\State\ApiResourceStateProvider;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
@@ -18,13 +20,14 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
#[API\ApiResource(
|
||||
shortName: 'Organization',
|
||||
security: 'is_granted("ORGANIZATION_VIEW", object)',
|
||||
stateOptions: new Options(entityClass: Organization::class),
|
||||
provider: ApiResourceStateProvider::class,
|
||||
processor: ApiResourceStateProcessor::class,
|
||||
uriTemplate: '/users/{id}/organization',
|
||||
uriVariables: [
|
||||
'id' => new API\Link(
|
||||
fromClass: UserApiResource::class,
|
||||
fromProperty: 'Organization'
|
||||
fromProperty: 'organization'
|
||||
),
|
||||
]
|
||||
)]
|
||||
|
||||
@@ -78,11 +78,17 @@ class UserApiResource
|
||||
public string $displayName;
|
||||
|
||||
/**
|
||||
* For `individual` User types: personal data about the User themselves,
|
||||
* for `organization` User types: personal data for the organization representative.
|
||||
* For `individual` User types: personal data about the User themselves.\
|
||||
* For `organization` User types: data for the organization representative or person managing the User.
|
||||
*/
|
||||
#[API\ApiProperty(writable: false)]
|
||||
public ?PersonApiResource $person = null;
|
||||
public PersonApiResource $person;
|
||||
|
||||
/**
|
||||
* For `organization` User types only. Legal entity data.
|
||||
*/
|
||||
#[API\ApiProperty(writable: false)]
|
||||
public ?OrganizationApiResource $organization = null;
|
||||
|
||||
/**
|
||||
* The Accounting for this User monetary movements.
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\User;
|
||||
|
||||
use Ambta\DoctrineEncryptBundle\Configuration\Encrypted;
|
||||
use App\Repository\User\OrganizationRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: OrganizationRepository::class)]
|
||||
class Organization
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\OneToOne(inversedBy: 'organization', cascade: ['persist', 'remove'])]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?User $user = null;
|
||||
|
||||
/**
|
||||
* ID for tax purposes. e.g: NIF (formerly CIF), Umsatzsteuer-Id, EID, etc.
|
||||
*/
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Encrypted()]
|
||||
private ?string $taxId = null;
|
||||
|
||||
/**
|
||||
* Organization legal name before government,
|
||||
* as it appears on legal documents issued by or for this organization.
|
||||
*/
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $legalName = null;
|
||||
|
||||
/**
|
||||
* The name under which the organization presents itself.
|
||||
*/
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $businessName = null;
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(User $user): static
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTaxId(): ?string
|
||||
{
|
||||
return $this->taxId;
|
||||
}
|
||||
|
||||
public function setTaxId(string $taxId): static
|
||||
{
|
||||
$this->taxId = $taxId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLegalName(): ?string
|
||||
{
|
||||
return $this->legalName;
|
||||
}
|
||||
|
||||
public function setLegalName(string $legalName): static
|
||||
{
|
||||
$this->legalName = $legalName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBusinessName(): ?string
|
||||
{
|
||||
return $this->businessName;
|
||||
}
|
||||
|
||||
public function setBusinessName(?string $businessName): static
|
||||
{
|
||||
$this->businessName = $businessName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Account
|
||||
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
|
||||
private ?Person $person = null;
|
||||
|
||||
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
|
||||
private ?Organization $organization = null;
|
||||
|
||||
/**
|
||||
* @var list<string> The user roles. Admin only property.
|
||||
*/
|
||||
@@ -268,6 +271,23 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Account
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrganization(): ?Organization
|
||||
{
|
||||
return $this->organization;
|
||||
}
|
||||
|
||||
public function setOrganization(Organization $organization): static
|
||||
{
|
||||
// set the owning side of the relation if necessary
|
||||
if ($organization->getUser() !== $this) {
|
||||
$organization->setUser($this);
|
||||
}
|
||||
|
||||
$this->organization = $organization;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UserInterface
|
||||
*
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository\User;
|
||||
|
||||
use App\Entity\User\Organization;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Organization>
|
||||
*/
|
||||
class OrganizationRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Organization::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Organization[] Returns an array of Organization objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('o')
|
||||
// ->andWhere('o.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('o.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?Organization
|
||||
// {
|
||||
// return $this->createQueryBuilder('o')
|
||||
// ->andWhere('o.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user