33const query = require ( '../services/db.js' ) ;
44
55class Device {
6- constructor ( uuid , model , config , lastSeen , clientip , iosVersion , ipaVersion , webserverPort = 8080 , notes = null , enabled = false ) {
6+ constructor ( uuid , model , config , lastSeen , clientip , iosVersion , ipaVersion , webserverPort = 8080 , notes = null , excludeReboots = false , enabled = false ) {
77 this . uuid = uuid ;
88 this . model = model ;
99 this . config = config ;
@@ -13,40 +13,47 @@ class Device {
1313 this . ipaVersion = ipaVersion ;
1414 this . webserverPort = webserverPort || 8080 ;
1515 this . notes = notes ;
16+ this . excludeReboots = excludeReboots ;
1617 this . enabled = enabled ;
1718 }
1819 static async getAll ( ) {
19- const devices = await query ( 'SELECT uuid, model, config, last_seen, clientip, ios_version, ipa_version, webserver_port, notes, enabled FROM devices' ) ;
20+ const sql = `
21+ SELECT uuid, model, config, last_seen, clientip, ios_version, ipa_version, webserver_port, notes, exclude_reboots, enabled
22+ FROM devices
23+ ` ;
24+ const devices = await query ( sql ) ;
2025 return devices ;
2126 }
2227 static async getByName ( uuid ) {
2328 const sql = `
24- SELECT uuid, model, config, last_seen, clientip, ios_version, ipa_version, notes, enabled
29+ SELECT uuid, model, config, last_seen, clientip, ios_version, ipa_version, webserver_port, notes, exclude_reboots , enabled
2530 FROM devices
2631 WHERE uuid = ?` ;
2732 const args = [ uuid ] ;
28- const result = await query ( sql , args ) ;
29- if ( result . length === 0 ) {
33+ const results = await query ( sql , args ) ;
34+ if ( results . length === 0 ) {
3035 return null ;
3136 }
37+ const result = results [ 0 ] ;
3238 return new Device (
33- result [ 0 ] . uuid ,
34- result [ 0 ] . model ,
35- result [ 0 ] . config ,
36- result [ 0 ] . last_seen ,
37- result [ 0 ] . clientip ,
38- result [ 0 ] . ios_version ,
39- result [ 0 ] . ipa_version ,
40- result [ 0 ] . webserverPort ,
41- result [ 0 ] . notes ,
42- result [ 0 ] . enabled
39+ result . uuid ,
40+ result . model ,
41+ result . config ,
42+ result . last_seen ,
43+ result . clientip ,
44+ result . ios_version ,
45+ result . ipa_version ,
46+ result . webserver_port ,
47+ result . notes ,
48+ result . exclude_reboots ,
49+ result . enabled
4350 ) ;
4451 }
45- static async create ( uuid , model = null , config = null , lastSeen = null , clientip = null , iosVersion = null , ipaVersion = null , webserverPort = 8080 , notes = null , enabled = true ) {
52+ static async create ( uuid , model = null , config = null , lastSeen = null , clientip = null , iosVersion = null , ipaVersion = null , webserverPort = 8080 , notes = null , excludeReboots = false , enabled = true ) {
4653 const sql = `
47- INSERT INTO devices (uuid, model, config, last_seen, clientip, ios_version, ipa_version, webserver_port, notes, enabled)
48- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` ;
49- const args = [ uuid , model , config , lastSeen , clientip , iosVersion , ipaVersion , webserverPort , notes , enabled ] ;
54+ INSERT INTO devices (uuid, model, config, last_seen, clientip, ios_version, ipa_version, webserver_port, notes, exclude_reboots, enabled)
55+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )` ;
56+ const args = [ uuid , model , config , lastSeen , clientip , iosVersion , ipaVersion , webserverPort , notes , excludeReboots , enabled ] ;
5057 const result = await query ( sql , args ) ;
5158 if ( result . affectedRows === 1 ) {
5259 return new Device (
@@ -59,6 +66,7 @@ class Device {
5966 ipaVersion ,
6067 webserverPort ,
6168 notes ,
69+ excludeReboots ,
6270 enabled
6371 ) ;
6472 }
@@ -78,9 +86,9 @@ class Device {
7886 async save ( ) {
7987 const sql = `
8088 UPDATE devices
81- SET model = ?, config = ?, last_seen = ?, clientip = ?, ios_version = ?, ipa_version = ?, webserver_port = ?, notes = ?, enabled = ?
89+ SET model = ?, config = ?, last_seen = ?, clientip = ?, ios_version = ?, ipa_version = ?, webserver_port = ?, notes = ?, exclude_reboots = ?, enabled = ?
8290 WHERE uuid = ?` ;
83- const args = [ this . model , this . config , this . lastSeen , this . clientip , this . iosVersion , this . ipaVersion , this . webserverPort , this . notes , this . enabled , this . uuid ] ;
91+ const args = [ this . model , this . config , this . lastSeen , this . clientip , this . iosVersion , this . ipaVersion , this . webserverPort , this . notes , this . excludeReboots , this . enabled , this . uuid ] ;
8492 const result = await query ( sql , args ) ;
8593 return result . affectedRows === 1 ;
8694 }
0 commit comments