Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
} else {
query = query.using(breeze.FetchStrategy.FromLocalCache);
}
return dataContext.executeQuery(query)
.then(success)
.catch(failed);
function success(response: any) {
// If there is no cmrp with this Id, return null
if (response.results.length === 0) {
return null;
}
// ResourcePool
var resourcePool = response.results[0];
function getResourcePoolSet(searchKey: any) {
searchKey = typeof searchKey !== "undefined" ? searchKey : "";
var query = breeze.EntityQuery
.from("ResourcePool")
.expand(["User"]);
if (searchKey !== "") {
var resourcePoolNamePredicate = new breeze.Predicate("Name", "contains", searchKey);
var userNamePredicate = new breeze.Predicate("User.UserName", "contains", searchKey);
query = query.where(resourcePoolNamePredicate.or(userNamePredicate));
}
// Prepare the query
//if (fetchFromServer) { // From remote
query = query.using(breeze.FetchStrategy.FromServer);
// fetchFromServer = false; // Do it only once per user
//}
//else { // From local
//query = query.using(breeze.FetchStrategy.FromLocalCache);
//}
return dataContext.executeQuery(query)
.then(success).catch(failed);
function success(response: any) {
return response.results;
}
function failed(error: any) {
var message = error.message || "ResourcePool query failed";
logger.logError(message, error, true);
function getUser(userName: any) {
// Already fetched, then query locally
var alreadyFetched = fetchedUsers.some(fetched => (userName === fetched));
var query = breeze.EntityQuery
.from("Users")
.expand("ResourcePoolSet")
.where("UserName", "eq", userName);
// From server or local?
if (alreadyFetched) {
query = query.using(breeze.FetchStrategy.FromLocalCache);
} else {
query = query.using(breeze.FetchStrategy.FromServer);
}
return executeQuery(query)
.then(success)
.catch(failed);
function success(response: any);
function success(response) {
// If there is no result
if (response.results.length === 0) {
return null;
}
var user = response.results[0];
function getUser(userName: any) {
// Already fetched, then query locally
var alreadyFetched = fetchedUsers.some(fetched => (userName === fetched));
var query = breeze.EntityQuery
.from("Users")
.expand("ResourcePoolSet")
.where("UserName", "eq", userName);
// From server or local?
if (alreadyFetched) {
query = query.using(breeze.FetchStrategy.FromLocalCache);
} else {
query = query.using(breeze.FetchStrategy.FromServer);
}
return executeQuery(query)
.then(success)
.catch(failed);
function success(response: any);
function success(response) {
// If there is no result
if (response.results.length === 0) {
return null;
}