Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getUser(username: string) {
// Already fetched, then query locally
let alreadyFetched = this.fetchedUsers.indexOf(username) > -1;
let query = EntityQuery
.from("Users")
.expand("ResourcePoolSet")
.where("UserName", "eq", username);
// From server or local?
if (alreadyFetched) {
query = query.using(FetchStrategy.FromLocalCache);
} else {
query = query.using(FetchStrategy.FromServer);
}
return this.executeQuery(query)
.map((response: any) => {
// If there is no result
if (response.results.length === 0) {
return null;
}
var user = response.results[0];
// Add to fetched list
if (!alreadyFetched) {
if (this.dataService.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 Predicate("User.UserName", "eq", resourcePoolUniqueKey.username);
var resourcePoolKeyPredicate = new Predicate("Key", "eq", resourcePoolUniqueKey.resourcePoolKey);
query = query.where(userNamePredicate.and(resourcePoolKeyPredicate));
// From server or local?
if (!fetchedEarlier) {
query = query.using(FetchStrategy.FromServer);
} else {
query = query.using(FetchStrategy.FromLocalCache);
}
return this.dataService.executeQuery(query)
.map((response: any): any => {
// If there is no cmrp with this Id, return null
if (response.results.length === 0) {
return null;
}
// ResourcePool
var resourcePool = response.results[0];
// Todo Is there a better way of doing this? / coni2k - 25 Feb. '17
// Events handlers
resourcePool.ElementSet.forEach((element: Element) => {
getUser(username: string) {
// Already fetched, then query locally
let alreadyFetched = this.fetchedUsers.indexOf(username) > -1;
let query = EntityQuery
.from("Users")
.expand("ResourcePoolSet")
.where("UserName", "eq", username);
// From server or local?
if (alreadyFetched) {
query = query.using(FetchStrategy.FromLocalCache);
} else {
query = query.using(FetchStrategy.FromServer);
}
return this.executeQuery(query)
.map((response: any) => {
// If there is no result
if (response.results.length === 0) {
return null;
}
var user = response.results[0];
// Add to fetched list
if (!alreadyFetched) {