2015-01-03 6 views
0

나는 완전히 바보 같다.하지만 나와 함께 한 친구가 함께 프로젝트를 진행하고 Etsy API에서 요청한 항목을 반환하는 첫 번째 경로를 얻는 데 문제가 있고 getAllListings가 항목을 데이터베이스에 추가하게하십시오. 우리가 잘못하고있는 것을 눈에 띄게 볼 수 있다면 알려주십시오.API에서 정보를 가져와 데이터베이스에 추가 (평균 스택)

나는 또한 문 console.dir(body) 터미널에 항목을 인쇄 않지만 내용이 GET '/api/etsy/getListings'

감사에 전달되는 것처럼 보이지 않는 것을 언급해야한다!

routes.js

//this i want to return a list of active listings from the users shop. 

app.get('/api/etsy/getListings',function(req, res){ 
    bEtsy.getAllListings(req, res, function(err, body) { 
    }); 
    res.json(req.body); 
}); 

bEtsy.js

var standardCallback = function (err, status, body, headers, callback) { 
    if (err) { 
    console.log(err); 
    return callback(err, null); 
    } 

    if (body) { 
    console.dir(body); 
    return callback(null, body); // this gives me an error 
    } 
} 


var getAllListings = function(itemId, callback){ 
    var Item = mongoose.model('Item'); 
    var listingsParams = { 
    include_private: true 
    } 

    etsy.auth().get(
    '/shops/'+etsy.shop+'/listings/active', 
    listingsParams, 
    function(err, status, body, headers){ 
     var newi = new Item({name: body.title, stock: body.count, owner: "00000000000000000000", 
     etsy:{listingId: body.listing_id, stock: body.count}}); 
     newi.save(function(err){ 
     if (err) return handError(err); 
     }); 
     standardCallback(err, status, body, headers, callback); 
    } 
); 
}; 

답변

1

그것은 단지 그 위에 두

bEtsy.getAllListings(req, res, function(err, body) { 
}); 

을 소요 할 때, 세 개의 매개 변수이 함수를 호출 첫 번째 인수 itemId이 요청 객체를 전달 중이고 사용되지 않습니다. 함수 자체 안에 있지만 listingsParams이라는 일부 전역 변수는?!?

관련 문제