UNPKG

@golemio/energetics

Version:
48 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.preInputRouter = exports.PreInputRouter = void 0; const express_1 = require("@golemio/core/dist/shared/express"); const helpers_1 = require("@golemio/core/dist/input-gateway/helpers"); const PreJsonInputController_1 = require("./PreJsonInputController"); const PreDataExtractor_1 = require("../helpers/PreDataExtractor"); const ioc_1 = require("@golemio/core/dist/input-gateway/ioc"); const PreCsvInputController_1 = require("./PreCsvInputController"); const PreCsvInputTransformation_1 = require("../transformations/PreCsvInputTransformation"); class PreInputRouter { constructor() { this.initRoutes = () => { this.router.post("/", (0, helpers_1.checkContentTypeMiddleware)(["application/json"]), this.postPreJson); this.router.post("/csv", (0, helpers_1.checkContentTypeMiddleware)(["text/csv"]), this.csvParser.getMiddleware({ delimiter: ";", shouldIncludeHeaders: true, }), this.postPreCsv); }; this.postPreJson = async (req, res, next) => { try { await this.jsonInputController.processData(req.body); res.sendStatus(204); } catch (err) { next(err); } }; this.postPreCsv = async (req, res, next) => { try { await this.csvInputController.processData(req.body); res.sendStatus(204); } catch (err) { next(err); } }; this.router = (0, express_1.Router)(); this.jsonInputController = new PreJsonInputController_1.PreJsonInputController(new PreDataExtractor_1.PreDataExtractor()); this.csvInputController = new PreCsvInputController_1.PreCsvInputController(new PreCsvInputTransformation_1.PreCsvInputTransformation()); this.csvParser = ioc_1.InputGatewayContainer.resolve(ioc_1.ContainerToken.CsvParserMiddleware); this.initRoutes(); } } exports.PreInputRouter = PreInputRouter; const preInputRouter = new PreInputRouter().router; exports.preInputRouter = preInputRouter; //# sourceMappingURL=PreInputRouter.js.map