How to use the breeze-client.EntityQuery function in breeze-client

To help you get started, we’ve selected a few breeze-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github forCrowd / WealthFramework / ngClient / _system / js / app / factories / resourcePoolFactory.ts View on Github external
function getResourcePoolExpanded(resourcePoolUniqueKey: any) {

        // TODO Validations?

        var currentUser = dataContext.getCurrentUser();

        var fetchedEarlier = false;

        // If it"s not newly created, check the fetched list
        fetchedEarlier = fetchedList.some(fetched => (resourcePoolUniqueKey === fetched));

        // Prepare the query
        var query = breeze.EntityQuery.from("ResourcePool");

        // Is authorized? No, then get only the public data, yes, then get include user"s own records
        if (currentUser.isAuthenticated()) {
            query = query.expand("User, UserResourcePoolSet, ElementSet.ElementFieldSet.UserElementFieldSet, ElementSet.ElementItemSet.ElementCellSet.UserElementCellSet");
        } else {
            query = query.expand("User, ElementSet.ElementFieldSet, ElementSet.ElementItemSet.ElementCellSet");
        }

        var userNamePredicate = new breeze.Predicate("User.UserName", "eq", resourcePoolUniqueKey.userName);
        var resourcePoolKeyPredicate = new breeze.Predicate("Key", "eq", resourcePoolUniqueKey.resourcePoolKey);

        query = query.where(userNamePredicate.and(resourcePoolKeyPredicate));

        // From server or local?
        if (!fetchedEarlier) {
            query = query.using(breeze.FetchStrategy.FromServer);
github forCrowd / WealthFramework / ngClient / _system / js / app / factories / dataContext.ts View on Github external
metadataReady()
                    .then(() => {
                        currentUser = createGuestUser();
                        $rootScope.$broadcast("dataContext_currentUserChanged", currentUser);
                        deferred.resolve(currentUser);
                    })
                    .catch(() => {
                        // TODO Handle?
                        deferred.reject();
                    });

            } else {

                var token = angular.fromJson($window.localStorage.getItem("token"));
                var userName = token.userName;
                var query = breeze.EntityQuery
                    .from("Users")
                    .expand("ResourcePoolSet")
                    .where("UserName", "eq", userName)
                    .using(breeze.FetchStrategy.FromServer);

                executeQuery(query)
                    .then(success)
                    .catch(failed);
            }
        }

        return initializeCurrentUserPromise;

        function success(response: any) {

            // If the response has an entity, use that, otherwise create an anonymous user