"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ConfigurationController = void 0;

var _lodash = _interopRequireDefault(require("lodash"));

var _typescriptRoutesToOpenapiServer = require("typescript-routes-to-openapi-server");

var _auth = require("../auth");

var _globalSettings = require("../repository/globalSettings");

var _user = require("../repository/user");

var _config = require("../config");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * @openapi_tags Configuration
 */
class ConfigurationController {
  /**
   * @openapi_operationId update
   */
  update = (0, _typescriptRoutesToOpenapiServer.createExpressRoute)(_auth.onlyForAdmin, async (req, res) => {
    await _globalSettings.configurationRepository.update(req.body);
    res.send();
  });
  /**
   * @openapi_operationId get
   */

  get = (0, _typescriptRoutesToOpenapiServer.createExpressRoute)(async (req, res) => {
    const configuration = await _globalSettings.configurationRepository.findOne();
    const numberOfUsers = await _user.userRepository.count();
    res.send({ ..._lodash.default.omit(configuration, 'id'),
      noUsers: numberOfUsers === 0,
      demo: _config.Config.DEMO,
      version: _config.Config.version
    });
  });
}

exports.ConfigurationController = ConfigurationController;
//# sourceMappingURL=configuration.js.map