Expand API, add new migration.

This commit is contained in:
James Cole
2020-06-30 20:33:08 +02:00
parent 77e7af75dc
commit cb65999124
11 changed files with 203 additions and 4 deletions

View File

@@ -190,7 +190,10 @@ class BillRepository implements BillRepositoryInterface
public function getBills(): Collection
{
/** @var Collection $set */
return $this->user->bills()->orderBy('active', 'DESC')->orderBy('name', 'ASC')->get();
return $this->user->bills()
->orderBy('order', 'ASC')
->orderBy('active', 'DESC')
->orderBy('name', 'ASC')->get();
}
/**
@@ -711,4 +714,20 @@ class BillRepository implements BillRepositoryInterface
{
$this->user->transactionJournals()->where('bill_id', $bill->id)->update(['bill_id' => null]);
}
/**
* Correct order of piggies in case of issues.
*/
public function correctOrder(): void
{
$set = $this->user->bills()->orderBy('order', 'ASC')->get();
$current = 1;
foreach ($set as $bill) {
if ((int) $bill->order !== $current) {
$bill->order = $current;
$bill->save();
}
$current++;
}
}
}