Skip to content

Instantly share code, notes, and snippets.

@colwem
Created March 28, 2016 21:29
Show Gist options
  • Save colwem/297495e5e9398fbf9e6e to your computer and use it in GitHub Desktop.
Save colwem/297495e5e9398fbf9e6e to your computer and use it in GitHub Desktop.
myApi.getProductionData = function(case_id) {
return new Promise(function(resolve, reject){
myApi.getToken().then(function(response) {
var data_json = '';
sagent
.get(myApi.url + '/v1/cases/' + case_id + '/productionSets/')
.set('Content-Type', 'application/json')
.set('Content-Length', data_json.length)
.set('my-auth-token', response)
.end(function(err, res) {
if(err) {
return reject(err);
}
// resolve(res);
var tmpres = JSON.parse(res['text']);
var productions = [];
Promise.map(tmpres, function(prod) {
var data_json = '';
return new Promise(function(resolve, reject) {
sagent
.get(myApi.url + '/v1/cases/' + case_id + '/productionSets/' + prod.guid + '/items')
.set('Content-Type', 'application/json')
.set('Content-Length', data_json.length)
.set('my-auth-token', response)
.end(function(err2, res2) {
if(err2) {
return reject(err2);
}
var tmpprod = JSON.parse(res2['text']);
console.log(tmpprod);
resolve(tmpprod);
});
});
}).then(function(the_data) {
console.log(the_data);
resolve(the_data);
});
});
}).catch(function(failure) {
return_data = {
"status" : "error",
"api_server" : "my",
"message" : failure
};
reject(return_data);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment