all files / express-stormpath/lib/helpers/ get-required-registration-fields.js

90.91% Statements 10/11
83.33% Branches 10/12
100% Functions 3/3
90.91% Lines 10/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                  21×   21×       21× 153× 77× 77×     153×   21×      
'use strict';
 
var async = require('async');
 
/**
 * @private
 * @callback getRequiredRegistrationFieldsCallback
 * @param {Array} fields - An array of required field names (as strings). Might
 *  be empty if the user explicitly disables all fields in the configuration.
 */
 
/**
 * Gets a list of required registration fields.
 *
 * @param {Object} config - The Stormpath Configuration object.
 * @param {getRequiredRegistrationFieldsCallback} callback - The callback to
 *  run.
 */
module.exports = function (config, callback) {
  var fields = [];
 
  Iif (!config || !config.web || !config.web.register) {
    return callback([]);
  }
 
  async.forEachOf(config.web.register.form.fields || {}, function (field, fieldName, cb) {
    if (field && field.enabled && field.required) {
      field.name = fieldName;
      fields.push(field);
    }
 
    cb();
  }, function () {
    callback(fields);
  });
};