refactor: deduplicate cash unit object creation

This commit is contained in:
siiky 2023-10-19 20:14:49 +01:00
parent 277335fea4
commit d8a4f89194

View file

@ -52,25 +52,14 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
const title = `Update counts` const title = `Update counts`
const isLastStep = step === LAST_STEP const isLastStep = step === LAST_STEP
const buildCassetteObj = cassetteInput => { const buildCashUnitObj = (fields, cassetteInput) => {
return R.reduce( return R.reduce(
(acc, value) => { (acc, value) => {
acc[value] = defaultToZero(cassetteInput[value]) acc[value] = defaultToZero(cassetteInput[value])
return acc return acc
}, },
{}, {},
CASSETTE_FIELDS fields
)
}
const buildRecyclerObj = cassetteInput => {
return R.reduce(
(acc, value) => {
acc[value] = defaultToZero(cassetteInput[value])
return acc
},
{},
RECYCLER_FIELDS
) )
} }
@ -82,8 +71,8 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
it?.wasCashboxEmptied it?.wasCashboxEmptied
].includes('YES') ].includes('YES')
const cassettes = buildCassetteObj(it) const cassettes = buildCashUnitObj(CASSETTE_FIELDS, it)
const recyclers = buildRecyclerObj(it) const recyclers = buildCashUnitObj(RECYCLER_FIELDS, it)
const cashUnits = { const cashUnits = {
cashbox: wasCashboxEmptied ? 0 : machine?.cashUnits.cashbox, cashbox: wasCashboxEmptied ? 0 : machine?.cashUnits.cashbox,