Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function request() {
- uservoiceRequest.get({
- url: "reports/user_satisfaction_responses.json",
- data: {
- page: 1,
- start_date: "2015-01-01T00:00:00-0600",
- end_date: moment().format()
- }
- }, function (err, respData) {
- if (err) return console.log(err)
- console.log(respData.pages)
- for (i = 1; i <= respData.pages; i++) {
- uservoiceRequest.get({
- url: "reports/user_satisfaction_responses.json",
- data: {
- page: i,
- start_date: "2015-01-01T00:00:00-0600",
- end_date: moment().format()
- }
- }, function (err, npsResp) {
- npsResp.responses.forEach(function (e) {
- if (e.id > 0) {
- myCollection.insert({
- created_at: new Date(e.created_at),
- body: e.body,
- score: e.score,
- id: e.id,
- user: {
- type: e.user.type
- }
- }, function (err, dataInsert) {
- if (err) return console.log(err);
- });
- }
- });
- });
- }
- });
- }
- var uservoiceRequestGetPromise = q.bind(uservoiceRequest.get, uservoiceRequest)
- uservoiceRequestGetPromise({
- url: "reports/user_satisfaction_responses.json",
- data: {
- page: i,
- start_date: "2015-01-01T00:00:00-0600",
- end_date: moment().format()
- }
- }).then(function(npsResp){
- var myCollectionInsertPromise = q.bind(myCollection.insert, myCollection)
- return Q.all(_.map(npsResp.responses, function(e){
- return myCollectionInsertPromise({
- created_at: new Date(e.created_at),
- body: e.body,
- score: e.score,
- id: e.id,
- user: {
- type: e.user.type
- }
- }
- }))
- }).finally(function(){
- console.log('done')
- })
Add Comment
Please, Sign In to add comment