cleanup, patterns
This commit is contained in:
@@ -1,14 +1,8 @@
|
||||
import { bind, ok, tap, tapError, pipe } from '../library/result.js';
|
||||
import { output, outputError } from '../library/logging.js';
|
||||
import { bind, ok, pipe } from '../library/result.js';
|
||||
import { log, logWith, formatMoney } from '../library/logging.js';
|
||||
import { withdraw } from '../domain/account.js';
|
||||
import { createMoney } from '../domain/money.js';
|
||||
|
||||
const log = (src, msg) => (result) =>
|
||||
tap((x) => output(src, msg)(x))(tapError((e) => outputError(src, e))(result));
|
||||
|
||||
const logWith = (src, renderText) => (result) =>
|
||||
tap((x) => output(src, renderText(x))(x))(tapError((e) => outputError(src, e))(result));
|
||||
|
||||
export const createWithdrawMoney = (repo) =>
|
||||
ok((accountId, amount) =>
|
||||
pipe(
|
||||
@@ -16,7 +10,7 @@ export const createWithdrawMoney = (repo) =>
|
||||
log('App load', 'Account loaded'),
|
||||
log('App exec wdrwl', `[App] Executing withdrawal of ${amount.toFixed(2)}...`),
|
||||
bind((account) => withdraw(account, createMoney(amount))),
|
||||
logWith('App wdrwl done', (a) => `Withdrawal applied. New balance: ${a.balance.amount.toFixed(2)}`),
|
||||
logWith('App wdrwl done', (a) => `Withdrawal applied. New balance: ${formatMoney(a.balance)}`),
|
||||
bind(repo.saveAccount),
|
||||
log('App acc svd', '[App] Account persisted.')
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user