alsmanager_lib 1.0.85 → 1.0.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/modules.js +59 -18
  2. package/package.json +1 -1
package/lib/modules.js CHANGED
@@ -413,14 +413,24 @@ function getStoragesByConfigSQLite(id_device, id_conf) {
413
413
  var query = "select ds.id, st.name as Tipo, ds.storage_size_unit as Unit, ds.storage_totsize as Dimensione, ds.storage_manifacturer as Marca, ds.storage_model as Modello from device_storages ds ";
414
414
  query += "join storage_types st on st.id = ds.storage_type ";
415
415
  query += "where id_device = " + id_device + " ";
416
- query += "and ds.id in (select id_part from change_config where id_conf = " + id_conf + ")";
416
+ if (id_conf > 0) {
417
+ query += "and ds.id in (select id_part from change_config where id_conf = " + id_conf + ")";
418
+ }
419
+ else {
420
+ query += "and ds.id in (select id_part from change_config where id_device = " + id_device + " and part_type = 'STORAGE' order by id desc LIMIT 1)"
421
+ }
417
422
  return query;
418
423
  }
419
424
  function getStoragesByConfigMySQL(id_device, id_conf) {
420
425
  var query = "select ds.id, st.name as Tipo, ds.storage_size_unit as Unit, ds.storage_totsize as Dimensione, ds.storage_manifacturer as Marca, ds.storage_model as Modello from device_storages ds ";
421
426
  query += "join storage_types st on st.id = ds.storage_type ";
422
427
  query += "where id_device = :id_device ";
423
- query += "and ds.id in (select id_part from change_config where id_conf = :id_conf)";
428
+ if (id_conf > 0) {
429
+ query += "and ds.id in (select id_part from change_config where id_conf = :id_conf)";
430
+ }
431
+ else {
432
+ query += "and ds.id in (select id_part from change_config where id_device = :id_device and part_type = 'STORAGE' order by id desc LIMIT 1)"
433
+ }
424
434
  return query;
425
435
  }
