@golemio/core 1.2.6-dev.507011079 → 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/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
|
@@ -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":""}
|