Prettified Code!

This commit is contained in:
daniep01
2022-02-26 10:41:40 +00:00
committed by GitHub Action
parent 88d3c3fd2d
commit 7370132af2

View File

@@ -44,7 +44,6 @@ instance.prototype.auth = function () {
self.header['Authorization'] = 'Basic ' + auth self.header['Authorization'] = 'Basic ' + auth
console.log(self.header) console.log(self.header)
} }
instance.prototype.config_fields = function () { instance.prototype.config_fields = function () {
@@ -92,7 +91,7 @@ instance.prototype.init_presets = function () {
action: 'startNewTimer', action: 'startNewTimer',
options: { options: {
description: '', description: '',
} },
}, },
], ],
}) })
@@ -165,7 +164,7 @@ instance.prototype.action = function (action) {
var cmd = 'https://api.track.toggl.com/api/v8/time_entries/' + self.currentTimer + '/stop' var cmd = 'https://api.track.toggl.com/api/v8/time_entries/' + self.currentTimer + '/stop'
console.log(cmd) console.log(cmd)
} else { } else {
self.log('warn','No running timer to stop or running timer ID unknown') self.log('warn', 'No running timer to stop or running timer ID unknown')
return return
} }
break break
@@ -180,14 +179,17 @@ instance.prototype.action = function (action) {
break break
} }
self.system.emit(restCmd, cmd, body, function (err, result) { self.system.emit(
restCmd,
cmd,
body,
function (err, result) {
if (err !== null) { if (err !== null) {
console.log(result.statusCode) console.log(result.statusCode)
console.log('HTTP Request failed (' + result.error.code + ')') console.log('HTTP Request failed (' + result.error.code + ')')
self.status(self.STATUS_ERROR, result.error.code); self.status(self.STATUS_ERROR, result.error.code)
} else { } else {
console.log(typeof(result.data)) console.log(typeof result.data)
console.log(result.statusCode) console.log(result.statusCode)
if (!self.auth_error) { if (!self.auth_error) {
self.status(self.STATUS_OK) self.status(self.STATUS_OK)
@@ -198,19 +200,23 @@ instance.prototype.action = function (action) {
} else { } else {
self.currentTimer = null self.currentTimer = null
console.log(result.data) console.log(result.data)
self.log('debug',result.data) self.log('debug', result.data)
} }
} }
} }
}, self.header) },
self.header
)
} }
instance.prototype.getCurrentTimer = function () { instance.prototype.getCurrentTimer = function () {
var self = this var self = this
var cmd = 'https://api.track.toggl.com/api/v8/time_entries/current' var cmd = 'https://api.track.toggl.com/api/v8/time_entries/current'
self.system.emit('rest_get', cmd, function (err, result) { self.system.emit(
'rest_get',
cmd,
function (err, result) {
if (err !== null) { if (err !== null) {
console.log('HTTP Request failed (' + result.error.code + ')') console.log('HTTP Request failed (' + result.error.code + ')')
self.status(self.STATUS_ERROR, result.error.code) self.status(self.STATUS_ERROR, result.error.code)
@@ -221,31 +227,33 @@ instance.prototype.getCurrentTimer = function () {
if ('id' in result.data.data) { if ('id' in result.data.data) {
self.currentTimer = result.data.data.id self.currentTimer = result.data.data.id
console.log(self.currentTimer) console.log(self.currentTimer)
self.log('debug','Current timer id ' + self.currentTimer) self.log('debug', 'Current timer id ' + self.currentTimer)
} }
} else { } else {
console.log(result.data) console.log(result.data)
self.log('debug','No timer running') self.log('debug', 'No timer running')
self.currentTimer = null self.currentTimer = null
} }
} else { } else {
console.log('error: ' + result.response.statusCode) console.log('error: ' + result.response.statusCode)
self.status(self.STATUS_ERROR, result.response.statusCode) self.status(self.STATUS_ERROR, result.response.statusCode)
self.log('warn','Unable to connect to toggl, check your API token is correct') self.log('warn', 'Unable to connect to toggl, check your API token is correct')
self.currentTimer = null self.currentTimer = null
} }
}, self.header) },
self.header
)
} }
instance.prototype.interpretData = function (data) { instance.prototype.interpretData = function (data) {
var self = this; var self = this
console.log(data) console.log(data)
if ('id' in data) { if ('id' in data) {
console.log(data.id) console.log(data.id)
self.currentTimer = data.id self.currentTimer = data.id
self.log('debug','timer id ' + data.id) self.log('debug', 'timer id ' + data.id)
} }
} }