diff --git a/src/GraphQL/Mutations/AddTokensMutation.php b/src/GraphQL/Mutations/AddTokensMutation.php index a202528..2da62e5 100644 --- a/src/GraphQL/Mutations/AddTokensMutation.php +++ b/src/GraphQL/Mutations/AddTokensMutation.php @@ -6,6 +6,7 @@ use Enjin\Platform\Beam\Enums\BeamType; use Enjin\Platform\Beam\GraphQL\Traits\HasBeamCommonFields; use Enjin\Platform\Beam\Models\Beam; +use Enjin\Platform\Beam\Rules\BeamExists; use Enjin\Platform\Beam\Rules\MaxTokenCount; use Enjin\Platform\Beam\Rules\MaxTokenSupply; use Enjin\Platform\Beam\Rules\TokensDoNotExistInBeam; @@ -86,7 +87,11 @@ protected function rules(array $args = []): array $beam = Beam::whereCode($args['code'])->first(); return [ - 'code' => ['filled', 'max:1024', 'exists:beams,code,deleted_at,NULL'], + 'code' => [ + 'filled', + 'max:1024', + new BeamExists(), + ], 'tokens' => ['bail', 'array', 'min:1', new UniqueTokenIds()], 'tokens.*.attributes' => Rule::forEach(function ($value, $attribute) use ($args) { if (empty($value)) { diff --git a/src/GraphQL/Mutations/DeleteBeamMutation.php b/src/GraphQL/Mutations/DeleteBeamMutation.php index cda0c58..dba7961 100644 --- a/src/GraphQL/Mutations/DeleteBeamMutation.php +++ b/src/GraphQL/Mutations/DeleteBeamMutation.php @@ -3,6 +3,7 @@ namespace Enjin\Platform\Beam\GraphQL\Mutations; use Closure; +use Enjin\Platform\Beam\Rules\BeamExists; use Enjin\Platform\Beam\Services\BeamService; use GraphQL\Type\Definition\ResolveInfo; use GraphQL\Type\Definition\Type; @@ -68,7 +69,11 @@ public function resolve( protected function rules(array $args = []): array { return [ - 'code' => ['filled', 'max:1024', 'exists:beams,code,deleted_at,NULL'], + 'code' => [ + 'filled', + 'max:1024', + new BeamExists(), + ], ]; } } diff --git a/src/GraphQL/Mutations/RemoveTokensMutation.php b/src/GraphQL/Mutations/RemoveTokensMutation.php index 2889494..9d7df97 100644 --- a/src/GraphQL/Mutations/RemoveTokensMutation.php +++ b/src/GraphQL/Mutations/RemoveTokensMutation.php @@ -3,6 +3,7 @@ namespace Enjin\Platform\Beam\GraphQL\Mutations; use Closure; +use Enjin\Platform\Beam\Rules\BeamExists; use Enjin\Platform\Beam\Rules\TokensExistInBeam; use Enjin\Platform\Beam\Services\BeamService; use GraphQL\Type\Definition\ResolveInfo; @@ -68,7 +69,11 @@ public function resolve( protected function rules(array $args = []): array { return [ - 'code' => ['filled', 'max:1024', 'exists:beams,code,deleted_at,NULL'], + 'code' => [ + 'filled', + 'max:1024', + new BeamExists(), + ], 'tokenIds' => [ 'array', 'min:1', diff --git a/src/Rules/BeamExists.php b/src/Rules/BeamExists.php new file mode 100644 index 0000000..07d6289 --- /dev/null +++ b/src/Rules/BeamExists.php @@ -0,0 +1,26 @@ +column => $value])->exists()) { + $fail('validation.exists')->translate(); + } + } +}