Skip to content

Commit

Permalink
fix: remove useless function
Browse files Browse the repository at this point in the history
fix: machine action promise chain
refactor: pull up machine address formatter
  • Loading branch information
chaotixkilla committed Jan 30, 2023
1 parent 56de186 commit 8d551e7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
5 changes: 1 addition & 4 deletions lib/machine-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,6 @@ function setMachine (rec, operatorId) {
}
}

function testLocation (rec) {
console.log(rec)
}

function updateNetworkPerformance (deviceId, data) {
if (_.isEmpty(data)) return Promise.resolve(true)
const downloadSpeed = _.head(data)
Expand Down Expand Up @@ -312,6 +308,7 @@ function createMachineLocation ({ id, label, addressLine1, addressLine2, zipCode
const sql2 = `UPDATE devices SET machine_location = $1 WHERE device_id = $2`
return db.none(sql, [_id, label, addressLine1, addressLine2, zipCode, country])
.then(() => _.isNil(deviceId) ? Promise.resolve() : db.none(sql2, [_id, deviceId]))
.then(() => _id)
}

function deleteMachineLocation (id) {
Expand Down
2 changes: 1 addition & 1 deletion lib/new-admin/graphql/resolvers/pairing.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const machine = require('../../../machine-loader')
const resolvers = {
Mutation: {
createPairingTotem: (parent, { name, location }, { res }, info) => machine.createMachineLocation(location)
.then(() => pairing.totem(name, res.locals.operatorId, location))
.then(locationId => pairing.totem(name, res.locals.operatorId, locationId))
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/new-admin/services/machines.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function machineAction ({ deviceId, action, cashbox, cassette1, cassette2, casse
if (!machine) throw new UserInputError(`machine:${deviceId} not found`, { deviceId })
return machine
})
.then(machineLoader.setMachine({ deviceId, action, cashbox, cassettes: [cassette1, cassette2, cassette3, cassette4], newName, location }, operatorId))
.then(getMachine(deviceId))
.then(() => machineLoader.setMachine({ deviceId, action, cashbox, cassettes: [cassette1, cassette2, cassette3, cassette4], newName, location }, operatorId))
.then(() => getMachine(deviceId))
}

module.exports = { machineAction }
4 changes: 2 additions & 2 deletions lib/new-admin/services/pairing.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const encodeTotem = _.flow(
csexp.toCanonical,
)

function totem (name, operatorId, location) {
function totem (name, operatorId, locationId) {
return readFile(CA_PATH)
.then(data => {
const caHash = crypto.createHash('sha256').update(data).digest('hex')
Expand All @@ -35,7 +35,7 @@ function totem (name, operatorId, location) {
const caHexToken = crypto.createHash('sha256').update(hexToken).digest('hex')
const sql = 'insert into pairing_tokens (token, name, machine_location) values ($1, $3, $4), ($2, $3, $4)'

return db.none(sql, [hexToken, caHexToken, name, location.id])
return db.none(sql, [hexToken, caHexToken, name, locationId])
.then(() => encodeTotem({
version: PAIRING_VERSION,
hostname: HOSTNAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const useStyles = makeStyles(styles)
const Overview = ({ data, onActionSuccess }) => {
const classes = useStyles()

const getAddressString = location => {
return `${location.addressLine1}${
location.addressLine2 ? `, ${location.addressLine2}` : ``
}, ${location.zipCode}, ${location.country}`
}

return (
<div className={classes.contentContainer}>
<div className={classes.overviewRow}>
Expand All @@ -26,13 +32,7 @@ const Overview = ({ data, onActionSuccess }) => {
{!R.isNil(data.location) && (
<div>
<Label1 noMargin>Address</Label1>
<P noMargin>
{`${data.location.addressLine1}${
data.location.addressLine2
? `, ${data.location.addressLine2}`
: ``
}, ${data.location.zipCode}, ${data.location.country}`}
</P>
<P noMargin>{getAddressString(data.location)}</P>
</div>
)}
</div>
Expand Down

0 comments on commit 8d551e7

Please sign in to comment.