Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
accountIdsByAccessId(newState, account.accessId).length === 0
? removeAccess(newState, account.accessId)
: newState;
// Reset the defaultAccountId if we just deleted it.
if (getDefaultAccountId(newState) === accountId) {
newState = u({ defaultAccountId: DefaultSettings.get('default-account-id') }, newState);
}
// Reset the current account id if we just deleted it.
if (getCurrentAccountId(newState) === accountId) {
newState = setCurrentAccessAndAccount(newState);
}
// Remove alerts attached to the account.
newState = u.updateIn('alerts', u.reject(alert => alert.accountId === accountId), newState);
// Finally, remove the account from the accounts map.
return updateAccountsMap(newState, u.omit(accountId));
}
function removeAccount(state, accountId) {
assert(
typeof accountId === 'number',
'second parameter of removeAccount should be a number id'
);
let account = accountById(state, accountId);
// First remove the attached operations from the operation map.
let newState = updateOperationsMap(state, u.omit(account.operationIds));
// Then remove the account from the access.
newState = updateAccessFields(newState, account.accessId, {
accountIds: u.reject(id => id === accountId)
});
// Remove access if no more accounts in the access.
newState =
accountIdsByAccessId(newState, account.accessId).length === 0
? removeAccess(newState, account.accessId)
: newState;
// Reset the defaultAccountId if we just deleted it.
if (getDefaultAccountId(newState) === accountId) {
newState = u({ defaultAccountId: DefaultSettings.get('default-account-id') }, newState);
}
// Reset the current account id if we just deleted it.
if (getCurrentAccountId(newState) === accountId) {
newState = setCurrentAccessAndAccount(newState);
);
let op = operationById(state, operationId);
let account = accountById(state, op.accountId);
let { balance, outstandingSum } = account;
let today = moment();
if (shouldIncludeInBalance(op, today, account.type)) {
balance -= op.amount;
} else if (shouldIncludeInOutstandingSum(op)) {
outstandingSum -= op.amount;
}
let newState = updateAccountFields(state, account.id, {
operationIds: u.reject(id => id === operationId),
balance,
outstandingSum
});
return updateOperationsMap(newState, u.omit(`${operationId}`));
}
function reduceDelete(state, action) {
let { status } = action;
if (status === SUCCESS) {
let id = action.id;
return u(
{
items: u.reject(c => c.id === id),
map: u.omit(id)
},
state
);
}
return state;
}
removeFlake: flakeId => edit(u({flakes: u.reject(flakeHasId(flakeId)) })),
explodeFlake: index => edit(u({flakes: { [index]: { explode: true } } })),