Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:versx/DeviceConfigManager into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
versx committed Apr 20, 2020
2 parents e3f8d5a + 032274c commit 5f2b292
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "src/index.js",
"scripts": {
"start": "node src/index.js",
"test": "npx eslint src/**.js"
"test": "npx eslint src/**/*.js",
"test-fix": "npx eslint src/**/*.js --fix"
},
"author": "versx",
"license": "ISC",
Expand Down
22 changes: 11 additions & 11 deletions src/models/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use strict"
'use strict';

const query = require('../db.js');

class Config {
constructor(name, backendUrl, port, heartbeatMaxTime, pokemonMaxTime, raidMaxTime, startupLat, startupLon, token, jitterValue,
maxWarningTimeRaid, encounterDelay, minDelayLogout, maxEmptyGmo, maxFailedCount, maxNoQuestCount, loggingUrl,
loggingPort, loggingTls, loggingTcp, accountManager, deployEggs, nearbyTracker, autoLogin, ultraIV, ultraQuests, isDefault) {
maxWarningTimeRaid, encounterDelay, minDelayLogout, maxEmptyGmo, maxFailedCount, maxNoQuestCount, loggingUrl,
loggingPort, loggingTls, loggingTcp, accountManager, deployEggs, nearbyTracker, autoLogin, ultraIV, ultraQuests, isDefault) {
this.name = name;
this.backendUrl = backendUrl;
this.port = port;
Expand Down Expand Up @@ -35,7 +35,7 @@ class Config {
this.isDefault = isDefault;
}
static async getAll() {
var configs = await query("SELECT * FROM configs");
var configs = await query('SELECT * FROM configs');
return configs;
}
static async getByName(name) {
Expand Down Expand Up @@ -86,22 +86,22 @@ class Config {
return data;
}
static async create(name, backendUrl, port, heartbeatMaxTime, pokemonMaxTime, raidMaxTime, startupLat, startupLon, token, jitterValue,
maxWarningTimeRaid, encounterDelay, minDelayLogout, maxEmptyGmo, maxFailedCount, maxNoQuestCount, loggingUrl, loggingPort,
loggingTls, loggingTcp, accountManager, deployEggs, nearbyTracker, autoLogin, ultraIV, ultraQuests, isDefault) {
maxWarningTimeRaid, encounterDelay, minDelayLogout, maxEmptyGmo, maxFailedCount, maxNoQuestCount, loggingUrl, loggingPort,
loggingTls, loggingTcp, accountManager, deployEggs, nearbyTracker, autoLogin, ultraIV, ultraQuests, isDefault) {
var sql = `
INSERT INTO configs (name, backend_url, port, heartbeat_max_time, pokemon_max_time, raid_max_time, startup_lat, startup_lon, token, jitter_value,
max_warning_time_raid, encounter_delay, min_delay_logout, max_empty_gmo, max_failed_count, max_no_quest_count, logging_url,
logging_port, logging_tls, logging_tcp, account_manager, deploy_eggs, nearby_tracker, auto_login, ultra_iv, ultra_quests,
is_default)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
var args = [name, backendUrl, port, heartbeatMaxTime, pokemonMaxTime, raidMaxTime, startupLat, startupLon, token, jitterValue,
maxWarningTimeRaid, encounterDelay, minDelayLogout, maxEmptyGmo, maxFailedCount, maxNoQuestCount, loggingUrl, loggingPort,
loggingTls, loggingTcp, accountManager, deployEggs, nearbyTracker, autoLogin, ultraIV, ultraQuests, isDefault];
maxWarningTimeRaid, encounterDelay, minDelayLogout, maxEmptyGmo, maxFailedCount, maxNoQuestCount, loggingUrl, loggingPort,
loggingTls, loggingTcp, accountManager, deployEggs, nearbyTracker, autoLogin, ultraIV, ultraQuests, isDefault];
var result = await query(sql, args);
return result.affectedRows === 1;
}
static async delete(name) {
var sql = "DELETE FROM configs WHERE name = ?";
var sql = 'DELETE FROM configs WHERE name = ?';
var args = [name];
var result = await query(sql, args);
return result.affectedRows === 1;
Expand Down Expand Up @@ -153,13 +153,13 @@ class Config {
}
static async setDefault(name) {
// TODO: Update both in one sql statement
var sql = "UPDATE configs SET is_default = 0 WHERE name != ?";
var sql = 'UPDATE configs SET is_default = 0 WHERE name != ?';
var args = [name];
var result = await query(sql, args);
if (result.affectedRows > 0) {
// Success
}
sql = "UPDATE config SET is_default = 1 WHERE name = ?";
sql = 'UPDATE config SET is_default = 1 WHERE name = ?';
result = await query(sql, args);
return result.affectedRows === 1;
}
Expand Down
6 changes: 3 additions & 3 deletions src/models/device.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict"
'use strict';

const query = require('../db.js');

Expand All @@ -9,7 +9,7 @@ class Device {
this.lastSeen = lastSeen;
}
static async getAll() {
var devices = await query("SELECT uuid, config, last_seen FROM devices");
var devices = await query('SELECT uuid, config, last_seen FROM devices');
return devices;
}
static async getByName(uuid) {
Expand Down Expand Up @@ -37,7 +37,7 @@ class Device {
return result.affectedRows === 1;
}
static async delete(uuid) {
var sql = "DELETE FROM devices WHERE uuid = ?";
var sql = 'DELETE FROM devices WHERE uuid = ?';
var args = [uuid];
var result = await query(sql, args);
return result.affectedRows === 1;
Expand Down
2 changes: 1 addition & 1 deletion src/models/log.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict"
'use strict';

const fs = require('fs');
const path = require('path');
Expand Down

0 comments on commit 5f2b292

Please sign in to comment.