UNPKG

@golemio/parkings

Version:
55 lines 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parkingsRouter = exports.KoridParkingsRouter = void 0; const helpers_1 = require("@golemio/core/dist/input-gateway/helpers"); const express_1 = require("@golemio/core/dist/shared/express"); const _1 = require("./"); class KoridParkingsRouter { constructor() { /** * Initiates all routes. Should respond with correct data to a HTTP requests to all routes. */ this.initRoutes = () => { this.router.post("/config", (0, helpers_1.checkContentTypeMiddleware)(["application/json"]), this.PostConfig); this.router.post("/data", (0, helpers_1.checkContentTypeMiddleware)(["application/json"]), this.PostData); }; this.PostConfig = async (req, res, next) => { try { await this.configController.processData(req.body); // logging number of records const dataToEmit = { numberOfRecords: req.body.geojson.features.length, req, }; helpers_1.loggerEvents.emit(helpers_1.LoggerEventType.NumberOfRecords, dataToEmit); res.sendStatus(204); } catch (err) { next(err); } }; this.PostData = async (req, res, next) => { try { await this.dataController.processData(req.body); // logging number of records const dataToEmit = { numberOfRecords: Object.keys(req.body.data).length, req, }; helpers_1.loggerEvents.emit(helpers_1.LoggerEventType.NumberOfRecords, dataToEmit); res.sendStatus(204); } catch (err) { next(err); } }; this.router = (0, express_1.Router)(); this.configController = new _1.KoridParkingsConfigController(); this.dataController = new _1.KoridParkingsDataController(); this.initRoutes(); } } exports.KoridParkingsRouter = KoridParkingsRouter; const parkingsRouter = new KoridParkingsRouter().router; exports.parkingsRouter = parkingsRouter; //# sourceMappingURL=KoridParkingsRouter.js.map