Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions packages/api/src/repository/ResultRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
Db,
Collection,
FeedInfo,
WithoutId
WithoutId,
PaginatedRequests
} from '../types'
import { containFalsyValues } from './containFalsyValues'

Expand Down Expand Up @@ -49,17 +50,26 @@ export class ResultRequestRepository {
feedFullName: string,
page: number,
size: number
): Promise<Array<ResultRequestDbObjectNormalized>> {
return (
await this.collection
.find({
feedFullName
})
.sort({ timestamp: -1 })
.skip(size * (page - 1))
.limit(size)
.toArray()
).map(this.normalizeId)
): Promise<PaginatedRequests> {
return {
requests: (
await this.collection
.find({
feedFullName
})
.sort({ timestamp: -1 })
.skip(size * (page - 1))
.limit(size)
.toArray()
).map(this.normalizeId),
total: (
await this.collection
.find({
feedFullName
})
.toArray()
).length
}
}

async getLastResult (
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ const resolvers = {
},

requests: async (_parent, args, { resultRequestRepository }: Context) => {
return await resultRequestRepository.getFeedRequestsPage(
const result = await resultRequestRepository.getFeedRequestsPage(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const result = await resultRequestRepository.getFeedRequestsPage(
return await resultRequestRepository.getFeedRequestsPage(

args.feedFullName,
args.page,
args.size
)
console.log('result', result)
return result
Comment on lines +19 to +20
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log('result', result)
return result

},

feed: async (_parent, args, { feedRepository }: Context) => {
Expand Down
11 changes: 10 additions & 1 deletion packages/api/src/typeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const typeDefs = gql`
timestamp: String! @column
}

type PaginatedResultRequest {
requests: [ResultRequest]
total: Int!
}

# type DataRequest @entity(embedded: true) {
# retrieval: String! @column
# aggregation: String! @column
Expand All @@ -59,7 +64,11 @@ const typeDefs = gql`
type Query {
feed(feedFullName: String!): Feed
feeds(network: String): FeedsPage!
requests(feedFullName: String!, page: Int!, size: Int!): [ResultRequest]!
requests(
feedFullName: String!
page: Int!
size: Int!
): PaginatedResultRequest!
networks: [NetworksConfig]!
}
`
Expand Down
5 changes: 5 additions & 0 deletions packages/api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export type ResultRequestDbObjectNormalized = ResultRequestDbObject & {
id: string
}

export type PaginatedRequests = {
requests: Array<ResultRequestDbObjectNormalized>
total: number
}

export type Repositories = {
feedRepository: FeedRepository
resultRequestRepository: ResultRequestRepository
Expand Down
13 changes: 8 additions & 5 deletions packages/ui/apollo/queries/requests.gql
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
query requests($feedFullName: String!, $page: Int!, $size: Int!) {
requests(feedFullName: $feedFullName, page: $page, size: $size) {
feedFullName
result
drTxHash,
requestId
timestamp
requests {
feedFullName
result
drTxHash,
requestId
timestamp
}
total
}
}
8 changes: 4 additions & 4 deletions packages/ui/components/DataFeedDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ export default {
}
},
numberOfPages() {
return this.feed
? Math.ceil(this.feed.requests.length / this.itemsPerPage)
return this.requests
? Math.ceil(this.requests.total / this.itemsPerPage)
: 0
},
chartData() {
Expand All @@ -204,8 +204,8 @@ export default {
}
},
transactions() {
if (this.feed && this.requests && this.requests.length > 0) {
return this.requests.map((request) => ({
if (this.requests && this.requests.total > 0) {
return this.requests.requests.map((request) => ({
witnetLink: getWitnetBlockExplorerLink(request.drTxHash),
drTxHash: request.drTxHash,
data: {
Expand Down