diff --git a/packages/api/src/repository/ResultRequest.ts b/packages/api/src/repository/ResultRequest.ts index e78a75b3..c0d9e913 100644 --- a/packages/api/src/repository/ResultRequest.ts +++ b/packages/api/src/repository/ResultRequest.ts @@ -24,14 +24,19 @@ export class ResultRequestRepository { .find( { feedFullName, - timestamp: { $gt: timestamp.toString() } + timestamp: { $gt: timestamp.toString() }, + result: { $exists: true } }, { sort: { timestamp: -1 } } ) .toArray() - ).map(this.normalizeId) + ) + .filter((request, index, self) => { + return index === self.findIndex(x => x.timestamp === request.timestamp) + }) + .map(this.normalizeId) } async getFeedRequestsPage ( @@ -42,7 +47,8 @@ export class ResultRequestRepository { return ( await this.collection .find({ - feedFullName + feedFullName, + result: { $exists: true } }) .sort({ timestamp: -1 }) .skip(size * (page - 1)) diff --git a/packages/api/test/feeds.spec.ts b/packages/api/test/feeds.spec.ts index fd0b1a43..cb7edb1c 100644 --- a/packages/api/test/feeds.spec.ts +++ b/packages/api/test/feeds.spec.ts @@ -142,7 +142,7 @@ describe('feeds', function () { result: '2222.0', feedFullName, requestId: '1', - timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 10).toString(), + timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 11).toString(), drTxHash: '666f4735c3cbfb71d6e2f06cd13e4705751c50500c1720162b16532072bae88a' } @@ -185,7 +185,7 @@ describe('feeds', function () { const feed = data.data.feed expect(feed).toHaveProperty('address', dataFeeds[0].address) expect(feed).toHaveProperty('name', dataFeeds[0].name) - expect(feed).toHaveProperty('lastResult', resultRequestExample1.result) + expect(feed).toHaveProperty('lastResult', resultRequestExample2.result) expect(feed.requests.length).toBe(2) expect(feed.requests[0]).toHaveProperty( 'feedFullName', @@ -193,7 +193,7 @@ describe('feeds', function () { ) expect(feed.requests[0]).toHaveProperty( 'result', - resultRequestExample1.result + resultRequestExample2.result ) expect(feed.requests[0]).toHaveProperty( 'requestId', @@ -240,7 +240,7 @@ describe('feeds', function () { result: '2222.0', feedFullName, requestId: '1', - timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 10).toString(), + timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 11).toString(), drTxHash: '666f4735c3cbfb71d6e2f06cd13e4705751c50500c1720162b16532072bae88a' } @@ -322,7 +322,7 @@ describe('feeds', function () { result: '2222.0', feedFullName, requestId: '1', - timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 10).toString(), + timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 11).toString(), address: '0x58995FaD03158fB9cd64397347bA97714EF9fC12', drTxHash: '666f4735c3cbfb71d6e2f06cd13e4705751c50500c1720162b16532072bae88a',