feat: add support for more than two cassettes
This commit is contained in:
parent
478af0fad0
commit
5788b6216d
13 changed files with 279 additions and 50 deletions
39
migrations/1630432869178-add-more-cassette-support.js
Normal file
39
migrations/1630432869178-add-more-cassette-support.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
var db = require('./db')
|
||||
const _ = require('lodash/fp')
|
||||
const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
|
||||
const { getMachines } = require('../lib/machine-loader')
|
||||
|
||||
exports.up = function (next) {
|
||||
var sql = [
|
||||
'ALTER TABLE devices ADD COLUMN cassette3 INTEGER NOT NULL DEFAULT 0',
|
||||
'ALTER TABLE devices ADD COLUMN cassette4 INTEGER NOT NULL DEFAULT 0',
|
||||
'ALTER TABLE cash_out_txs ADD COLUMN provisioned_3 INTEGER',
|
||||
'ALTER TABLE cash_out_txs ADD COLUMN provisioned_4 INTEGER',
|
||||
'ALTER TABLE cash_out_txs ADD COLUMN denomination_3 INTEGER',
|
||||
'ALTER TABLE cash_out_txs ADD COLUMN denomination_4 INTEGER'
|
||||
]
|
||||
|
||||
return Promise.all([loadLatest(), getMachines()])
|
||||
.then(([config, machines]) => {
|
||||
const formattedMachines = _.map(it => _.pick(['deviceId'], it), machines)
|
||||
const newConfig = _.reduce((acc, value) => {
|
||||
if(_.includes(`cashOut_${value.deviceId}_top`, _.keys(config.config))) {
|
||||
acc[`cashOut_${value.deviceId}_cassette1`] = config.config[`cashOut_${value.deviceId}_top`]
|
||||
}
|
||||
|
||||
if(_.includes(`cashOut_${value.deviceId}_bottom`, _.keys(config.config))) {
|
||||
acc[`cashOut_${value.deviceId}_cassette2`] = config.config[`cashOut_${value.deviceId}_bottom`]
|
||||
}
|
||||
|
||||
return acc
|
||||
}, {}, formattedMachines)
|
||||
|
||||
return saveConfig(newConfig)
|
||||
.then(() => db.multi(sql, next))
|
||||
.catch(err => next(err))
|
||||
})
|
||||
}
|
||||
|
||||
exports.down = function (next) {
|
||||
next()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue