@sedni/cloud_common 1.0.5 → 1.0.7

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.
@@ -152,7 +152,7 @@ channeldataBucketSchema.statics.insertDataPoint = async function(timestamp, valu
152
152
  date.setMilliseconds(0);
153
153
 
154
154
  // Upsert the data point
155
- const bucket = await this.updateOne(
155
+ const bucket = await this.findOneAndUpdate(
156
156
  {
157
157
  start_date: date
158
158
  },
@@ -178,7 +178,8 @@ channeldataBucketSchema.statics.insertDataPoint = async function(timestamp, valu
178
178
  }
179
179
  },
180
180
  {
181
- upsert: true
181
+ upsert: true,
182
+ new: true
182
183
  }
183
184
  );
184
185
 
@@ -253,14 +254,21 @@ channeldataBucketSchema.statics.getData = async function(start_date, end_date, p
253
254
  }
254
255
 
255
256
  // Remove the data inside the bucket that is not in the specified date range
256
- data[0].data.removeDataPointsOutsideDateRange(start_date, end_date);
257
+ data[0].removeDataPointsOutsideDateRange(start_date, end_date);
257
258
 
258
259
  if(data.length > 1)
259
260
  {
260
- data[1].data.removeDataPointsOutsideDateRange(start_date, end_date);
261
+ data[1].removeDataPointsOutsideDateRange(start_date, end_date);
261
262
  }
262
263
 
263
- return plain ? data.flatMap(bucket => bucket.data) : data;
264
+ return plain ? data.flatMap(bucket => {
265
+ return bucket.data.map(data_point => {
266
+ return {
267
+ timestamp: data_point.timestamp,
268
+ value: data_point.value
269
+ };
270
+ });
271
+ }) : data;
264
272
  };
265
273
 
266
274
 
