<commit_before>const mongoose = require('mongoose');
const logger = require('../../lib/logger');
const adminChecker = require('../helpers/auth/request_admin_checker');
const langUtil = require('../helpers/language/lang_util');
const enterpriseInternationalPublicModel = mongoose.model('EnterpriseInternationalPublic');
const pendingEnterpriseInternationalPublicModel = mongoose.model('PendingEnterpriseInternationalPublic');
const unpublishedEnterpriseInternationalPublicModel = mongoose.model('UnpublishedEnterpriseInternationalPublic');

module.exports.getAccountEnterpriseSummary = function(req, res) {
  let language = langUtil.getLanguage(req);

  if (!adminChecker.isLoggedIn(req)) {
    res.status(403).json({'message': 'Not logged in'});
    return;
  }

  if (adminChecker.isRequestDirectoryAdmin(req)) {
    handleEnterpriseSummary(language)
      .then(summary => {res.status(200).json(summary);})
      .catch(err => {
        logger.error('Error handling directory admin enterprise summary ', err);
        res.status(500).json({'message': err});
      });
    return;
  }

  let enterprisePermissions = adminChecker.getAuthenticatedEnterprisesByRequest(req);
  let query = {'_id': { $in: enterprisePermissions}};
  handleEnterpriseSummary(language, query)
    .then(summary => {res.status(200).json(summary);})
    .catch(err => {
      logger.error('Error handling enterprise admin enterprise summary ', err);
      res.status(500).json({'message': err});
    });
};

function handleEnterpriseSummary(language, query) {
  return new Promise( (resolve, reject) => {
    let summary = {
      published: [],<commit_msg>fix enterprise admin flow<commit_after>const mongoose = require('mongoose');
const logger = require('../../lib/logger');
const adminChecker = require('../helpers/auth/request_admin_checker');
const langUtil = require('../helpers/language/lang_util');
const enterpriseInternationalPublicModel = mongoose.model('EnterpriseInternationalPublic');
const pendingEnterpriseInternationalPublicModel = mongoose.model('PendingEnterpriseInternationalPublic');
const unpublishedEnterpriseInternationalPublicModel = mongoose.model('UnpublishedEnterpriseInternationalPublic');

module.exports.getAccountEnterpriseSummary = function(req, res) {
  let language = langUtil.getLanguage(req);

  if (!adminChecker.isLoggedIn(req)) {
    res.status(403).json({'message': 'Not logged in'});
    return;
  }

  if (adminChecker.isRequestDirectoryAdmin(req)) {
    handleEnterpriseSummary(language)
      .then(summary => {res.status(200).json(summary);})
      .catch(err => {
        logger.error('Error handling directory admin enterprise summary ', err);
        res.status(500).json({'message': err});
      });
    return;
  }

  let enterprisePermissions = adminChecker.getAuthenticatedEnterprisesByRequest(req);
  let query = {'_id': { $in: enterprisePermissions.map(v => v.id)}};
  handleEnterpriseSummary(language, query)
    .then(summary => {res.status(200).json(summary);})
    .catch(err => {
      logger.error('Error handling enterprise admin enterprise summary ', err);
      res.status(500).json({'message': err});
    });
};

function handleEnterpriseSummary(language, query) {
  return new Promise( (resolve, reject) => {
    let summary = {
      published: [],
{'fraction_non_alphanumeric': 0.14159829838954724, 'fraction_numerical': 0.009115770282588878, 'mean_word_length': 5.118959107806692, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6639466', 'n_tokens_mistral': 916, 'n_tokens_neox': 903, 'n_words': 170}