*/ public function schema(JsonSchema $schema): array { return [ 'transaction_id' => $schema->string()->description('Id of the manually-created transaction to delete.')->required(), 'update_balance' => $schema->boolean()->description('When true, reverse this transaction from the account balance snapshots. Ignored on connected accounts, whose balances come from the bank. Default false.'), 'space' => $schema->string()->description('Space id. Defaults to the personal space.'), ]; } protected function write(Request $request, User $user): Response { $space = $this->resolveSpace($request, $user); $transaction = $this->transactionInSpace($request, $space); if ($transaction->source !== TransactionSource::ManuallyCreated) { return Response::error('Only manually-created transactions can be deleted. This one came from a bank or import.'); } $balanceUpdated = $request->boolean('update_balance') && app(ManualBalanceAdjuster::class)->reverseDeletedTransaction($transaction); $transaction->delete(); return $this->json([ 'deleted' => true, 'id' => $transaction->id, 'balance_updated' => $balanceUpdated, ]); } }