From 8973e7b50f58c61e36d3f0b55d4c2a47b1cc522a Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 4 Aug 2024 03:22:53 +0800 Subject: [PATCH] Fix a problem where voucherify campaign vouchers limit not displaying with correct info for the month --- app/Classes/General/Interfaces/KeyValueInterface.php | 2 +- app/Classes/Modules/Accounts/Services/CreatesKeyValuePair.php | 2 +- .../Modules/Vouchers/ControllersLogic/CreateVoucherLogic.php | 2 +- app/Http/Resources/UserRewardResource.php | 2 +- app/Http/Resources/VoucherCampaignResource.php | 2 +- app/Models/User.php | 4 ++-- app/Models/VoucherCampaign.php | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Classes/General/Interfaces/KeyValueInterface.php b/app/Classes/General/Interfaces/KeyValueInterface.php index fbee5265..8089e46a 100644 --- a/app/Classes/General/Interfaces/KeyValueInterface.php +++ b/app/Classes/General/Interfaces/KeyValueInterface.php @@ -8,5 +8,5 @@ use Illuminate\Database\Eloquent\Relations\MorphMany; interface KeyValueInterface { - public function attributes(): morphMany; + public function attributesKVP(): morphMany; } diff --git a/app/Classes/Modules/Accounts/Services/CreatesKeyValuePair.php b/app/Classes/Modules/Accounts/Services/CreatesKeyValuePair.php index c963ec4e..6634bed2 100644 --- a/app/Classes/Modules/Accounts/Services/CreatesKeyValuePair.php +++ b/app/Classes/Modules/Accounts/Services/CreatesKeyValuePair.php @@ -22,7 +22,7 @@ class CreatesKeyValuePair extends AbstractUpdateRelationshipRecord $model->key = $object->getKey(); $model->value = $object->getValue(); - return $this->handler($kv->attributes(), $model); + return $this->handler($kv->attributesKVP(), $model); } } diff --git a/app/Classes/Modules/Vouchers/ControllersLogic/CreateVoucherLogic.php b/app/Classes/Modules/Vouchers/ControllersLogic/CreateVoucherLogic.php index de29aa63..5c85895a 100644 --- a/app/Classes/Modules/Vouchers/ControllersLogic/CreateVoucherLogic.php +++ b/app/Classes/Modules/Vouchers/ControllersLogic/CreateVoucherLogic.php @@ -193,7 +193,7 @@ class CreateVoucherLogic extends AbstractControllerLogic $key, $total ); - $metadata = $voucherCampaign->attributes()->where('key', $key)->first(); + $metadata = $voucherCampaign->attributesKVP()->where('key', $key)->first(); if($metadata){ $this->updatesKeyValuePair->execute($metadata, $keyValuePairObject); } diff --git a/app/Http/Resources/UserRewardResource.php b/app/Http/Resources/UserRewardResource.php index b988a1d3..25080270 100644 --- a/app/Http/Resources/UserRewardResource.php +++ b/app/Http/Resources/UserRewardResource.php @@ -17,7 +17,7 @@ class UserRewardResource extends JsonResource { $emailReminder = null; if ($request->has('isAdmin')) { - $keyValuePairs = $this->user->attributes()->get(); + $keyValuePairs = $this->user->attributesKVP()->get(); $emailReminder = KeyValueBasicResource::collection($keyValuePairs); $this->voucher->email = $emailReminder; } diff --git a/app/Http/Resources/VoucherCampaignResource.php b/app/Http/Resources/VoucherCampaignResource.php index ade4334b..ebc6964c 100644 --- a/app/Http/Resources/VoucherCampaignResource.php +++ b/app/Http/Resources/VoucherCampaignResource.php @@ -17,7 +17,7 @@ class VoucherCampaignResource extends JsonResource { $metadata = null; if ($request->has('include_metadata')) { - $metadata = KeyValueBasicResource::collection($this->attributes); + $metadata = KeyValueBasicResource::collection($this->attributesKVP()->latest()->get()); } return [ diff --git a/app/Models/User.php b/app/Models/User.php index 7e0a4aa9..46e8635f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -106,7 +106,7 @@ class User extends AbstractModel implements public function hasAttribute(string $key, $value = null): bool { - $query = $this->attributes()->where('key', $key); + $query = $this->attributesKVP()->where('key', $key); if ($value !== null) { $query->where('value', $value); @@ -116,7 +116,7 @@ class User extends AbstractModel implements } - public function attributes(): MorphMany + public function attributesKVP(): MorphMany { return $this->morphMany(KeyValuePair::class, 'owner'); } diff --git a/app/Models/VoucherCampaign.php b/app/Models/VoucherCampaign.php index e97320e5..4e14cc12 100644 --- a/app/Models/VoucherCampaign.php +++ b/app/Models/VoucherCampaign.php @@ -22,7 +22,7 @@ class VoucherCampaign extends AbstractModel implements KeyValueInterface /** * @return MorphMany */ - public function attributes(): MorphMany + public function attributesKVP(): MorphMany { return $this->morphMany(KeyValuePair::class, 'owner'); }