Is now capable of updating transactions over the API.

This commit is contained in:
James Cole
2019-04-06 08:10:50 +02:00
parent b692cccdfb
commit c519b4d0df
36 changed files with 1840 additions and 709 deletions

View File

@@ -53,10 +53,12 @@ class TransactionJournalMetaFactory
*/
public function updateOrCreate(array $data): ?TransactionJournalMeta
{
Log::debug('In updateOrCreate()');
$value = $data['data'];
/** @var TransactionJournalMeta $entry */
$entry = $data['journal']->transactionJournalMeta()->where('name', $data['name'])->first();
if (null === $value && null !== $entry) {
Log::debug('Value is empty, delete meta value.');
try {
$entry->delete();
} catch (Exception $e) { // @codeCoverageIgnore
@@ -67,11 +69,14 @@ class TransactionJournalMetaFactory
}
if ($data['data'] instanceof Carbon) {
Log::debug('Is a carbon object.');
$value = $data['data']->toW3cString();
}
if ('' === (string)$value) {
Log::debug('Is an empty string.');
// don't store blank strings.
if (null !== $entry) {
Log::debug('Will not store empty strings, delete meta value');
try {
$entry->delete();
} catch (Exception $e) { // @codeCoverageIgnore
@@ -83,11 +88,13 @@ class TransactionJournalMetaFactory
}
if (null === $entry) {
Log::debug('Will create new object.');
Log::debug(sprintf('Going to create new meta-data entry to store "%s".', $data['name']));
$entry = new TransactionJournalMeta();
$entry->transactionJournal()->associate($data['journal']);
$entry->name = $data['name'];
}
Log::debug('Will update value and return.');
$entry->data = $value;
$entry->save();