use yarn and prettier
This commit is contained in:
@@ -1,61 +1,72 @@
|
||||
var express = require('express');
|
||||
var express = require("express");
|
||||
var app = express();
|
||||
var cors = require('cors');
|
||||
var session = require('express-session')
|
||||
var morgan = require('morgan');
|
||||
var bodyParser = require('body-parser');
|
||||
var MongoStore = require('connect-mongo')(session);
|
||||
|
||||
var cors = require("cors");
|
||||
var session = require("express-session");
|
||||
var morgan = require("morgan");
|
||||
var bodyParser = require("body-parser");
|
||||
var MongoStore = require("connect-mongo")(session);
|
||||
|
||||
app.use(express.static(__dirname + "/public"));
|
||||
app.use(morgan('dev'));
|
||||
app.use(morgan("dev"));
|
||||
|
||||
let whitelist = ['localhost:3000',
|
||||
'localhost:8080',
|
||||
'http://localhost:8080',
|
||||
'http://api.henrypump.cloud',
|
||||
'http://api.henrypump.cloud:3000',
|
||||
'api.henrypump.cloud',
|
||||
'http://reports.henrypump.cloud',
|
||||
'reports.henrypump.cloud'];
|
||||
let whitelist = [
|
||||
"localhost:3000",
|
||||
"localhost:8080",
|
||||
"http://localhost:8080",
|
||||
"http://api.henrypump.cloud",
|
||||
"http://api.henrypump.cloud:3000",
|
||||
"api.henrypump.cloud",
|
||||
"http://reports.henrypump.cloud",
|
||||
"reports.henrypump.cloud"
|
||||
];
|
||||
// let whitelist = ['api.henrypump.cloud', 'http://api.henrypump.cloud', 'http://api.henrypump.cloud:3000', ];
|
||||
|
||||
var corsOptions = {
|
||||
origin: function (origin, callback) {
|
||||
origin: function(origin, callback) {
|
||||
if (whitelist.indexOf(origin) !== -1) {
|
||||
callback(null, true)
|
||||
callback(null, true);
|
||||
} else {
|
||||
callback(new Error('Not allowed by CORS: ' + origin))
|
||||
callback(new Error("Not allowed by CORS: " + origin));
|
||||
}
|
||||
}, credentials: true
|
||||
}
|
||||
app.use(function(req,res,next){ req.headers.origin = req.headers.origin || req.headers.host; next(); })
|
||||
},
|
||||
credentials: true
|
||||
};
|
||||
app.use(function(req, res, next) {
|
||||
req.headers.origin = req.headers.origin || req.headers.host;
|
||||
next();
|
||||
});
|
||||
|
||||
app.use(cors(corsOptions));
|
||||
|
||||
app.set('trust proxy', 1) // trust first proxy
|
||||
app.use(session({
|
||||
secret: 'keyboard cat',
|
||||
resave: false,
|
||||
saveUninitialized: true,
|
||||
store: new MongoStore({ url: 'mongodb://localhost:27017/pocloud-live-reports-server' })
|
||||
}))
|
||||
app.set("trust proxy", 1); // trust first proxy
|
||||
app.use(
|
||||
session({
|
||||
secret: "keyboard cat",
|
||||
resave: false,
|
||||
saveUninitialized: true,
|
||||
store: new MongoStore({
|
||||
url: "mongodb://localhost:27017/pocloud-live-reports-server"
|
||||
})
|
||||
})
|
||||
);
|
||||
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({
|
||||
extended: true
|
||||
}));
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
extended: true
|
||||
})
|
||||
);
|
||||
|
||||
app.get('/', require('./routes').index);
|
||||
app.get('/deviceTypes', require('./routes').deviceTypes);
|
||||
app.get('/devices/:deviceId/values', require('./routes').channelValues);
|
||||
app.get('/devices', require('./routes').devices);
|
||||
app.get('/companies', require('./routes').companies);
|
||||
app.get('/alldata', require('./routes').getAllData);
|
||||
app.post('/login', require('./routes').login);
|
||||
app.get('/login', require('./routes').getLogin);
|
||||
app.get('/logout', require('./routes').logout);
|
||||
app.get("/", require("./routes").index);
|
||||
app.get("/deviceTypes", require("./routes").deviceTypes);
|
||||
app.get("/devices/:deviceId/values", require("./routes").channelValues);
|
||||
app.get("/devices", require("./routes").devices);
|
||||
app.get("/companies", require("./routes").companies);
|
||||
app.get("/alldata", require("./routes").getAllData);
|
||||
app.post("/login", require("./routes").login);
|
||||
app.get("/login", require("./routes").getLogin);
|
||||
app.get("/logout", require("./routes").logout);
|
||||
|
||||
app.listen(3000, function () {
|
||||
console.log('Listening on port 3000!')
|
||||
})
|
||||
app.listen(3000, function() {
|
||||
console.log("Listening on port 3000!");
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"description": "Live Reporting Server for POCloud Data",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"precommit": "lint-staged"
|
||||
},
|
||||
"author": "Patrick McDonagh",
|
||||
"license": "ISC",
|
||||
@@ -20,5 +20,13 @@
|
||||
"mongoose": "^4.11.11",
|
||||
"morgan": "^1.8.2",
|
||||
"redis": "^2.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"husky": "^0.14.3",
|
||||
"lint-staged": "^7.0.0",
|
||||
"prettier": "^1.11.1"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,json,css,md}": ["prettier --write", "git add"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,326 +1,354 @@
|
||||
var https = require('https');
|
||||
var dcopy = require('deep-copy');
|
||||
var https = require("https");
|
||||
var dcopy = require("deep-copy");
|
||||
|
||||
const meshifyOptions = {
|
||||
protocol: 'https:',
|
||||
hostname: 'henrypump.meshify.com',
|
||||
path: '/api/v3/',
|
||||
protocol: "https:",
|
||||
hostname: "henrypump.meshify.com",
|
||||
path: "/api/v3/",
|
||||
port: 443,
|
||||
headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' },
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Access-Control-Allow-Origin": "*"
|
||||
}
|
||||
};
|
||||
|
||||
const hiddenDevices = ["gen", "mainHP", "mainMeshify", "M1"];
|
||||
|
||||
const deviceChannels = {
|
||||
advvfdipp: [
|
||||
'wellstatus',
|
||||
'flowtotalyesterday',
|
||||
'flowtotal',
|
||||
'energytotalyesterday',
|
||||
'energytotal',
|
||||
'fluidlevel',
|
||||
'flowrate',
|
||||
'vfdcurrent',
|
||||
'vfd_fault',
|
||||
'pidcontrolmode',
|
||||
'downholesensorstatus',
|
||||
'intakepressure',
|
||||
'intaketemperature',
|
||||
'tubingpressure',
|
||||
"wellstatus",
|
||||
"flowtotalyesterday",
|
||||
"flowtotal",
|
||||
"energytotalyesterday",
|
||||
"energytotal",
|
||||
"fluidlevel",
|
||||
"flowrate",
|
||||
"vfdcurrent",
|
||||
"vfd_fault",
|
||||
"pidcontrolmode",
|
||||
"downholesensorstatus",
|
||||
"intakepressure",
|
||||
"intaketemperature",
|
||||
"tubingpressure"
|
||||
],
|
||||
abbflow: [
|
||||
'yesterday_volume',
|
||||
'today_volume',
|
||||
'volume_flow',
|
||||
'differential_pressure',
|
||||
'static_pressure',
|
||||
'temperature',
|
||||
'battery_voltage',
|
||||
'last_calculation_period_volume'
|
||||
"yesterday_volume",
|
||||
"today_volume",
|
||||
"volume_flow",
|
||||
"differential_pressure",
|
||||
"static_pressure",
|
||||
"temperature",
|
||||
"battery_voltage",
|
||||
"last_calculation_period_volume"
|
||||
],
|
||||
flowmonitor:[
|
||||
'gal_total_yesterday',
|
||||
'bbl_total_yesterday',
|
||||
'gal_total',
|
||||
'bbl_total',
|
||||
'gpm_flow',
|
||||
'bpd_flow',
|
||||
'run_status'
|
||||
flowmonitor: [
|
||||
"gal_total_yesterday",
|
||||
"bbl_total_yesterday",
|
||||
"gal_total",
|
||||
"bbl_total",
|
||||
"gpm_flow",
|
||||
"bpd_flow",
|
||||
"run_status"
|
||||
],
|
||||
poc: [
|
||||
'go_percent_run',
|
||||
'go_kwh',
|
||||
'go_kwh_regen',
|
||||
'go_electricity_cost',
|
||||
'go_peak_load',
|
||||
'go_min_load',
|
||||
'go_average_spm',
|
||||
'go_production_calculated',
|
||||
'go_polished_rod_hp',
|
||||
'go_lifting_cost',
|
||||
'go_fluid_above_pump',
|
||||
'go_pump_intake_pressure',
|
||||
'go_inflow_rate',
|
||||
'dt_percent_run',
|
||||
'dt_kwh',
|
||||
'dt_kwh_regen',
|
||||
'dt_electricity_cost',
|
||||
'dt_peak_load',
|
||||
'dt_min_load',
|
||||
'dt_average_spm',
|
||||
'dt_production_calculated',
|
||||
'dt_polished_rod_hp',
|
||||
'dt_lifting_cost',
|
||||
'dt_fluid_above_pump',
|
||||
'dt_pump_intake_pressure',
|
||||
'dt_inflow_rate',
|
||||
"go_percent_run",
|
||||
"go_kwh",
|
||||
"go_kwh_regen",
|
||||
"go_electricity_cost",
|
||||
"go_peak_load",
|
||||
"go_min_load",
|
||||
"go_average_spm",
|
||||
"go_production_calculated",
|
||||
"go_polished_rod_hp",
|
||||
"go_lifting_cost",
|
||||
"go_fluid_above_pump",
|
||||
"go_pump_intake_pressure",
|
||||
"go_inflow_rate",
|
||||
"dt_percent_run",
|
||||
"dt_kwh",
|
||||
"dt_kwh_regen",
|
||||
"dt_electricity_cost",
|
||||
"dt_peak_load",
|
||||
"dt_min_load",
|
||||
"dt_average_spm",
|
||||
"dt_production_calculated",
|
||||
"dt_polished_rod_hp",
|
||||
"dt_lifting_cost",
|
||||
"dt_fluid_above_pump",
|
||||
"dt_pump_intake_pressure",
|
||||
"dt_inflow_rate"
|
||||
],
|
||||
rigpump: [
|
||||
'device_status',
|
||||
'flow_rate',
|
||||
'discharge_pressure',
|
||||
'vfd_current',
|
||||
'vfd_frequency',
|
||||
'auto_manual',
|
||||
'auto_control_mode',
|
||||
'watchdog'
|
||||
"device_status",
|
||||
"flow_rate",
|
||||
"discharge_pressure",
|
||||
"vfd_current",
|
||||
"vfd_frequency",
|
||||
"auto_manual",
|
||||
"auto_control_mode",
|
||||
"watchdog"
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const allowedDeviceTypes = Object.keys(deviceChannels);
|
||||
|
||||
exports.index = function(req, res){
|
||||
res.render('index', { });
|
||||
exports.index = function(req, res) {
|
||||
res.render("index", {});
|
||||
};
|
||||
|
||||
var checkLogin = function(req, authToken){
|
||||
console.log("token in checkLogin: " + authToken)
|
||||
let prom = new Promise(function(resolve, reject){
|
||||
if (typeof authToken === 'undefined'){
|
||||
reject({status: "failure", reason:"no token specified"})
|
||||
var checkLogin = function(req, authToken) {
|
||||
console.log("token in checkLogin: " + authToken);
|
||||
let prom = new Promise(function(resolve, reject) {
|
||||
if (typeof authToken === "undefined") {
|
||||
reject({ status: "failure", reason: "no token specified" });
|
||||
}
|
||||
let options = dcopy(meshifyOptions);
|
||||
options.path += "users/me";
|
||||
options.headers.Authorization = authToken;
|
||||
|
||||
const apiReq = https.get(options, (apiRes) => {
|
||||
let body = '';
|
||||
apiRes.on('data', function(d) {
|
||||
const apiReq = https
|
||||
.get(options, apiRes => {
|
||||
let body = "";
|
||||
apiRes.on("data", function(d) {
|
||||
body += d;
|
||||
});
|
||||
apiRes.on('end', function() {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(body);
|
||||
} catch (e){
|
||||
console.log("Got an error: ", e);
|
||||
reject({status: "failure", reason: "bad username or password"});
|
||||
}
|
||||
resolve({status: 'success', user: parsed});
|
||||
});
|
||||
apiRes.on("end", function() {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(body);
|
||||
} catch (e) {
|
||||
console.log("Got an error: ", e);
|
||||
reject({ status: "failure", reason: "bad username or password" });
|
||||
}
|
||||
resolve({ status: "success", user: parsed });
|
||||
});
|
||||
})
|
||||
}).on('error', function(e){
|
||||
console.log("Got an error: ", e);
|
||||
reject({status: "failure", reason: "bad username or password"});
|
||||
});
|
||||
.on("error", function(e) {
|
||||
console.log("Got an error: ", e);
|
||||
reject({ status: "failure", reason: "bad username or password" });
|
||||
});
|
||||
});
|
||||
return prom;
|
||||
}
|
||||
};
|
||||
|
||||
exports.login = function(req, res){
|
||||
exports.login = function(req, res) {
|
||||
console.log(req.body);
|
||||
console.log("# Username set to "+ req.body.username);
|
||||
res.setHeader('Access-Control-Allow-Credentials', 'true')
|
||||
console.log("# Username set to " + req.body.username);
|
||||
res.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
|
||||
checkLogin(req, req.body.authToken).then(function(userCheck){
|
||||
req.session['username'] = req.body.username;
|
||||
req.session['authorization'] = req.body.authToken;
|
||||
req.session.save();
|
||||
res.json({status:'success', username:req.session.username});
|
||||
}).catch(function(userCheck){
|
||||
console.log("couldn't verify login");
|
||||
console.log(userCheck);
|
||||
res.json(userCheck);
|
||||
})
|
||||
}
|
||||
checkLogin(req, req.body.authToken)
|
||||
.then(function(userCheck) {
|
||||
req.session["username"] = req.body.username;
|
||||
req.session["authorization"] = req.body.authToken;
|
||||
req.session.save();
|
||||
res.json({ status: "success", username: req.session.username });
|
||||
})
|
||||
.catch(function(userCheck) {
|
||||
console.log("couldn't verify login");
|
||||
console.log(userCheck);
|
||||
res.json(userCheck);
|
||||
});
|
||||
};
|
||||
|
||||
exports.getLogin = function(req, res){
|
||||
console.log("# Client Username check "+ req.session.username);
|
||||
checkLogin(req, req.session.authorization).then(function(userCheck){
|
||||
res.json({status:'success', username:req.session.username});
|
||||
}).catch(function(userCheck){
|
||||
console.log("couldn't verify login");
|
||||
console.log(userCheck);
|
||||
res.json(userCheck);
|
||||
})
|
||||
}
|
||||
exports.getLogin = function(req, res) {
|
||||
console.log("# Client Username check " + req.session.username);
|
||||
checkLogin(req, req.session.authorization)
|
||||
.then(function(userCheck) {
|
||||
res.json({ status: "success", username: req.session.username });
|
||||
})
|
||||
.catch(function(userCheck) {
|
||||
console.log("couldn't verify login");
|
||||
console.log(userCheck);
|
||||
res.json(userCheck);
|
||||
});
|
||||
};
|
||||
|
||||
exports.logout = function(req, res){
|
||||
exports.logout = function(req, res) {
|
||||
req.session.destroy();
|
||||
res.end();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var getMeshifyPromise = function(req, path){
|
||||
if (typeof req.session['authorization'] !== 'undefined'){
|
||||
let prom = new Promise(function(resolve, reject){
|
||||
var getMeshifyPromise = function(req, path) {
|
||||
if (typeof req.session["authorization"] !== "undefined") {
|
||||
let prom = new Promise(function(resolve, reject) {
|
||||
let options = dcopy(meshifyOptions);
|
||||
options.path += path;
|
||||
options.headers.Authorization = req.session['authorization'];
|
||||
options.headers.Authorization = req.session["authorization"];
|
||||
|
||||
const apiReq = https.get(options, (apiRes) => {
|
||||
let body = '';
|
||||
apiRes.on('data', function(d) {
|
||||
body += d;
|
||||
const apiReq = https.get(options, apiRes => {
|
||||
let body = "";
|
||||
apiRes.on("data", function(d) {
|
||||
body += d;
|
||||
});
|
||||
apiRes.on('end', function() {
|
||||
apiRes.on("end", function() {
|
||||
const parsed = JSON.parse(body);
|
||||
resolve(parsed);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
return prom;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.deviceTypes = function(req, res){
|
||||
getMeshifyPromise(req, 'devicetypes').then(function(jsData){
|
||||
if(jsData){
|
||||
exports.deviceTypes = function(req, res) {
|
||||
getMeshifyPromise(req, "devicetypes").then(function(jsData) {
|
||||
if (jsData) {
|
||||
res.json(jsData);
|
||||
} else {
|
||||
res.json({status: 'error', message: 'no token specified'});
|
||||
res.json({ status: "error", message: "no token specified" });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.devices = function(req, res){
|
||||
getMeshifyPromise(req, 'devices').then(function(jsData){
|
||||
if(jsData){
|
||||
exports.devices = function(req, res) {
|
||||
getMeshifyPromise(req, "devices").then(function(jsData) {
|
||||
if (jsData) {
|
||||
res.json(jsData);
|
||||
} else {
|
||||
res.json({status: 'error', message: 'no token specified'});
|
||||
res.json({ status: "error", message: "no token specified" });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.companies = function(req, res){
|
||||
getMeshifyPromise(req, 'companies').then(function(jsData){
|
||||
if(jsData){
|
||||
exports.companies = function(req, res) {
|
||||
getMeshifyPromise(req, "companies").then(function(jsData) {
|
||||
if (jsData) {
|
||||
res.json(jsData);
|
||||
} else {
|
||||
res.json({status: 'error', message: 'no token specified'});
|
||||
res.json({ status: "error", message: "no token specified" });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.channelValues = function(req, res){
|
||||
getMeshifyPromise(req, "devices/" + req.params.deviceId + "/values").then(function(jsData){
|
||||
if(jsData){
|
||||
res.json(jsData);
|
||||
} else {
|
||||
res.json({status: 'error', message: 'no token specified'});
|
||||
exports.channelValues = function(req, res) {
|
||||
getMeshifyPromise(req, "devices/" + req.params.deviceId + "/values").then(
|
||||
function(jsData) {
|
||||
if (jsData) {
|
||||
res.json(jsData);
|
||||
} else {
|
||||
res.json({ status: "error", message: "no token specified" });
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
exports.getAllData = function(req, res){
|
||||
exports.getAllData = function(req, res) {
|
||||
var cleanData = [];
|
||||
var deviceTypeMap = {};
|
||||
var companies;
|
||||
var devicetypes;
|
||||
var devices;
|
||||
|
||||
let getData = Promise.all([getMeshifyPromise(req, 'companies'), getMeshifyPromise(req, 'devicetypes'), getMeshifyPromise(req, 'devices')]).then(function(results){
|
||||
companies = results[0];
|
||||
devicetypes = results[1];
|
||||
devices = results[2];
|
||||
let getData = Promise.all([
|
||||
getMeshifyPromise(req, "companies"),
|
||||
getMeshifyPromise(req, "devicetypes"),
|
||||
getMeshifyPromise(req, "devices")
|
||||
])
|
||||
.then(function(results) {
|
||||
companies = results[0];
|
||||
devicetypes = results[1];
|
||||
devices = results[2];
|
||||
|
||||
return companies.map(function(c){
|
||||
var newCompany = {
|
||||
id: c.id,
|
||||
name: c.name,
|
||||
tenantId: c.tenantId,
|
||||
addressId: c.addressId,
|
||||
devices: {}
|
||||
return companies.map(function(c) {
|
||||
var newCompany = {
|
||||
id: c.id,
|
||||
name: c.name,
|
||||
tenantId: c.tenantId,
|
||||
addressId: c.addressId,
|
||||
devices: {}
|
||||
};
|
||||
return newCompany;
|
||||
});
|
||||
})
|
||||
.then(function(compList) {
|
||||
cleanData = compList;
|
||||
let i = 0;
|
||||
while (i < devicetypes.length) {
|
||||
deviceTypeMap[devicetypes[i].id] = devicetypes[i].name;
|
||||
i++;
|
||||
if (i == devicetypes.length) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return newCompany;
|
||||
})
|
||||
.then(function() {
|
||||
return Promise.all(
|
||||
devices.map(function(device) {
|
||||
return getMeshifyPromise(req, "devices/" + device.id + "/values");
|
||||
})
|
||||
);
|
||||
});
|
||||
}).then(function(compList){
|
||||
cleanData = compList;
|
||||
let i = 0;
|
||||
while (i < devicetypes.length){
|
||||
deviceTypeMap[devicetypes[i].id] = devicetypes[i].name;
|
||||
i++;
|
||||
if(i == devicetypes.length){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}).then(function(){
|
||||
return Promise.all(devices.map(function(device){
|
||||
return getMeshifyPromise(req, 'devices/' + device.id + '/values');
|
||||
}))
|
||||
});
|
||||
|
||||
getData.then(function(allDeviceValues){
|
||||
return allDeviceValues.map(function(devValObj, i){
|
||||
const thisDeviceType = deviceTypeMap[devices[i].deviceTypeId];
|
||||
if (allowedDeviceTypes.indexOf(thisDeviceType) > -1){
|
||||
let values = [];
|
||||
let valkeys = Object.keys(devValObj);
|
||||
let v = 0;
|
||||
while(v < valkeys.length){
|
||||
if(deviceChannels[thisDeviceType].indexOf(valkeys[v]) > -1){
|
||||
let newVal = {
|
||||
channel: valkeys[v],
|
||||
timestamp: devValObj[valkeys[v]].timestamp,
|
||||
value: devValObj[valkeys[v]].value
|
||||
getData
|
||||
.then(function(allDeviceValues) {
|
||||
return allDeviceValues.map(function(devValObj, i) {
|
||||
const thisDeviceType = deviceTypeMap[devices[i].deviceTypeId];
|
||||
if (allowedDeviceTypes.indexOf(thisDeviceType) > -1) {
|
||||
let values = [];
|
||||
let valkeys = Object.keys(devValObj);
|
||||
let v = 0;
|
||||
while (v < valkeys.length) {
|
||||
if (deviceChannels[thisDeviceType].indexOf(valkeys[v]) > -1) {
|
||||
let newVal = {
|
||||
channel: valkeys[v],
|
||||
timestamp: devValObj[valkeys[v]].timestamp,
|
||||
value: devValObj[valkeys[v]].value
|
||||
};
|
||||
values.push(newVal);
|
||||
}
|
||||
v++;
|
||||
if (v == valkeys.length) {
|
||||
return values;
|
||||
}
|
||||
values.push(newVal);
|
||||
}
|
||||
v++;
|
||||
if(v == valkeys.length){
|
||||
return values
|
||||
}
|
||||
});
|
||||
})
|
||||
.then(function(allDevValuesClean) {
|
||||
return devices.map(function(device, i) {
|
||||
return {
|
||||
id: device.id,
|
||||
companyId: device.companyId,
|
||||
tenantId: device.tenantId,
|
||||
deviceTypeId: device.deviceTypeId,
|
||||
deviceType: deviceTypeMap[device.deviceTypeId],
|
||||
gatewayId: device.gatewayId,
|
||||
techname: device.techname,
|
||||
macAddress: device.macAddress,
|
||||
vanityName: device.vanityName,
|
||||
values: allDevValuesClean[i]
|
||||
};
|
||||
});
|
||||
})
|
||||
.then(function(devicesWithValues) {
|
||||
let i = 0;
|
||||
while (i < devicesWithValues.length) {
|
||||
for (let c = 0; c < cleanData.length; c++) {
|
||||
if (cleanData[c].id === devicesWithValues[i].companyId) {
|
||||
if (
|
||||
allowedDeviceTypes.indexOf(devicesWithValues[i].deviceType) >= 0
|
||||
) {
|
||||
if (
|
||||
typeof cleanData[c].devices[devicesWithValues[i].deviceType] ===
|
||||
"undefined"
|
||||
) {
|
||||
cleanData[c].devices[devicesWithValues[i].deviceType] = [];
|
||||
}
|
||||
cleanData[c].devices[devicesWithValues[i].deviceType].push(
|
||||
devicesWithValues[i]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
if (i == devicesWithValues.length) {
|
||||
return cleanData;
|
||||
}
|
||||
}
|
||||
})
|
||||
}).then(function(allDevValuesClean){
|
||||
return devices.map(function(device, i){
|
||||
return {
|
||||
id: device.id,
|
||||
companyId: device.companyId,
|
||||
tenantId: device.tenantId,
|
||||
deviceTypeId: device.deviceTypeId,
|
||||
deviceType: deviceTypeMap[device.deviceTypeId],
|
||||
gatewayId: device.gatewayId,
|
||||
techname: device.techname,
|
||||
macAddress: device.macAddress,
|
||||
vanityName: device.vanityName,
|
||||
values: allDevValuesClean[i]
|
||||
}
|
||||
})
|
||||
}).then(function(devicesWithValues){
|
||||
let i = 0;
|
||||
while(i < devicesWithValues.length){
|
||||
for(let c = 0; c < cleanData.length; c++){
|
||||
if (cleanData[c].id === devicesWithValues[i].companyId){
|
||||
if(allowedDeviceTypes.indexOf(devicesWithValues[i].deviceType) >= 0){
|
||||
if (typeof cleanData[c].devices[devicesWithValues[i].deviceType] === 'undefined'){
|
||||
cleanData[c].devices[devicesWithValues[i].deviceType] = [];
|
||||
}
|
||||
cleanData[c].devices[devicesWithValues[i].deviceType].push(devicesWithValues[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
if(i == devicesWithValues.length){
|
||||
return cleanData;
|
||||
}
|
||||
}
|
||||
}).then(function(data){
|
||||
res.json(data);
|
||||
})
|
||||
.then(function(data) {
|
||||
res.json(data);
|
||||
});
|
||||
};
|
||||
|
||||
2660
server/yarn.lock
Normal file
2660
server/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user