fix: add default number of cassette server side to avoid pairing issues on older machine versions

This commit is contained in:
Sérgio Salgado 2021-10-26 15:18:36 +01:00
parent f32d02a808
commit b89f11adeb

View file

@ -5,6 +5,10 @@ const db = require('./db')
const options = require('./options') const options = require('./options')
const logger = require('./logger') const logger = require('./logger')
// A machine on an older version (no multicassette code) could be paired with a server with multicassette code.
// This makes sure that the server stores a default value
const DEFAULT_NUMBER_OF_CASSETTES = 2
function pullToken (token) { function pullToken (token) {
const sql = `delete from pairing_tokens const sql = `delete from pairing_tokens
where token=$1 where token=$1
@ -20,7 +24,7 @@ function unpair (deviceId) {
return Promise.all([db.none(sql, [deviceId]), db.none(deleteMachinePings, [deviceId])]) return Promise.all([db.none(sql, [deviceId]), db.none(deleteMachinePings, [deviceId])])
} }
function pair (token, deviceId, machineModel, numOfCassettes) { function pair (token, deviceId, machineModel, numOfCassettes = DEFAULT_NUMBER_OF_CASSETTES) {
return pullToken(token) return pullToken(token)
.then(r => { .then(r => {
if (r.expired) return false if (r.expired) return false