refactor: move pairing.js:isPaired() to machine-loader.js:getPairedMachineName()
This commit is contained in:
parent
22b6b64fe4
commit
49080b0412
3 changed files with 11 additions and 13 deletions
|
|
@ -173,6 +173,13 @@ function getMachineName(machineId) {
|
|||
return db.oneOrNone(sql, [machineId]).then(it => it?.name)
|
||||
}
|
||||
|
||||
const getPairedMachineName = deviceId =>
|
||||
db.oneOrNone(
|
||||
'SELECT name FROM devices WHERE device_id = $1 AND paired = TRUE',
|
||||
[deviceId],
|
||||
machine => machine?.name,
|
||||
)
|
||||
|
||||
function getMachine(machineId, config) {
|
||||
const sql = `${MACHINE_WITH_CALCULATED_FIELD_SQL} WHERE d.device_id = $1`
|
||||
|
||||
|
|
@ -750,6 +757,7 @@ const batchRecordPendingPings = () => {
|
|||
|
||||
module.exports = {
|
||||
getMachineName,
|
||||
getPairedMachineName,
|
||||
getMachines,
|
||||
getUnpairedMachines,
|
||||
getMachine,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
const pairing = require('../pairing')
|
||||
const { getPairedMachineName } = require('../machine-loader')
|
||||
const logger = require('../logger')
|
||||
|
||||
const authorize = function (req, res, next) {
|
||||
return pairing
|
||||
.isPaired(req.deviceId)
|
||||
return getPairedMachineName(req.deviceId)
|
||||
.then(deviceName => {
|
||||
if (deviceName) {
|
||||
req.deviceName = deviceName
|
||||
|
|
|
|||
|
|
@ -81,13 +81,4 @@ function authorizeCaDownload(caToken) {
|
|||
})
|
||||
}
|
||||
|
||||
function isPaired(deviceId) {
|
||||
const sql =
|
||||
'select device_id, name from devices where device_id=$1 and paired=TRUE'
|
||||
|
||||
return db
|
||||
.oneOrNone(sql, [deviceId])
|
||||
.then(row => (row && row.device_id === deviceId ? row.name : false))
|
||||
}
|
||||
|
||||
module.exports = { pair, unpair, authorizeCaDownload, isPaired }
|
||||
module.exports = { pair, unpair, authorizeCaDownload }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue