Skip to content

Commit

Permalink
fix: avoid null chart data points
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Nov 10, 2021
1 parent 3a6f2ab commit b815e47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 9 additions & 3 deletions packages/api/src/repository/ResultRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -42,7 +47,8 @@ export class ResultRequestRepository {
return (
await this.collection
.find({
feedFullName
feedFullName,
result: { $exists: true }
})
.sort({ timestamp: -1 })
.skip(size * (page - 1))
Expand Down
10 changes: 5 additions & 5 deletions packages/api/test/feeds.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -185,15 +185,15 @@ 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',
resultRequestExample1.feedFullName
)
expect(feed.requests[0]).toHaveProperty(
'result',
resultRequestExample1.result
resultRequestExample2.result
)
expect(feed.requests[0]).toHaveProperty(
'requestId',
Expand Down Expand Up @@ -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'
}
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit b815e47

Please sign in to comment.