2016-06-23 2 views
0

루프백의 프레임 워크를 사용하여 API를 생성합니다. 이제는 긴 숫자 (유닉스 형식의 타임 스탬프, 예 : 1466598625506)를 필요로하고 동기화 객체의 배열을 반환하는 사용자 지정 "RemoteMethod"를 작성하려고합니다 (종단점과 comunicate하기 위해 retrofit을 사용하고 있습니다). 내 안드로이드 애플 리케이션에서 끝점 "getRecodsAfterTimestamp"를 호출하면 요청에 제공된 것보다 같거나 더 큰 timeStamp 값을 가진 레코드를 반환해야합니다. 그것이 반환하는 것은 모든 레코드입니다 (현재 3 개).루프백 원격 메소드가 올바른 값을 반환하지 않습니다.

{ 
"name": "Sync", 
"base": "PersistedModel", 
"idInjection": true, 
"options": { 
"validateUpsert": true 
}, 
"properties": { 
"uuid": { 
    "type": "string" 
}, 
"table": { 
    "type": "string" 
}, 
"action": { 
    "type": "string" 
}, 
"timeChanged": { 
    "type": "number" 
} 
}, 
"validations": [], 
"relations": {}, 
"acls": [], 
"methods": {} 
} 

그리고 원격 메소드의 모습으로이 내 sync.js입니다 :

module.exports = function(Sync) { 

Sync.getRecodsAfterTimestamp = function(timestamp, cb){ 
// var response; 

Sync.find({where:{ or: [ 
    {timeChanged:timestamp}, 
    {timeChanged: {gt:timestamp } } 
] }}, function(err, sync) { 
    cb(null,sync); 
    // response.push(sync); 
}); 

// cb(null, response); 
} 

Sync.remoteMethod (
'getRecodsAfterTimestamp', 
{ 
    http: {path: '/getRecodsAfterTimestamp', verb: 'get'}, 
    accepts: {arg: 'timeChanged', type: 'number', http: { source: 'query' } }, 
    returns: { 
    arg: 'data', 
    type: 'array', 
    root: true 
    } 
} 
); 


}; 

나는 잘 모릅니다 동기화라는 내 모델 (sync.json)과 같은 방법

이입니다 그것은 중요하지만 내 개조 메소드 선언의 경우 : 나는 그런 식으로 호출하고

@GET("Syncs") 
Call<List<Sync>> getAllSyncsAfterThisTimeStamp(@Query(("getRecodsAfterTimestamp?timeChanged=")) long timeChanged); 

그리고 여기 :

Long timeStamp = 1466598625506L; 
Log.e(TAG, "Job Service task is running..."); 
getAllSyncsCall = espcService.getAllSyncsAfterThisTimeStamp(timeStamp); 
getAllSyncsCall.enqueue(EspcJobSheculerService.this); 

이 코드는이 내가 원하는 결과가 아니다 enter image description here

반환합니다. 두 개의 레코드 인 1466598625506 이후의 모든 레코드가 반환되었을 것입니다.

답변

1

귀하의 질의가 정확합니다.

콜백 find 콜백에서 올바른 출력을 얻을 수 있습니까?

관련 문제