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'); } diff --git a/resources/assets/vue/components/vouchers/elements/SingleVoucherCampaignItemComponent.vue b/resources/assets/vue/components/vouchers/elements/SingleVoucherCampaignItemComponent.vue index 40c082ee..43b9d59a 100644 --- a/resources/assets/vue/components/vouchers/elements/SingleVoucherCampaignItemComponent.vue +++ b/resources/assets/vue/components/vouchers/elements/SingleVoucherCampaignItemComponent.vue @@ -2,6 +2,7 @@
{{data.name}}
{{data.metadata && data.metadata.length > 0 ? data.metadata[0].value : 0 }}
+
{{data.metadata && data.metadata.length > 0 ? extractMonth(data.metadata[0].key) : '' }}
{{data.limit_per_month}}
{{data.campaign_id}}
@@ -17,6 +18,18 @@ }, }, methods: { + extractMonth(inputString) { + const firstUnderscoreIndex = inputString.indexOf('_'); + if (firstUnderscoreIndex === -1) return ''; + + const secondUnderscoreIndex = inputString.indexOf('_', firstUnderscoreIndex + 1); + if (secondUnderscoreIndex === -1) return ''; + + const thirdUnderscoreIndex = inputString.indexOf('_', secondUnderscoreIndex + 1); + if (thirdUnderscoreIndex === -1) return ''; + + return inputString.substring(secondUnderscoreIndex + 1, thirdUnderscoreIndex); + } }, mixins: [componentHandler], } diff --git a/resources/assets/vue/components/vouchers/sections/VoucherCampaignsSectionComponent.vue b/resources/assets/vue/components/vouchers/sections/VoucherCampaignsSectionComponent.vue index be8460f5..6170762a 100644 --- a/resources/assets/vue/components/vouchers/sections/VoucherCampaignsSectionComponent.vue +++ b/resources/assets/vue/components/vouchers/sections/VoucherCampaignsSectionComponent.vue @@ -10,7 +10,8 @@
Name
-
Issued (this month)
+
Issued
+
Month
Limit Per Month
Campaign Id