Source: controllers/Struct.js

'use strict';

/**
 * @module controller
 * API controller for methods mapping.
 * @license MIT
 * @author Kai KRETSCHMANN <kai@kretschmann.consulting>
 */

const log4js = require("log4js");
const logger = log4js.getLogger();
logger.level = process.env.LOGLEVEL || "warn";

const utils = require('../utils/writer.js');
const feature = require('../utils/feature.js');
const eventEmitter = require('../utils/eventer').em;
const Struct = require('../service/StructService');


/**
 * @method
 * Expose API lorem ipsum.
 * @public
 */
module.exports.getStructure = function getStructure(req, res, next) {
    const amount = req.swagger.params['amount'].value;
    const format = req.swagger.params['format'].value;

    if(feature.isEnabled(req, 'apihit')) {
        eventEmitter.emit('apihit', req);
    }

    Struct.getStructure(amount, format)
        .then(function(payload) {
            utils.writeJson(res, payload);
        })
        .catch(function(payload) {
            utils.writeText(res, payload, 400);
        });
};