/var/www/myprog.com.ua/server/node/objects
Edit: /var/www/myprog.com.ua/server/node/objects/host.js (1492B)
//const User = require('./user');
const microtime = require('../helpers/date');
class Host {
constructor(data) {
// db fields
this.id = 0;
this.sn = '';
this.name = '';
this.key = '';
this.hw = '';
this.sw = '';
this.socket_id = '';
this.online = 0;
this.active = 0;
this.deleted = 0;
if (db_fields_names_order.length == 0) {
for (var i in this) {
db_fields_names_order.push(i);
}
}
// set order data from db
if (data) {
for (var i in this) {
if (data[i]) {
this[i] = data[i];
}
}
}
this.socket = null;
this.devices = [];
this.events = [];
this.commands = [];
this.values = [];
}
connect(socket_id) {
this.socket_id = socket_id;
}
disconnect() {
this.socket_id = undefined;
}
is_activated(){
return this.active==1?true:false;
}
get_db_fields_names() {
return db_fields_names_order;
}
get_array() {
let array = [];
this.get_db_fields_names().forEach(k => {
array[k] = this[k];
})
return array;
}
get_json() {
let copy = {};
Object.assign(copy, this.get_array());
return JSON.stringify(copy);
}
}
let db_fields_names_order = [];
module.exports = Host;