Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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