Skip to content

Instantly share code, notes, and snippets.

@eirikb
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eirikb/dfd50d981b9e189c68aa to your computer and use it in GitHub Desktop.
Save eirikb/dfd50d981b9e189c68aa to your computer and use it in GitHub Desktop.
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);
});
// !!! 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