Skip to content

Commit

Permalink
Add prettier code formatting (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-fox authored and dcalvoalonso committed Jan 30, 2019
1 parent ef14613 commit 1f9e761
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 194 deletions.
10 changes: 5 additions & 5 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ config.iota = {
/**
* Version of NGSI
*/
ngsiVersion: 'v2'
ngsiVersion: 'v2',
},

/**
Expand All @@ -61,7 +61,7 @@ config.iota = {
/**
* Port where the IoT Agent will be listening for requests.
*/
port: 4061
port: 4061,
},

/**
Expand All @@ -81,7 +81,7 @@ config.iota = {
* from the 'mongoDb' configuration property.
*/
deviceRegistry: {
type: 'mongodb'
type: 'mongodb',
},

/**
Expand All @@ -104,7 +104,7 @@ config.iota = {
/**
* Name of the Mongo database that will be created to store IOTAgent data.
*/
db: 'iotagentlora'
db: 'iotagentlora',

/**
* Name of the set in case the Mongo database is configured as a Replica Set. Optional otherwise.
Expand Down Expand Up @@ -144,7 +144,7 @@ config.iota = {
/**
* Default type, for IOTA installations that won't require preregistration.
*/
defaultType: 'Thing'
defaultType: 'Thing',
};

module.exports = config;
10 changes: 5 additions & 5 deletions docker/config-docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ config.iota = {
/**
* Version of NGSI
*/
ngsiVersion: 'v2'
ngsiVersion: 'v2',
},

/**
Expand All @@ -61,7 +61,7 @@ config.iota = {
/**
* Port where the IoT Agent will be listening for requests.
*/
port: 4061
port: 4061,
},

/**
Expand All @@ -81,7 +81,7 @@ config.iota = {
* from the 'mongoDb' configuration property.
*/
deviceRegistry: {
type: 'mongodb'
type: 'mongodb',
},

/**
Expand All @@ -104,7 +104,7 @@ config.iota = {
/**
* Name of the Mongo database that will be created to store IOTAgent data.
*/
db: 'iotagentlora'
db: 'iotagentlora',

/**
* Name of the set in case the Mongo database is configured as a Replica Set. Optional otherwise.
Expand Down Expand Up @@ -144,7 +144,7 @@ config.iota = {
/**
* Default type, for IOTA installations that won't require preregistration.
*/
defaultType: 'Thing'
defaultType: 'Thing',
};

module.exports = config;
20 changes: 9 additions & 11 deletions lib/configService.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,30 @@
var winston = require('winston');
var config = {};

const tsFormat = () => (new Date().toISOString());
const tsFormat = () => new Date().toISOString();

/**
* Sets the configuration.
*
* @param {<type>} newConfig The new configuration
*/
function setConfig (newConfig) {
function setConfig(newConfig) {
config = newConfig;
winston.configure({
level: newConfig.iota.logLevel.toLowerCase(),
timestamp: tsFormat,
format: winston.format.combine(
winston.format.timestamp(),
winston.format.splat(),
winston.format.printf(info => JSON.stringify(
{
winston.format.printf(info =>
JSON.stringify({
timestamp: `${info.timestamp}`,
level: `${info.level}`,
message: `${info.message}`
}
))
message: `${info.message}`,
})
)
),
transports: [
new winston.transports.Console()
]
transports: [new winston.transports.Console()],
});
}

Expand All @@ -58,7 +56,7 @@ function setConfig (newConfig) {
*
* @return {<type>} The configuration.
*/
function getConfig () {
function getConfig() {
return config;
}

Expand Down
39 changes: 21 additions & 18 deletions lib/dataTranslationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var winston = require('winston');
* @param {Object} device The device
* @return {Object} {NGSI message}
*/
function toNgsi (payload, device) {
function toNgsi(payload, device) {
var ngsiAtts = [];
var decodedPayload = {};
if (payload && device) {
Expand Down Expand Up @@ -68,26 +68,29 @@ function toNgsi (payload, device) {
for (var field in decodedPayload) {
var value = decodedPayload[field];
for (i = 0; i < device.active.length; i++) {
if (device.active[i].type === 'geo:point' && value.latitude && value.longitude) {
if (
device.active[i].type === 'geo:point' &&
value.latitude &&
value.longitude
) {
value = value.latitude + ',' + value.longitude;
}

if (field === device.active[i].name) {
ngsiAtts.push(
{
'name': field,
'type': device.active[i].type,
'value': value
}
);
} else if (device.active[i].object_id && device.active[i].object_id === field) {
ngsiAtts.push(
{
'name': field,
'type': device.active[i].type,
'value': value
}
);
ngsiAtts.push({
name: field,
type: device.active[i].type,
value: value,
});
} else if (
device.active[i].object_id &&
device.active[i].object_id === field
) {
ngsiAtts.push({
name: field,
type: device.active[i].type,
value: value,
});
}
}
}
Expand All @@ -99,6 +102,6 @@ function toNgsi (payload, device) {
}

return ngsiAtts;
};
}

exports.toNgsi = toNgsi;

0 comments on commit 1f9e761

Please sign in to comment.