all files / express-stormpath/lib/helpers/ stripped-account-response.js

100% Statements 8/8
100% Branches 4/4
100% Functions 2/2
100% Lines 8/8
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                      14× 14× 378× 197×     14×        
'use strict';
 
var _ = require('lodash');
 
/**
 * Respond with an account object, but strips all of the linked resources.
 *
 * @function
 *
 * @param {Object} account - The stormpath account object.
 * @param {Object} req - The http request.
 */
function strippedAccountResponse(account, res) {
  var strippedAccount = _.clone(account);
  Object.keys(strippedAccount).forEach(function (property) {
    if (strippedAccount[property] && strippedAccount[property].href) {
      delete strippedAccount[property];
    }
  });
  res.json({
    account: strippedAccount
  });
}
 
module.exports = strippedAccountResponse;