mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
New method for consistent data collection.
This commit is contained in:
parent
cbe046ba07
commit
35c9367819
@ -49,7 +49,8 @@ class PiggyBankUpdateRequest extends FormRequest
|
||||
// TODO this should be the way to collect fields for all API things.
|
||||
// TODO make sure piggy bank uses 'start_date' etc. until right up to DB update.
|
||||
// TODO can we configure this and return it from config?
|
||||
$return = [];
|
||||
|
||||
// TODO this is the way.
|
||||
$fields = [
|
||||
'name' => ['name', 'string'],
|
||||
'account_id' => ['account_id', 'integer'],
|
||||
@ -62,14 +63,7 @@ class PiggyBankUpdateRequest extends FormRequest
|
||||
'object_group' => ['object_group', 'string'],
|
||||
'object_group_id' => ['object_group_id', 'integer'],
|
||||
];
|
||||
foreach ($fields as $field => $info) {
|
||||
if ($this->has($info[0])) {
|
||||
$method = $info[1];
|
||||
$return[$field] = $this->$method($info[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
return $this->getAllData($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,12 +42,23 @@ class CreateRequest extends FormRequest
|
||||
$responses = array_flip(config('firefly.webhooks.responses'));
|
||||
$deliveries = array_flip(config('firefly.webhooks.deliveries'));
|
||||
|
||||
$fields = [
|
||||
'active' => ['active', 'boolean'],
|
||||
'trigger' => ['trigger', 'string'],
|
||||
'response' => ['response', 'string'],
|
||||
'delivery' => ['delivery', 'string'],
|
||||
'url' => ['url', 'string'],
|
||||
];
|
||||
|
||||
// this is the way.
|
||||
$return = $this->getAllData($fields);
|
||||
|
||||
return [
|
||||
'active' => $this->boolean('active'),
|
||||
'trigger' => $triggers[$this->string('trigger')] ?? 0,
|
||||
'response' => $responses[$this->string('response')] ?? 0,
|
||||
'delivery' => $deliveries[$this->string('delivery')] ?? 0,
|
||||
'url' => $this->string('url'),
|
||||
'active' => $return['active'],
|
||||
'trigger' => $triggers[$return['trigger']] ?? 0,
|
||||
'response' => $responses[$return['response']] ?? 0,
|
||||
'delivery' => $deliveries[$return['delivery']] ?? 0,
|
||||
'url' => $return['url'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,23 @@ class UpdateRequest extends FormRequest
|
||||
$responses = array_flip(config('firefly.webhooks.responses'));
|
||||
$deliveries = array_flip(config('firefly.webhooks.deliveries'));
|
||||
|
||||
$fields = [
|
||||
'active' => ['active', 'boolean'],
|
||||
'trigger' => ['trigger', 'string'],
|
||||
'response' => ['response', 'string'],
|
||||
'delivery' => ['delivery', 'string'],
|
||||
'url' => ['url', 'string'],
|
||||
];
|
||||
|
||||
// this is the way.
|
||||
$return = $this->getAllData($fields);
|
||||
|
||||
return [
|
||||
'active' => $this->boolean('active'),
|
||||
'trigger' => $triggers[$this->string('trigger')] ?? 0,
|
||||
'response' => $responses[$this->string('response')] ?? 0,
|
||||
'delivery' => $deliveries[$this->string('delivery')] ?? 0,
|
||||
'url' => $this->string('url'),
|
||||
'active' => $return['active'],
|
||||
'trigger' => $triggers[$return['trigger']] ?? 0,
|
||||
'response' => $responses[$return['response']] ?? 0,
|
||||
'delivery' => $deliveries[$return['delivery']] ?? 0,
|
||||
'url' => $return['url'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,27 @@ use Log;
|
||||
trait ConvertsDataTypes
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns all data in the request, or omits the field if not set,
|
||||
* according to the config from the request. This is the way.
|
||||
*
|
||||
* @param array $fields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllData(array $fields): array
|
||||
{
|
||||
$return = [];
|
||||
foreach ($fields as $field => $info) {
|
||||
if ($this->has($info[0])) {
|
||||
$method = $info[1];
|
||||
$return[$field] = $this->$method($info[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return date or NULL.
|
||||
*
|
||||
@ -142,7 +163,7 @@ trait ConvertsDataTypes
|
||||
|
||||
return null;
|
||||
}
|
||||
Log::debug(sprintf('Date object: %s (%s)',$carbon->toW3cString() , $carbon->getTimezone()));
|
||||
Log::debug(sprintf('Date object: %s (%s)', $carbon->toW3cString(), $carbon->getTimezone()));
|
||||
|
||||
return $carbon;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user