-
-
Save eirikb/dfd50d981b9e189c68aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var usersUrl = "/_api/Web/SiteUsers"; | |
function getItem(res) { | |
return res.data.value; | |
} | |
$q.all({ | |
first: $http.get(usersUrl, { params: { $orderBy: "ID", $top: 1, $select: "Id" }}).then(getItem), | |
last: $http.get(usersUrl, { params: { $orderBy: "ID desc", $top: 1, $select: "Id" }}).then(getItem) | |
}).then(function(res){ | |
console.log(res.first[0].Id, res.last[0].Id); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// !!! UPDATE !!! | |
// New full example using Angular and lodash | |
var usersUrl = "/_api/Web/SiteUsers"; | |
function getItem(res) { | |
return res.data.value[0].Id; | |
} | |
var q = { params: { $orderBy: "Id", $top: 1, $select: "Id", $filter: "Id le 100000" }}; | |
$q.all({ | |
first: $http.get(usersUrl, q).then(getItem), | |
last: $http.get(usersUrl, _.defaultsDeep({ params: { $orderBy: "Id desc" }}, q)).then(getItem) | |
}).then(function(res){ | |
var idPool = _.range(res.first, res.last + 1); | |
return _().range(5).map(function(i) { | |
var idIndex = _.random(idPool.length - 1); | |
return idPool.splice(idIndex, 1)[0]; | |
}).value(); | |
}).then(function(fiveRandomIds) { | |
console.log(fiveRandomIds); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment