From fe18ae8edc6ea11066cb440cdb3f656fd2c51cf3 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Tue, 9 Sep 2025 14:19:45 +0200 Subject: [PATCH] Minor bug fixes --- src/ApiResource/ApiMoney.php | 2 +- src/ApiResource/Project/RewardApiResource.php | 2 ++ src/Benzina/UsersPump.php | 8 +++++++- src/Entity/Project/RewardClaim.php | 2 +- src/Entity/Project/Support.php | 2 +- src/EventListener/GatewayCheckoutSupportsListener.php | 4 ++-- src/Mapping/AutoMapper.php | 4 +++- src/Service/AccountingService.php | 5 +++-- 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/ApiResource/ApiMoney.php b/src/ApiResource/ApiMoney.php index 3d56faf..daab79e 100644 --- a/src/ApiResource/ApiMoney.php +++ b/src/ApiResource/ApiMoney.php @@ -28,7 +28,7 @@ class ApiMoney implements MoneyInterface * Conversion metadata. */ #[API\ApiProperty(readable: true, writable: false)] - public ?array $conversion; + public ?array $conversion = null; public function __construct( int $amount, diff --git a/src/ApiResource/Project/RewardApiResource.php b/src/ApiResource/Project/RewardApiResource.php index 3c864aa..8589018 100644 --- a/src/ApiResource/Project/RewardApiResource.php +++ b/src/ApiResource/Project/RewardApiResource.php @@ -13,6 +13,7 @@ use App\Entity\Project\Reward; use App\State\ApiResourceStateProvider; use App\State\Project\RewardStateProcessor; use AutoMapper\Attribute\MapTo; +use Symfony\Component\Serializer\Attribute\MaxDepth; use Symfony\Component\Validator\Constraints as Assert; /** @@ -91,5 +92,6 @@ class RewardApiResource * @var RewardClaimApiResource[] */ #[API\ApiProperty(writable: false)] + #[MaxDepth(2)] public array $claims; } diff --git a/src/Benzina/UsersPump.php b/src/Benzina/UsersPump.php index 10f8d9f..53da200 100644 --- a/src/Benzina/UsersPump.php +++ b/src/Benzina/UsersPump.php @@ -64,7 +64,13 @@ class UsersPump implements PumpInterface private function getDateCreated(array $record): \DateTime { - return new \DateTime($record['created'] ?? $record['modified']); + $created = new \DateTime($record['created'] ?? '0000-00-00'); + + if ($created > new \DateTime('2011-01-01')) { + return $created; + } + + return new \DateTime($record['modified'] ?? 'now'); } private function getUserType(array $record): UserType diff --git a/src/Entity/Project/RewardClaim.php b/src/Entity/Project/RewardClaim.php index 1707ea5..023f39b 100644 --- a/src/Entity/Project/RewardClaim.php +++ b/src/Entity/Project/RewardClaim.php @@ -27,7 +27,7 @@ class RewardClaim implements UserOwnedInterface #[ORM\JoinColumn(nullable: false)] private ?Charge $charge = null; - #[ORM\ManyToOne(inversedBy: 'claims')] + #[ORM\ManyToOne(inversedBy: 'claims', cascade: ['persist'])] #[ORM\JoinColumn(nullable: false)] private ?Reward $reward = null; diff --git a/src/Entity/Project/Support.php b/src/Entity/Project/Support.php index 0262d3a..4a67613 100644 --- a/src/Entity/Project/Support.php +++ b/src/Entity/Project/Support.php @@ -16,7 +16,7 @@ use Doctrine\ORM\Mapping\Embedded; #[MapProvider(EntityMapProvider::class)] #[ORM\Table(name: 'project_support')] -#[ORM\UniqueConstraint(fields: ['project', 'origin'])] +#[ORM\UniqueConstraint(fields: ['project', 'origin'], name: 'project_origin_unique')] #[ORM\Entity(repositoryClass: SupportRepository::class)] class Support { diff --git a/src/EventListener/GatewayCheckoutSupportsListener.php b/src/EventListener/GatewayCheckoutSupportsListener.php index 5960518..860685c 100644 --- a/src/EventListener/GatewayCheckoutSupportsListener.php +++ b/src/EventListener/GatewayCheckoutSupportsListener.php @@ -99,8 +99,8 @@ class GatewayCheckoutSupportsListener { /** @var Support|null */ $projectSupport = $this->supportRepository->findOneBy([ - 'project' => $project->getId(), - 'origin' => $origin->getId(), + 'project' => $project, + 'origin' => $origin, ]); if (!$projectSupport) { diff --git a/src/Mapping/AutoMapper.php b/src/Mapping/AutoMapper.php index 1e20c33..d63aedd 100644 --- a/src/Mapping/AutoMapper.php +++ b/src/Mapping/AutoMapper.php @@ -4,13 +4,15 @@ namespace App\Mapping; use AutoMapper\AutoMapper as InnerMapper; use AutoMapper\AutoMapperInterface; +use AutoMapper\MapperContext; class AutoMapper implements AutoMapperInterface { public const CACHE_DIR = 'automapper'; public const DEFAULT_CONTEXT = [ - 'skip_null_values' => true, + MapperContext::DEPTH => 1, + MapperContext::SKIP_NULL_VALUES => true, ]; private AutoMapperInterface $innerMapper; diff --git a/src/Service/AccountingService.php b/src/Service/AccountingService.php index e9c5380..09f7289 100644 --- a/src/Service/AccountingService.php +++ b/src/Service/AccountingService.php @@ -55,7 +55,7 @@ class AccountingService * * @return Transaction[] */ - private function getTransactionsInPeriod( + private function filterTransactions( array $transactions, \DateTimeInterface $start, \DateTimeInterface $end, @@ -97,13 +97,14 @@ class AccountingService $period->getStartDate(), $period->getEndDate(), ); + $points = []; $totalBalance = new Money(0, $accounting->getCurrency()); $accountingId = $accounting->getId(); foreach ($period as $start) { $end = \DateTime::createFromInterface($start)->add($period->getDateInterval()); - $periodTrxs = $this->getTransactionsInPeriod($trxs, $start, $end); + $periodTrxs = $this->filterTransactions($trxs, $start, $end); $balance = $aggregate ? $totalBalance : new Money(0, $accounting->getCurrency()); foreach ($periodTrxs as $trx) {