@golemio/core 1.2.6-dev.503576573 → 1.2.6-dev.508166941
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.
- package/dist/input-gateway/helpers/SaveRawDataMiddleware.d.ts +8 -1
- package/dist/input-gateway/helpers/SaveRawDataMiddleware.js +28 -32
- package/dist/input-gateway/helpers/SaveRawDataMiddleware.js.map +1 -1
- package/dist/output-gateway/routes/AbstractHistoryRouter.d.ts +12 -0
- package/dist/output-gateway/routes/AbstractHistoryRouter.js +49 -0
- package/dist/output-gateway/routes/AbstractHistoryRouter.js.map +1 -0
- package/dist/output-gateway/routes/HistoryRouter.d.ts +3 -8
- package/dist/output-gateway/routes/HistoryRouter.js +4 -36
- package/dist/output-gateway/routes/HistoryRouter.js.map +1 -1
- package/dist/output-gateway/routes/interfaces/IHistoryFilterParameters.d.ts +7 -0
- package/dist/output-gateway/routes/interfaces/IHistoryFilterParameters.js +3 -0
- package/dist/output-gateway/routes/interfaces/IHistoryFilterParameters.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { S3 } from "aws-sdk";
|
|
1
2
|
import { NextFunction, Request, Response } from "express";
|
|
3
|
+
export declare const routesRegexp: RegExp;
|
|
4
|
+
export declare const headersRegexp: RegExp;
|
|
2
5
|
/**
|
|
3
|
-
* Middleware function
|
|
6
|
+
* Middleware function for saving raw data to file
|
|
4
7
|
*/
|
|
5
8
|
export declare const saveRawDataMiddleware: (req: Request, res: Response, next: NextFunction) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Helper function for saving data to S3
|
|
11
|
+
*/
|
|
12
|
+
export declare const uploadDataToS3: (data: S3.Types.PutObjectRequest, options: S3.ManagedUpload.ManagedUploadOptions, requestUrlPath: string) => void;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.saveRawDataMiddleware = void 0;
|
|
6
|
+
exports.uploadDataToS3 = exports.saveRawDataMiddleware = exports.headersRegexp = exports.routesRegexp = void 0;
|
|
7
7
|
const errors_1 = require("@golemio/errors");
|
|
8
8
|
const aws_sdk_1 = require("aws-sdk");
|
|
9
9
|
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
@@ -13,7 +13,7 @@ const helpers_1 = require("./");
|
|
|
13
13
|
// load all whitelisted datasets
|
|
14
14
|
let regexpRoutesString = "";
|
|
15
15
|
let regexpHeadersString = "";
|
|
16
|
-
config_1.config.saveRawDataWhitelist
|
|
16
|
+
for (const dataset of config_1.config.saveRawDataWhitelist) {
|
|
17
17
|
if (regexpRoutesString.length !== 0) {
|
|
18
18
|
regexpRoutesString += "|";
|
|
19
19
|
}
|
|
@@ -25,10 +25,10 @@ config_1.config.saveRawDataWhitelist.forEach((dataset) => {
|
|
|
25
25
|
}
|
|
26
26
|
regexpHeadersString += routeRegexp;
|
|
27
27
|
}
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
29
|
// regexp for matching all whitelisted datasets
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
exports.routesRegexp = regexpRoutesString !== "" ? RegExp(regexpRoutesString) : RegExp(/.^/);
|
|
31
|
+
exports.headersRegexp = regexpHeadersString !== "" ? RegExp(regexpHeadersString) : RegExp(/.^/);
|
|
32
32
|
const s3 = new aws_sdk_1.S3({
|
|
33
33
|
accessKeyId: config_1.config.s3.access_key_id,
|
|
34
34
|
endpoint: config_1.config.s3.endpoint,
|
|
@@ -37,24 +37,25 @@ const s3 = new aws_sdk_1.S3({
|
|
|
37
37
|
signatureVersion: "v4",
|
|
38
38
|
});
|
|
39
39
|
/**
|
|
40
|
-
* Middleware function
|
|
40
|
+
* Middleware function for saving raw data to file
|
|
41
41
|
*/
|
|
42
42
|
const saveRawDataMiddleware = (req, res, next) => {
|
|
43
|
+
const requestUrlPath = req.path;
|
|
43
44
|
// save file only if S3 is enabled and the method is POST and the url match one of whitelisted route
|
|
44
|
-
if (config_1.config.s3.enabled && req.method === "POST" && routesRegexp.exec(
|
|
45
|
+
if (config_1.config.s3.enabled && req.method === "POST" && exports.routesRegexp.exec(requestUrlPath)) {
|
|
45
46
|
// file name (path) in format {url}/{YYYY-MM-DD}/{HH_mm_ss.s}, e.g. mos-be/accounts/2020-04-17/12_59_42.456
|
|
46
47
|
const now = (0, moment_timezone_1.default)().tz("Europe/Prague");
|
|
47
|
-
const name = `${
|
|
48
|
+
const name = `${requestUrlPath.slice(1)}/${now.format("YYYY-MM-DD")}/${now.format("HH_mm_ss.SSS")}`;
|
|
48
49
|
// file extension by content-type
|
|
49
50
|
const contentType = (0, helpers_1.getContentType)(req);
|
|
50
51
|
const ext = helpers_1.contentTypeToExtension[contentType];
|
|
51
52
|
// content-type checking
|
|
52
53
|
if (!ext) {
|
|
53
|
-
errors_1.ErrorHandler.handle(new errors_1.CustomError(`Saving raw data failed. (${
|
|
54
|
+
errors_1.ErrorHandler.handle(new errors_1.CustomError(`Saving raw data failed. (${requestUrlPath})`, true, "SaveRawDataMiddleware", 406, new Error(`Extension for content-type ${contentType} was not found.`)));
|
|
54
55
|
return next();
|
|
55
56
|
}
|
|
56
57
|
// save file with body of the matched route
|
|
57
|
-
const
|
|
58
|
+
const dataPutRequest = {
|
|
58
59
|
Body: req,
|
|
59
60
|
Bucket: config_1.config.s3.bucket_name,
|
|
60
61
|
Key: `${name}.${ext}`,
|
|
@@ -63,36 +64,31 @@ const saveRawDataMiddleware = (req, res, next) => {
|
|
|
63
64
|
partSize: config_1.config.s3.upload_part_size * 1024 * 1024,
|
|
64
65
|
queueSize: config_1.config.s3.upload_queue_size,
|
|
65
66
|
};
|
|
66
|
-
|
|
67
|
-
if (err) {
|
|
68
|
-
errors_1.ErrorHandler.handle(
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
new errors_1.CustomError(`Saving raw data failed. (${req.url})`, true, "SaveRawDataMiddleware", err.statusCode, err));
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
.on("httpUploadProgress", (httpUploadProgress) => {
|
|
74
|
-
helpers_1.log.debug(`S3 file upload progress: ${httpUploadProgress.loaded} / ${httpUploadProgress.total}`);
|
|
75
|
-
})
|
|
76
|
-
.on("error", (err) => {
|
|
77
|
-
errors_1.ErrorHandler.handle(new errors_1.CustomError(`Saving raw data failed. (${req.url})`, true, "SaveRawDataMiddleware", err.statusCode, err));
|
|
78
|
-
});
|
|
67
|
+
(0, exports.uploadDataToS3)(dataPutRequest, options, requestUrlPath);
|
|
79
68
|
// save file with headers of the matched route
|
|
80
|
-
if (headersRegexp.exec(
|
|
81
|
-
const
|
|
69
|
+
if (exports.headersRegexp.exec(requestUrlPath)) {
|
|
70
|
+
const headersPutRequest = {
|
|
82
71
|
Body: JSON.stringify(req.headers),
|
|
83
72
|
Bucket: config_1.config.s3.bucket_name,
|
|
84
73
|
Key: `${name}_headers.json`,
|
|
85
74
|
};
|
|
86
|
-
|
|
87
|
-
if (err) {
|
|
88
|
-
errors_1.ErrorHandler.handle(new errors_1.CustomError(`Saving headers of raw data failed. (${req.url})`, true, "SaveRawDataMiddleware",
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
err.statusCode, err));
|
|
91
|
-
}
|
|
92
|
-
});
|
|
75
|
+
(0, exports.uploadDataToS3)(headersPutRequest, options, requestUrlPath);
|
|
93
76
|
}
|
|
94
77
|
}
|
|
95
78
|
next();
|
|
96
79
|
};
|
|
97
80
|
exports.saveRawDataMiddleware = saveRawDataMiddleware;
|
|
81
|
+
/**
|
|
82
|
+
* Helper function for saving data to S3
|
|
83
|
+
*/
|
|
84
|
+
const uploadDataToS3 = (data, options, requestUrlPath) => {
|
|
85
|
+
s3.upload(data, options, (err, _data) => {
|
|
86
|
+
if (err) {
|
|
87
|
+
errors_1.ErrorHandler.handle(new errors_1.CustomError(`Uploading data failed to S3 failed. (${requestUrlPath})`, true, "SaveRawDataMiddleware", err.statusCode, err));
|
|
88
|
+
}
|
|
89
|
+
}).on("httpUploadProgress", (httpUploadProgress) => {
|
|
90
|
+
helpers_1.log.debug(`S3 file upload progress: ${httpUploadProgress.loaded} / ${httpUploadProgress.total}`);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
exports.uploadDataToS3 = uploadDataToS3;
|
|
98
94
|
//# sourceMappingURL=SaveRawDataMiddleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SaveRawDataMiddleware.js","sourceRoot":"","sources":["../../../src/input-gateway/helpers/SaveRawDataMiddleware.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA4D;AAC5D,qCAA6B;AAE7B,sEAAqC;AACrC,mDAA8C;AAC9C,sCAAoC;AACpC,gCAA0E;
|
|
1
|
+
{"version":3,"file":"SaveRawDataMiddleware.js","sourceRoot":"","sources":["../../../src/input-gateway/helpers/SaveRawDataMiddleware.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA4D;AAC5D,qCAA6B;AAE7B,sEAAqC;AACrC,mDAA8C;AAC9C,sCAAoC;AACpC,gCAA0E;AAM1E,gCAAgC;AAChC,IAAI,kBAAkB,GAAG,EAAE,CAAC;AAC5B,IAAI,mBAAmB,GAAG,EAAE,CAAC;AAE7B,KAAK,MAAM,OAAO,IAAI,eAAM,CAAC,oBAAoB,EAAE;IAC/C,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE;QACjC,kBAAkB,IAAI,GAAG,CAAC;KAC7B;IACD,MAAM,WAAW,GAAG,IAAI,IAAA,6BAAY,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC;IAC9D,kBAAkB,IAAI,WAAW,CAAC;IAElC,IAAI,OAAO,CAAC,WAAW,EAAE;QACrB,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC,EAAE;YAClC,mBAAmB,IAAI,GAAG,CAAC;SAC9B;QACD,mBAAmB,IAA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AO,EAAE,CAAC,GAAqB,EAAE,KAAgC,EAAE,EAAE;QACjF,IAAI,GAAG,EAAE;YACL,qBAAY,CAAC,MAAM,CACf,IAAI,oBAAW,CACX,wCAAwC,cAAc,GAAG,EACzD,IAAI,EACJ,uBAAuB,EACvB,GAAG,CAAC,UAAU,EACd,GAAG,CACN,CACJ,CAAC;SACL;IACL,CAAC,CAAC,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,kBAAkB,EAAE,EAAE;QAC/C,aAAG,CAAC,KAAK,CAAC,4BAA4B,kBAAkB,CAAC,MAAM,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC,CAAC;IACrG,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AApBW,QAAA,cAAc,kBAoBzB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IBaseModel } from "../models/interfaces/IBaseModel";
|
|
2
|
+
import { BaseRouter } from "./BaseRouter";
|
|
3
|
+
import { NextFunction, Request, Response, Router } from "express";
|
|
4
|
+
import { ValidationChain } from "express-validator/check";
|
|
5
|
+
export declare abstract class AbstractHistoryRouter extends BaseRouter {
|
|
6
|
+
router: Router;
|
|
7
|
+
protected model: IBaseModel;
|
|
8
|
+
constructor(inModel: IBaseModel);
|
|
9
|
+
initRoutes: (expire?: string | number | undefined) => Promise<void>;
|
|
10
|
+
GetAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
11
|
+
protected abstract GetIdQueryParamWithCorrectType(): Promise<ValidationChain>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AbstractHistoryRouter = void 0;
|
|
13
|
+
const redis_1 = require("../redis");
|
|
14
|
+
const BaseRouter_1 = require("./BaseRouter");
|
|
15
|
+
const Validation_1 = require("../Validation");
|
|
16
|
+
const express_1 = require("express");
|
|
17
|
+
const check_1 = require("express-validator/check");
|
|
18
|
+
const lodash_1 = require("lodash");
|
|
19
|
+
class AbstractHistoryRouter extends BaseRouter_1.BaseRouter {
|
|
20
|
+
constructor(inModel) {
|
|
21
|
+
super();
|
|
22
|
+
// Assign router to the express.Router() instance
|
|
23
|
+
this.router = (0, express_1.Router)();
|
|
24
|
+
this.initRoutes = (expire) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const sensorIdParam = yield this.GetIdQueryParamWithCorrectType();
|
|
26
|
+
this.router.get("/", (0, redis_1.useCacheMiddleware)(expire), [(0, check_1.query)("from").optional().isISO8601(), (0, check_1.query)("to").optional().isISO8601(), sensorIdParam], Validation_1.pagination, (0, Validation_1.paginationLimitMiddleware)("HistoryRouter"), Validation_1.checkErrors, this.GetAll);
|
|
27
|
+
});
|
|
28
|
+
this.GetAll = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const timestampFrom = new Date(req.query.from).getTime();
|
|
30
|
+
const timestampTo = new Date(req.query.to).getTime();
|
|
31
|
+
try {
|
|
32
|
+
const data = yield this.model.GetAll({
|
|
33
|
+
from: timestampFrom,
|
|
34
|
+
limit: (0, lodash_1.toNumber)(req.query.limit),
|
|
35
|
+
offset: (0, lodash_1.toNumber)(req.query.offset),
|
|
36
|
+
sensorId: req.query.sensorId,
|
|
37
|
+
to: timestampTo,
|
|
38
|
+
});
|
|
39
|
+
res.status(200).send(data);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
next(err);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.model = inModel;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.AbstractHistoryRouter = AbstractHistoryRouter;
|
|
49
|
+
//# sourceMappingURL=AbstractHistoryRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractHistoryRouter.js","sourceRoot":"","sources":["../../../src/output-gateway/routes/AbstractHistoryRouter.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAA+C;AAC/C,6CAAmD;AACnD,8CAAoF;AACpF,qCAAkE;AAClE,mDAAiE;AACjE,mCAAkC;AAElC,MAAsB,qBAAsB,SAAQ,uBAAU;IAM1D,YAAmB,OAAmB;QAClC,KAAK,EAAE,CAAC;QANZ,iDAAiD;QAC1C,WAAM,GAAW,IAAA,gBAAM,GAAE,CAAC;QAS1B,eAAU,GAAG,CAAO,MAAwB,EAAE,EAAE;YACnD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,8BAA8B,EAAE,CAAC;YAClE,IAAI,CAAC,MAAM,CAAC,GAAG,CACX,GAAG,EACH,IAAA,0BAAkB,EAAC,MAAM,CAAC,EAC1B,CAAC,IAAA,aAAK,EAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE,aAAa,CAAC,EACzF,uBAAU,EACV,IAAA,sCAAyB,EAAC,eAAe,CAAC,EAC1C,wBAAW,EACX,IAAI,CAAC,MAAM,CACd,CAAC;QACN,CAAC,CAAA,CAAC;QAEK,WAAM,GAAG,CAAO,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;YACtE,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAc,CAAC,CAAC,OAAO,EAAE,CAAC;YACnE,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAY,CAAC,CAAC,OAAO,EAAE,CAAC;YAE/D,IAAI;gBACA,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;oBACjC,IAAI,EAAE,aAAa;oBACnB,KAAK,EAAE,IAAA,iBAAQ,EAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC;oBAChC,MAAM,EAAE,IAAA,iBAAQ,EAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC;oBAClC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,QAAkB;oBACtC,EAAE,EAAE,WAAW;iBAClB,CAAC,CAAC;gBAEH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC9B;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,CAAC,GAAG,CAAC,CAAC;aACb;QACL,CAAC,CAAA,CAAC;QAjCE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;IACzB,CAAC;CAmCJ;AA5CD,sDA4CC"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { NextFunction, Request, Response, Router } from "express";
|
|
2
|
-
import { ValidationChain } from "express-validator/check";
|
|
3
1
|
import { HistoryModel } from "../models";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
protected model: HistoryModel;
|
|
2
|
+
import { ValidationChain } from "express-validator/check";
|
|
3
|
+
import { AbstractHistoryRouter } from "./AbstractHistoryRouter";
|
|
4
|
+
export declare class HistoryRouter extends AbstractHistoryRouter {
|
|
8
5
|
constructor(inModel: HistoryModel);
|
|
9
|
-
initRoutes: (expire?: string | number | undefined) => Promise<void>;
|
|
10
|
-
GetAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
11
6
|
protected GetIdQueryParamWithCorrectType: () => Promise<ValidationChain>;
|
|
12
7
|
}
|
|
@@ -10,44 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.HistoryRouter = void 0;
|
|
13
|
-
const
|
|
13
|
+
const Logger_1 = require("../Logger");
|
|
14
14
|
const check_1 = require("express-validator/check");
|
|
15
15
|
const mongoose_1 = require("mongoose");
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const redis_1 = require("../redis");
|
|
19
|
-
const Validation_1 = require("../Validation");
|
|
20
|
-
const BaseRouter_1 = require("./BaseRouter");
|
|
21
|
-
class HistoryRouter extends BaseRouter_1.BaseRouter {
|
|
16
|
+
const AbstractHistoryRouter_1 = require("./AbstractHistoryRouter");
|
|
17
|
+
class HistoryRouter extends AbstractHistoryRouter_1.AbstractHistoryRouter {
|
|
22
18
|
constructor(inModel) {
|
|
23
|
-
super();
|
|
24
|
-
// Assign router to the express.Router() instance
|
|
25
|
-
this.router = (0, express_1.Router)();
|
|
26
|
-
this.initRoutes = (expire) => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const sensorIdParam = yield this.GetIdQueryParamWithCorrectType();
|
|
28
|
-
this.router.get("/", (0, redis_1.useCacheMiddleware)(expire), [(0, check_1.query)("from").optional().isISO8601(), (0, check_1.query)("to").optional().isISO8601(), sensorIdParam], Validation_1.pagination, (0, Validation_1.paginationLimitMiddleware)("HistoryRouter"), Validation_1.checkErrors, this.GetAll);
|
|
29
|
-
});
|
|
30
|
-
this.GetAll = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const timestampFrom = new Date(req.query.from).getTime();
|
|
32
|
-
const timestampTo = new Date(req.query.to).getTime();
|
|
33
|
-
let sensorIds = req.query.ids;
|
|
34
|
-
if (sensorIds) {
|
|
35
|
-
sensorIds = this.ConvertToArray(sensorIds);
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
const data = yield this.model.GetAll({
|
|
39
|
-
from: timestampFrom,
|
|
40
|
-
limit: (0, lodash_1.toNumber)(req.query.limit),
|
|
41
|
-
offset: (0, lodash_1.toNumber)(req.query.offset),
|
|
42
|
-
sensorId: req.query.sensorId,
|
|
43
|
-
to: timestampTo,
|
|
44
|
-
});
|
|
45
|
-
res.status(200).send(data);
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
next(err);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
19
|
+
super(inModel);
|
|
51
20
|
this.GetIdQueryParamWithCorrectType = () => __awaiter(this, void 0, void 0, function* () {
|
|
52
21
|
let sensorIdParam;
|
|
53
22
|
// @ts-ignore
|
|
@@ -71,7 +40,6 @@ class HistoryRouter extends BaseRouter_1.BaseRouter {
|
|
|
71
40
|
return sensorIdParam;
|
|
72
41
|
});
|
|
73
42
|
});
|
|
74
|
-
this.model = inModel;
|
|
75
43
|
}
|
|
76
44
|
}
|
|
77
45
|
exports.HistoryRouter = HistoryRouter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HistoryRouter.js","sourceRoot":"","sources":["../../../src/output-gateway/routes/HistoryRouter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"HistoryRouter.js","sourceRoot":"","sources":["../../../src/output-gateway/routes/HistoryRouter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAiC;AAEjC,mDAAiE;AACjE,uCAAkC;AAClC,mEAAgE;AAEhE,MAAa,aAAc,SAAQ,6CAAqB;IACpD,YAAmB,OAAqB;QACpC,KAAK,CAAC,OAAO,CAAC,CAAC;QAGT,mCAA8B,GAAG,GAAmC,EAAE;YAC5E,IAAI,aAA8B,CAAC;YACnC,aAAa;YACb,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBAChD,gEAAgE;gBAChE,MAAM,KAAK,GAAI,IAAI,CAAC,KAAsB,CAAC,+BAA+B,CAAC;gBAC3E,IAAI,OAAO,GAAW,wBAAwB,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,qBAAqB,GAAG,KAAK,GAAG,YAAY,CAAC;gBACrH,mDAAmD;gBACnD,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,iBAAM,CAAC,KAAK,CAAC,MAAM,EAAE;oBACnD,OAAO,IAAI,SAAS,CAAC;oBACrB,oGAAoG;oBACpG,aAAa,GAAG,IAAA,aAAK,EAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,CAAC;oBAC3D,mDAAmD;iBACtD;qBAAM;oBACH,OAAO,IAAI,SAAS,CAAC;oBACrB,oGAAoG;oBACpG,aAAa,GAAG,IAAA,aAAK,EAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC;iBAC7D;gBACD,YAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACnB,OAAO,aAAa,CAAC;YACzB,CAAC,CAAC,CAAC;QACP,CAAC,CAAA,CAAC;IAvBF,CAAC;CAwBJ;AA3BD,sCA2BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IHistoryFilterParameters.js","sourceRoot":"","sources":["../../../../src/output-gateway/routes/interfaces/IHistoryFilterParameters.ts"],"names":[],"mappings":""}
|