chore: separate queries
This commit is contained in:
parent
39633e93a9
commit
eb835b401c
1 changed files with 19 additions and 15 deletions
|
|
@ -19,21 +19,25 @@ function pullToken (token) {
|
||||||
|
|
||||||
// TODO new-admin: We should remove all configs related to that device. This can get tricky.
|
// TODO new-admin: We should remove all configs related to that device. This can get tricky.
|
||||||
function unpair (deviceId) {
|
function unpair (deviceId) {
|
||||||
const sql = `INSERT INTO
|
return db.tx(t =>
|
||||||
unpaired_devices(id, device_id, name, model, paired, unpaired)
|
t.none(`INSERT INTO
|
||||||
VALUES (
|
unpaired_devices(id, device_id, name, model, paired, unpaired)
|
||||||
$1,
|
VALUES (
|
||||||
$2,
|
$1,
|
||||||
(SELECT name FROM devices WHERE device_id=$2),
|
$2,
|
||||||
(SELECT model FROM devices WHERE device_id=$2),
|
(SELECT name FROM devices WHERE device_id=$2),
|
||||||
(SELECT created FROM devices WHERE device_id=$2),
|
(SELECT model FROM devices WHERE device_id=$2),
|
||||||
now());
|
(SELECT created FROM devices WHERE device_id=$2),
|
||||||
DELETE FROM devices WHERE device_id=$2;
|
now()
|
||||||
DELETE FROM machine_pings WHERE device_id=$2;
|
)`, [uuid.v4(), deviceId])
|
||||||
DELETE FROM machine_network_heartbeat WHERE device_id=$2;
|
.then(() => {
|
||||||
DELETE FROM machine_network_performance WHERE device_id=$2;`
|
const q1 = t.none(`DELETE FROM devices WHERE device_id=$1`, [deviceId])
|
||||||
|
const q2 = t.none(`DELETE FROM machine_pings WHERE device_id=$1`, [deviceId])
|
||||||
return db.tx(t => t.none(sql, [uuid.v4(), deviceId]))
|
const q3 = t.none(`DELETE FROM machine_network_heartbeat WHERE device_id=$1`, [deviceId])
|
||||||
|
const q4 = t.none(`DELETE FROM machine_network_performance WHERE device_id=$1`, [deviceId])
|
||||||
|
return Promise.all([q1, q2, q3, q4])
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function pair (token, deviceId, machineModel, numOfCassettes = DEFAULT_NUMBER_OF_CASSETTES) {
|
function pair (token, deviceId, machineModel, numOfCassettes = DEFAULT_NUMBER_OF_CASSETTES) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue