Skip to content

Commit

Permalink
fixing runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Baalmart committed Dec 11, 2024
1 parent 58290b8 commit 534690c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 39 deletions.
64 changes: 44 additions & 20 deletions src/device-registry/controllers/create-collocation.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
const httpStatus = require("http-status");
const { v4: uuidv4 } = require("uuid");
const logger = require("@utils/logger");
const { CollocationService } = require("@services/collocation");
const { decodeUserToken } = require("@utils/auth");
const constants = require("@config/constants");
const log4js = require("log4js");
const logger = log4js.getLogger(
`${constants.ENVIRONMENT} -- create-collocation controller`
);
const { CollocationService } = require("@utils/create-collocation");
const {
CollocationDefaults,
CollocationBatchStatus,
CollocationBatchResult,
} = require("@models/collocation");
} = require("@models/CollocationBatch");
const { HttpError } = require("@utils/errors");
const { handleResponse } = require("@utils/response");
const handleResponse = (response) => {
response.res.status().json(response.result);

Check warning on line 16 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L16

Added line #L16 was not covered by tests
};

const moment = require("moment");

const collocationController = {
Expand All @@ -30,7 +36,6 @@ const collocationController = {
);
}
},

saveCollocationBatch: async (req, res, next) => {
try {

Check warning on line 40 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L40

Added line #L40 was not covered by tests
const {
Expand All @@ -48,7 +53,7 @@ const collocationController = {
} = req.body;

Check warning on line 53 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L53

Added line #L53 was not covered by tests

const userToken = req.headers.authorization?.split(" ")[1] || "";
const userDetails = userToken ? decodeUserToken(userToken) : {};
const userDetails = {};

Check warning on line 56 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L55-L56

Added lines #L55 - L56 were not covered by tests

const batch = {

Check warning on line 58 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L58

Added line #L58 was not covered by tests
batchId: "", // will be set by service
Expand Down Expand Up @@ -87,19 +92,18 @@ const collocationController = {
);
}
},

// Other methods following similar patterns for:
// - deleteCollocationBatch
// - resetCollocationBatch
// - getCollocationBatch
// - getCollocationSummary
// - getCollocationBatchData
// - getCollocationBatchResults
// - getCollocationDataCompleteness
// - getCollocationDataStatistics
// - getCollocationIntraSensorCorrelation

// Example of one more method to illustrate:
deleteCollocationBatch: async (req, res, next) => {
try {

Check warning on line 96 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L96

Added line #L96 was not covered by tests
} catch (error) {}
},
resetCollocationBatch: async (req, res, next) => {
try {

Check warning on line 100 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L100

Added line #L100 was not covered by tests
} catch (error) {}
},
getCollocationBatch: async (req, res, next) => {
try {

Check warning on line 104 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L104

Added line #L104 was not covered by tests
} catch (error) {}
},
getCollocationSummary: async (req, res, next) => {
try {
const collocationService = new CollocationService();
Expand All @@ -123,6 +127,26 @@ const collocationController = {
);
}
},
getCollocationBatchData: async (req, res, next) => {
try {

Check warning on line 131 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L131

Added line #L131 was not covered by tests
} catch (error) {}
},
getCollocationBatchResults: async (req, res, next) => {
try {

Check warning on line 135 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L135

Added line #L135 was not covered by tests
} catch (error) {}
},
getCollocationDataCompleteness: async (req, res, next) => {
try {

Check warning on line 139 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L139

Added line #L139 was not covered by tests
} catch (error) {}
},
getCollocationDataStatistics: async (req, res, next) => {
try {

Check warning on line 143 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L143

Added line #L143 was not covered by tests
} catch (error) {}
},
getCollocationIntraSensorCorrelation: async (req, res, next) => {
try {

Check warning on line 147 in src/device-registry/controllers/create-collocation.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/controllers/create-collocation.js#L147

Added line #L147 was not covered by tests
} catch (error) {}
},
};

module.exports = collocationController;
2 changes: 1 addition & 1 deletion src/device-registry/models/CollocationBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const collocationBatchSchema = new Schema(
type: Schema.Types.Mixed,
default: null,
},
errors: {
issues: {
type: [String],
default: [],
},
Expand Down
5 changes: 4 additions & 1 deletion src/device-registry/models/DeviceBattery.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const { HttpError } = require("@utils/errors");
const isEmpty = require("is-empty");
const constants = require("@config/constants");
const { getModelByTenant } = require("@config/database");
const logger = require("@utils/logger");
const log4js = require("log4js");
const logger = log4js.getLogger(
`${constants.ENVIRONMENT} -- device_battery model`
);
const BigQuery = require("@google-cloud/bigquery");

const deviceBatterySchema = new Schema(
Expand Down
5 changes: 4 additions & 1 deletion src/device-registry/models/DeviceStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const { HttpError } = require("@utils/errors");
const isEmpty = require("is-empty");
const constants = require("@config/constants");
const { getModelByTenant } = require("@config/database");
const logger = require("@utils/logger");
const log4js = require("log4js");
const logger = log4js.getLogger(
`${constants.ENVIRONMENT} -- device_status model`
);

const deviceStatusSchema = new Schema(
{
Expand Down
5 changes: 4 additions & 1 deletion src/device-registry/models/DeviceUptime.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const { HttpError } = require("@utils/errors");
const isEmpty = require("is-empty");
const constants = require("@config/constants");
const { getModelByTenant } = require("@config/database");
const logger = require("@utils/logger");
const log4js = require("log4js");
const logger = log4js.getLogger(
`${constants.ENVIRONMENT} -- device_uptime model`
);

const deviceUptimeSchema = new Schema(
{
Expand Down
5 changes: 4 additions & 1 deletion src/device-registry/models/NetworkUptime.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const { HttpError } = require("@utils/errors");
const isEmpty = require("is-empty");
const constants = require("@config/constants");
const { getModelByTenant } = require("@config/database");
const logger = require("@utils/logger");
const log4js = require("log4js");
const logger = log4js.getLogger(
`${constants.ENVIRONMENT} -- network_uptime model`
);

const networkUptimeSchema = new Schema(
{
Expand Down
14 changes: 2 additions & 12 deletions src/device-registry/routes/v2/collocations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const express = require("express");
const router = express.Router();
const collocationController = require("@controllers/collocation");
const { validateToken } = require("@middleware/auth");
const collocationController = require("@controllers/create-collocation");
const {
validateCollocationBatch,
validateCollocationParams,
Expand All @@ -14,23 +13,20 @@ router.get("/export-collection", collocationController.exportCollocationData);
// Create Collocation Batch Route
router.post(
"",
validateToken,
validateCollocationBatch,
collocationController.saveCollocationBatch
);

// Delete Collocation Batch Route
router.delete(
"",
validateToken,
"/",
validateCollocationParams,
collocationController.deleteCollocationBatch
);

// Reset Collocation Batch Route
router.patch(
"/reset",
validateToken,
validateCollocationParams,
validateCollocationReset,
collocationController.resetCollocationBatch
Expand All @@ -39,7 +35,6 @@ router.patch(
// Get Collocation Batch Route
router.get(
"",
validateToken,
validateCollocationParams,
collocationController.getCollocationBatch
);
Expand All @@ -50,39 +45,34 @@ router.get("/summary", collocationController.getCollocationSummary);
// Get Collocation Batch Data Route
router.get(
"/data",
validateToken,
validateCollocationParams,
collocationController.getCollocationBatchData
);

// Get Collocation Batch Results Route
router.get(
"/results",
validateToken,
validateCollocationParams,
collocationController.getCollocationBatchResults
);

// Get Collocation Data Completeness Route
router.get(
"/data-completeness",
validateToken,
validateCollocationParams,
collocationController.getCollocationDataCompleteness
);

// Get Collocation Data Statistics Route
router.get(
"/statistics",
validateToken,
validateCollocationParams,
collocationController.getCollocationDataStatistics
);

// Get Collocation Intra Sensor Correlation Route
router.get(
"/intra",
validateToken,
validateCollocationParams,
collocationController.getCollocationIntraSensorCorrelation
);
Expand Down
2 changes: 1 addition & 1 deletion src/device-registry/validators/collocation.validators.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { body, query, validationResult } = require("express-validator");
const httpStatus = require("http-status");
const { HttpError } = require("@utils/errors");
const { CollocationDefaults } = require("@models/collocation");
const CollocationBatchModel = require("@models/CollocationBatch");

const validateErrorMiddleware = (req, res, next) => {
const errors = validationResult(req);
Expand Down
9 changes: 8 additions & 1 deletion src/device-registry/validators/uptime.validators.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const { body, param, query, validationResult } = require("express-validator");
const {
body,
param,
query,
validationResult,
oneOf,
} = require("express-validator");

const moment = require("moment");
const httpStatus = require("http-status");
const { HttpError } = require("@utils/errors");
Expand Down

0 comments on commit 534690c

Please sign in to comment.