426
436
  function getStoragesByConfig(db_used, id_device, id_conf) {
@@ -679,13 +689,23 @@ function getLastNetworkInserted(db_used, id_device) {
679
689
  function getNetworksByConfigSQLite(id_device, id_conf) {
680
690
  var query = "select dn.id, dn.net_type as Tipo, dn.mac_address as MAC, dn.ipv4_static as IP4, dn.ipv6_static as IP6 from device_networks dn ";
681
691
  query += "where dn.id_device = " + id_device + " ";
682
- query += "and dn.id in (select id_part from change_config where id_conf = " + id_conf + ")";
692
+ if (id_conf > 0) {
693
+ query += "and dn.id in (select id_part from change_config where id_conf = " + id_conf + ")";
694
+ }
695
+ else {
696
+ query += "and dn.id in (select id_part from change_config where id_device = " + id_device + " and part_type = 'NETWORK' order by id desc LIMIT 1)"
697
+ }
683
698
  return query;
684
699
  }
685
700
  function getNetworksByConfigMySQL(id_device, id_conf) {
686
701
  var query = "select dn.id, dn.net_type as Tipo, dn.mac_address as MAC, dn.ipv4_static as IP4, dn.ipv6_static as IP6 from device_networks dn ";
687
702
  query += "where dn.id_device = :id_device ";
688
- query += "and dn.id in (select id_part from change_config where id_conf = :id_conf)";
703
+ if (id_conf > 0) {
704
+ query += "and dn.id in (select id_part from change_config where id_conf = :id_conf)";
705
+ }
706
+ else {
707
+ query += "and dn.id in (select id_part from change_config where id_device = :id_device and part_type = 'NETWORK' order by id desc LIMIT 1)"
708
+ }
689
709
  return query;
690
710
  }
691
711
  function getNetworksByConfig(db_used, id_device, id_conf) {
@@ -971,14 +991,24 @@ function getAddOnsByConfigSQLite(id_device, id_conf) {
971
991
  var query = "select da.id, a.name as Tipo, da.maker as Marca, da.model as Modello, da.description as Descrizione from device_addons da ";
972
992
  query += "join addon_types a on a.id = da.addon_type ";
973
993
  query += "where da.id_device = " + id_device + " ";
974
- query += "and da.id in (select id_part from change_config where id_conf = " + id_conf + ")";
994
+ if (id_conf > 0) {
995
+ query += "and da.id in (select id_part from change_config where id_conf = " + id_conf + ")";
996
+ }
997
+ else {
998
+ query += "and da.id in (select id_part from change_config where id_device = " + id_device + " and part_type = 'ADDON' order by id desc LIMIT 1)"
999
+ }
975
1000
  return query;
976
1001
  }
977
1002
  function getAddOnsByConfigMySQL(id_device, id_conf) {
978
1003
  var query = "select da.id, a.name as Tipo, da.maker as Marca, da.model as Modello, da.description as Descrizione from device_addons da ";
979
1004
  query += "join addon_types a on a.id = da.addon_type ";
980
1005
  query += "where da.id_device = :id_device ";
981
- query += "and da.id in (select id_part from change_config where id_conf = :id_conf)";
1006
+ if (id_conf > 0) {
1007
+ query += "and da.id in (select id_part from change_config where id_conf = :id_conf)";
1008
+ }
1009
+ else {
1010
+ query += "and da.id in (select id_part from change_config where id_device = :id_device and part_type = 'ADDON' order by id desc LIMIT 1)"
1011
+ }
982
1012
  return query;
983
1013
  }
984
1014
  function getAddOnsByConfig(db_used, id_device, id_conf) {
@@ -1156,7 +1186,7 @@ function removeDeviceConfiguration(db_used, id_conf) {
1156
1186
  return query;
1157
1187
  }
1158
1188
  //
1159
- function insertPartChangedSQLite(id_conf, part_type, id_part, operation, id_part_replaced) {
1189
+ function insertPartChangedSQLite(id_conf, id_part, part_type, operation, id_part_replaced) {
1160
1190
  var query = "insert into change_config (id_conf, part_type, id_part, operation, id_part_replaced) values (";
1161
1191
  query += id_conf + ", ";
1162
1192
  query += "'" + part_type + "', ";
@@ -1167,17 +1197,24 @@ function insertPartChangedSQLite(id_conf, part_type, id_part, operation, id_part
1167
1197
  return query;
1168
1198
  }
1169
1199
  function insertPartChangedMySQL() {
1170
-
1200
+ var query = "insert into change_config (id_conf, part_type, id_part, operation, id_part_replaced) values (";
1201
+ query += ":id_conf, ";
1202
+ query += ":part_type, ";
1203
+ query += ":id_part, ";
1204
+ query += ":operation, ";
1205
+ query += ":id_part_replaced";
1206
+ query += ")";
1207
+ return query;
1171
1208
  }
1172
- function insertPartChanged(db_used, id_conf, part_type, id_part, operation, id_part_replaced) {
1209
+ function insertPartChanged(db_used, id_conf, id_part, part_type, operation, id_part_replaced) {
1173
1210
  var query = "";
1174
1211
  if (db_used) {
1175
1212
  switch (db_used) {
1176
1213
  case 'SQLITE':
1177
- query = insertPartChangedSQLite(id_conf, part_type, id_part, operation, id_part_replaced);
1214
+ query = insertPartChangedSQLite(id_conf, id_part, part_type, operation, id_part_replaced);
1178
1215
  break;
1179
1216
  case 'MYSQL':
1180
- query = insertPartChangedMySQL(id_conf, part_type, id_part, operation, id_part_replaced);
1217
+ query = insertPartChangedMySQL(id_conf, id_part, part_type, operation, id_part_replaced);
1181
1218
  break;
1182
1219
  }
1183
1220
  }
@@ -1215,27 +1252,31 @@ function updatePartChanged(db_used, id_change, operation, id_part_replaced) {
1215
1252
  return query;
1216
1253
  }
1217
1254
 
1218
- function removePartChangedSQLite(id_change, id_conf) {
1255
+ function removePartChangedSQLite(id_conf, id_part, part_type) {
1219
1256
  var query = "delete from change_config ";
1220
- query += "where id = " + id_change + " and id_conf = " + id_conf;
1257
+ query += "where id_device = " + id_part + " ";
1258
+ query += "and id_conf = " + id_conf + " ";
1259
+ query += "and part_type = '" + part_type + "'";
1221
1260
  return query;
1222
1261
  }
1223
1262
 
1224
- function removePartChangedMySQL(id_change, id_conf) {
1263
+ function removePartChangedMySQL(id_conf, id_part) {
1225
1264
  var query = "delete from change_config ";
1226
- query += "where id = :id_change and id_conf = :id_conf";
1265
+ query += "where id_device = :id_part ";
1266
+ query += "and id_conf = :id_conf ";
1267
+ query += "and part_type = :part_type";
1227
1268
  return query;
1228
1269
  }
1229
1270
 
1230
- function removePartChanged(db_used, id_change, id_conf) {
1271
+ function removePartChanged(db_used, id_conf, id_part, part_type) {
1231
1272
  var query = "";
1232
1273
  if (db_used) {
1233
1274
  switch (db_used) {
1234
1275
  case 'SQLITE':
1235
- query = removePartChangedSQLite(id_change, id_conf);
1276
+ query = removePartChangedSQLite(id_conf, id_part, part_type);
1236
1277
  break;
1237
1278
  case 'MYSQL':
1238
- query = removePartChangedMySQL(id_change, id_conf);
1279
+ query = removePartChangedMySQL(id_conf, id_part, part_type);
1239
1280
  break;
1240
1281
  }
1241
1282
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alsmanager_lib",
3
- "version": "1.0.85",
3
+ "version": "1.0.87",
4
4
  "description": "Funzioni per ALSManager",
5
5
  "license": "ISC",
6
6
  "author": "Luca Cattani",