@@ -42,6 +42,10 @@ const historySchema = new mongoose.Schema({
42
42
  type: String,
43
43
  required: false,
44
44
  },
45
+ alarm_data: {
46
+ type: Object,
47
+ required: false,
48
+ },
45
49
  }, {
46
50
  timestamps: {
47
51
  createdAt: false,
@@ -55,13 +59,13 @@ const historySchema = new mongoose.Schema({
55
59
  ret.id = ret._id;
56
60
  delete ret._id;
57
61
  delete ret.__v;
58
- ret.alarm_timestamp = ret.alarm_timestamp.getTime();
62
+ ret.alarm_timestamp = new Date(ret.alarm_timestamp).getTime();
59
63
  ret.alarm = {
60
- priority: ret.alarm_priority,
61
- state: ret.alarm_original_state ?? "Inactive",
62
- type: ret.alarm_type,
63
- value: ret.alarm_value === null ? "inf" : `${ret.alarm_value}`,
64
- timestamp: new Date(ret.alarm_timestamp).getTime()
64
+ alarm_priority: ret.alarm_priority,
65
+ alarm_state: ret.alarm_original_state ?? "Inactive",
66
+ alarm_type: ret.alarm_type,
67
+ alarm_value: ret.alarm_value === null ? "inf" : `${ret.alarm_value}`,
68
+ alarm_timestamp: new Date(ret.alarm_timestamp).getTime()
65
69
  };
66
70
  },
67
71
  },
@@ -23,6 +23,7 @@ const CloudAlarmStates =
23
23
  WARNING_ACK: "WarningAcknowledged",
24
24
  RETURN_NO_ACK: "Unacknowledged",
25
25
  INHIBITED: "Inhibited",
26
+ OFFSCAN : "Offscan",
26
27
  UNDEFINED: "Undefined",
27
28
  };
28
29
 
@@ -37,7 +38,7 @@ const AlarmTypes =
37
38
  ALARM_L: "AlarmL",
38
39
  ALARM_LL: "AlarmLl",
39
40
  ALARM_IFL: "AlarmIfl",
40
- ALARM_OFFSCAN: "AlarmOffscan",
41
+ ALARM_OFFSCAN: "AlarmOffScan",
41
42
  ALARM_FAIL: "AlarmFail",
42
43
  ALARM_INH: "AlarmInh",
43
44
  ALARM_UNK: "AlarmUnk",
@@ -1,12 +1,13 @@
1
1
  const EventCategories =
2
2
  {
3
- ACCESS_CONTROL: "ACCESS_CONTROL",
4
- REQUEST_FAILURE: "REQUEST_FAILURE",
5
- OS: "OS",
6
- CONTROL: "CONTROL",
7
- BACKUP: "BACKUP",
8
- CONFIG_CHANGE: "CONFIG_CHANGE",
9
- LOGS: "LOGS"
3
+ ACCESS_CONTROL: "AccessControl",
4
+ REQUEST_ERROR: "RequestErrors",
5
+ OS: "OperatingSystemEvents",
6
+ CONTROL: "ControlSystemEvents",
7
+ BACKUP: "BackupAndRestoreEvents",
8
+ CONFIG_CHANGE: "ConfigurationChanges",
9
+ LOGS: "AuditLogEvents",
10
+ POTENTIAL_ATTACK: "PotentialAttackActivity",
10
11
  };
11
12
 
12
13
  module.exports = {
package/index.js CHANGED
@@ -38,6 +38,7 @@ const Types = {
38
38
  * EXTERNAL
39
39
  */
40
40
  const mongoose = require("mongoose");
41
+ const mongooseAutopopulate = require("mongoose-autopopulate");
41
42
  const mongoosePaginate = require("mongoose-paginate-v2");
42
43
  const mongooseAggregatePaginate = require("mongoose-aggregate-paginate-v2");
43
44
 
@@ -48,4 +49,5 @@ module.exports = {
48
49
  mongoose,
49
50
  mongoosePaginate,
50
51
  mongooseAggregatePaginate,
52
+ mongooseAutopopulate,
51
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sedni/cloud_common",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Common package for all types, resources and tools of Diamar Cloud",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -30,4 +30,4 @@
30
30
  "sinon": "^19.0.2",
31
31
  "supertest": "^7.0.0"
32
32
  }
33
- }
33
+ }
package/eslint.config.js DELETED
@@ -1,40 +0,0 @@
1
- const globals = require("globals");
2
- const pluginJs = require("@eslint/js");
3
- const nodePlugin = require("eslint-plugin-n");
4
- const mochaPlugin = require("eslint-plugin-mocha");
5
-
6
- module.exports = [
7
- mochaPlugin.configs.recommended,
8
- pluginJs.configs.recommended,
9
- nodePlugin.configs["flat/recommended-script"],
10
- {
11
- files: ["app/**/*.js", "index.js"],
12
- languageOptions: {
13
- "ecmaVersion": "latest",
14
- "sourceType": "commonjs",
15
- "globals": globals.node,
16
- },
17
- rules: {
18
- "prefer-const": ["error"],
19
- "no-var": ["error"],
20
- "semi": ["error", "always"],
21
- "indent": ["error", 4],
22
- "quotes": ["error", "double"],
23
- "no-unused-vars": [
24
- "error",
25
- {
26
- "varsIgnorePattern": "should|expect|supertest|assert",
27
- },
28
- ],
29
- "curly": ["error", "all"],
30
- "brace-style": ["error", "allman"],
31
- "n/no-missing-require" : "off",
32
- "n/no-unpublished-require": [
33
- "error",
34
- {
35
- "allowModules": ["swagger-ui-express"],
36
- },
37
- ],
38
- }
39
- },
40
- ];
package/playground.js DELETED
@@ -1,11 +0,0 @@
1
-
2
- // Get the timestamp before importing the models
3
- const start = Date.now();
4
-
5
- const ChannelDataBucket = require("./app/test/data/ChannelDataBucket");
6
-
7
- // Get the timestamp after importing the models
8
- const end = Date.now();
9
-
10
- // Print the difference
11
- console.log(`Time taken to import the models: ${end - start}ms`);