How to get currently logged in user details from Promise object in jhipster based application
<p>I am trying to create 'Order' object in the front end and pushing it into the database using REST services. POJO of 'Order' looks like below</p>

<pre><code>@NotNull
@Field("total")
private BigDecimal total;

@Field("status")
private String status;

@Embedded
public User user;
</code></pre>

<p>Now I have a 'Principal' service which is providing information of the currently logged in user.I have tried 'console.log(Principal.identity())' which is returning result as shown below. Here 'User' data is present inside the '$$state' Object.<br>
<a href="https://i.stack.imgur.com/VS0sY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VS0sY.png" alt="enter image description here"></a>
 I am not able to find out how to take 'user' data from promise object and add to the 'Order' object. I have dirty method to get user data by digging inside the Promise object as shown below but I am skeptical about this method.
<a href="https://i.stack.imgur.com/92H8p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/92H8p.png" alt="enter image description here"></a> </p>

<p>What is the correct way to get data from Promise in this scenario?</p>

<p>EDIT:
This is jhipster based application. Below is the "Principle" service code </p>

<hr>

<pre><code>            'identity: function (force) {
            var deferred = $q.defer();

            if (force === true) {
                _identity = undefined;
            }

            // check and see if we have retrieved the identity data from the server.
            // if we have, reuse it by immediately resolving
            if (angular.isDefined(_identity)) {
                deferred.resolve(_identity);

                return deferred.promise;
            }

            // retrieve the identity data from the server, update the identity object, and then resolve.
            Account.get().$promise
                .then(function (account) {
                    _identity = account.data;
                    _authenticated = true;
                    deferred.resolve(_identity);
                    Tracker.connect();
                })
                .catch(function() {
                    _identity = null;
                    _authenticated = false;
                    deferred.resolve(_identity);
                });
            return deferred.promise;
        }'
</code></pre>

<p>Here is the jhipster generated method to receive resource from server using ngResource.</p>

<pre><code>'angular.module('hotSpiceApp')
.factory('Order', function ($resource, DateUtils) {
    return $resource('api/orders/:id', {}, {
        'query': { method: 'GET', isArray: true},
        'get': {
            method: 'GET',
            transformResponse: function (data) {
                data = angular.fromJson(data);
                return data;
            }
        },
        'update': { method:'PUT' }
    });
});'
</code></pre>