Skip to content

Commit

Permalink
Fix rule set params (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner authored Aug 10, 2023
1 parent 80e055d commit 5c14efc
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 73 deletions.
4 changes: 2 additions & 2 deletions src/GraphQL/Mutations/InsertRuleSetMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function args(): array
'description' => __('enjin-platform-fuel-tanks::mutation.schedule_mutate_freeze_state.args.ruleSetId'),
],
'dispatchRules' => [
'type' => GraphQL::type('[DispatchRuleInputType!]'),
'type' => GraphQL::type('DispatchRuleInputType!'),
'description' => __('enjin-platform-fuel-tanks::input_type.dispatch_rule.description'),
],
...$this->getIdempotencyField(),
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function rules(array $args = []): array
new MaxBigInt(Hex::MAX_UINT32),
new RuleSetNotExists(),
],
...$this->dispatchRules($args),
...$this->dispatchRules($args, '', false),
];
}
}
16 changes: 9 additions & 7 deletions src/GraphQL/Traits/HasFuelTankValidationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,30 @@ protected function validationRules(array $args = [], array $except = [], string
/**
* Get the dispatch rules validation rules.
*/
protected function dispatchRules(array $args = [], string $attributePrefix = ''): array
protected function dispatchRules(array $args = [], string $attributePrefix = '', $isArray = true): array
{
$array = $isArray ? '.*' : '';

return [
...$this->commonRules("{$attributePrefix}dispatchRules.*", $args),
"{$attributePrefix}dispatchRules.*.whitelistedCollections.*" => [
...$this->commonRules("{$attributePrefix}dispatchRules{$array}", $args),
"{$attributePrefix}dispatchRules{$array}.whitelistedCollections.*" => [
'bail',
'distinct',
'max:255',
Rule::exists('collections', 'collection_chain_id'),
],
"{$attributePrefix}dispatchRules.*.whitelistedCollections" => [
"{$attributePrefix}dispatchRules{$array}.whitelistedCollections" => [
'nullable',
'array',
'min:1',
],
"{$attributePrefix}dispatchRules.*.maxFuelBurnPerTransaction" => [
"{$attributePrefix}dispatchRules{$array}.maxFuelBurnPerTransaction" => [
'bail',
new MinBigInt(),
new MaxBigInt(Hex::MAX_UINT128),
],
...$this->commonRules("{$attributePrefix}dispatchRules.*.userFuelBudget"),
...$this->commonRules("{$attributePrefix}dispatchRules.*.tankFuelBudget"),
...$this->commonRules("{$attributePrefix}dispatchRules{$array}.userFuelBudget"),
...$this->commonRules("{$attributePrefix}dispatchRules{$array}.tankFuelBudget"),
];
}
}
2 changes: 1 addition & 1 deletion src/Services/TransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function insertRuleSet(array $args): Model
'encoded_data' => $this->codec->encode()->insertRuleSet(
$account,
Arr::get($args, 'ruleSetId'),
$this->setDispatchRulesParams($args)
$this->setDispatchRulesParams(Arr::get($args, 'dispatchRules', [])),
),
'method' => 'InsertRuleSet',
]);
Expand Down
Loading

0 comments on commit 5c14efc

Please sign in to comment.