Merge pull request #1159 from siiky/fix/lam-396/cashbox-history-crash
fix: don't crash with batches of unpaired machines
This commit is contained in:
commit
729662d980
5 changed files with 38 additions and 5 deletions
|
|
@ -43,6 +43,16 @@ function getMachines () {
|
|||
.then(rr => rr.map(toMachineObject))
|
||||
}
|
||||
|
||||
function getUnpairedMachines () {
|
||||
return db.any('SELECT * FROM unpaired_devices')
|
||||
.then(_.map(r =>
|
||||
_.flow(
|
||||
_.set('deviceId', _.get('device_id', r)),
|
||||
_.unset('device_id')
|
||||
)(r)
|
||||
))
|
||||
}
|
||||
|
||||
function getConfig (defaultConfig) {
|
||||
if (defaultConfig) return Promise.resolve(defaultConfig)
|
||||
|
||||
|
|
@ -257,6 +267,7 @@ function getNetworkHeartbeatByDevice (deviceId) {
|
|||
module.exports = {
|
||||
getMachineName,
|
||||
getMachines,
|
||||
getUnpairedMachines,
|
||||
getMachine,
|
||||
getMachineNames,
|
||||
setMachine,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ const resolvers = {
|
|||
},
|
||||
Query: {
|
||||
machines: () => machineLoader.getMachineNames(),
|
||||
machine: (...[, { deviceId }]) => machineLoader.getMachine(deviceId)
|
||||
machine: (...[, { deviceId }]) => machineLoader.getMachine(deviceId),
|
||||
unpairedMachines: () => machineLoader.getUnpairedMachines()
|
||||
},
|
||||
Mutation: {
|
||||
machineAction: (...[, { deviceId, action, cashbox, cassette1, cassette2, cassette3, cassette4, newName }, context]) =>
|
||||
|
|
|
|||
|
|
@ -27,6 +27,15 @@ const typeDef = gql`
|
|||
packetLoss: String
|
||||
}
|
||||
|
||||
type UnpairedMachine {
|
||||
id: ID!
|
||||
deviceId: ID!
|
||||
name: String
|
||||
model: String
|
||||
paired: Date!
|
||||
unpaired: Date!
|
||||
}
|
||||
|
||||
type MachineEvent {
|
||||
id: ID
|
||||
deviceId: String
|
||||
|
|
@ -51,6 +60,7 @@ const typeDef = gql`
|
|||
type Query {
|
||||
machines: [Machine] @auth
|
||||
machine(deviceId: ID!): Machine @auth
|
||||
unpairedMachines: [UnpairedMachine!]! @auth
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
|
|
|
|||
|
|
@ -98,6 +98,10 @@ const GET_MACHINES_AND_CONFIG = gql`
|
|||
cassette4
|
||||
numberOfCassettes
|
||||
}
|
||||
unpairedMachines {
|
||||
id: deviceId
|
||||
name
|
||||
}
|
||||
config
|
||||
bills(filters: $billFilters) {
|
||||
id
|
||||
|
|
@ -160,6 +164,7 @@ const CashCassettes = () => {
|
|||
const [machineId, setMachineId] = useState('')
|
||||
|
||||
const machines = R.path(['machines'])(data) ?? []
|
||||
const unpairedMachines = R.path(['unpairedMachines'])(data) ?? []
|
||||
const config = R.path(['config'])(data) ?? {}
|
||||
const fillingPercentageSettings = fromNamespace('notifications', config)
|
||||
const [setCassetteBills, { error }] = useMutation(SET_CASSETTE_BILLS, {
|
||||
|
|
@ -356,7 +361,10 @@ const CashCassettes = () => {
|
|||
</>
|
||||
)}
|
||||
{showHistory && (
|
||||
<CashboxHistory machines={machines} currency={fiatCurrency} />
|
||||
<CashboxHistory
|
||||
machines={R.concat(machines, unpairedMachines)}
|
||||
currency={fiatCurrency}
|
||||
/>
|
||||
)}
|
||||
<CashCassettesFooter
|
||||
currencyCode={fiatCurrency}
|
||||
|
|
|
|||
|
|
@ -161,9 +161,12 @@ const CashboxHistory = ({ machines, currency }) => {
|
|||
header: 'Machine',
|
||||
width: 200,
|
||||
textAlign: 'left',
|
||||
view: it => {
|
||||
return R.find(R.propEq('id', it.deviceId))(machines).name
|
||||
}
|
||||
view: R.pipe(
|
||||
R.prop('deviceId'),
|
||||
id => R.find(R.propEq('id', id), machines),
|
||||
R.defaultTo({ name: <i>Unpaired device</i> }),
|
||||
R.prop('name')
|
||||
)
|
||||
},
|
||||
{
|
||||
name: 'billCount',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue