Skip to content

Commit

Permalink
fix: Fix query for the /item endpoint (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed May 24, 2022
1 parent 584f541 commit 5e5d05b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/Item/Item.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ describe('Item router', () => {
.set(createAuthHeaders('get', url))
.expect(200)
.then((response: any) => {
expect(collectionAPI.fetchCollectionWithItem).toHaveBeenCalledWith(
dbCollectionMock.contract_address,
`${dbCollectionMock.contract_address}-${dbItem.blockchain_item_id}`
)
expect(response.body).toEqual({
data: {
...resultingItem,
Expand Down
2 changes: 1 addition & 1 deletion src/Item/Item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export class ItemService {
item: remoteItem,
} = await collectionAPI.fetchCollectionWithItem(
dbCollection.contract_address!,
dbItem.blockchain_item_id
`${dbCollection.contract_address}-${dbItem.blockchain_item_id}`
)

if (remoteCollection) {
Expand Down
11 changes: 5 additions & 6 deletions src/ethereum/api/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ export class CollectionAPI extends BaseGraphAPI {
return collections.length > 0 ? collections[0] : null
}

fetchCollections = async (filters: CollectionQueryFilters): Promise<CollectionFragment[]> => {
fetchCollections = async (
filters: CollectionQueryFilters
): Promise<CollectionFragment[]> => {
return this.paginate(['collections'], {
query: getCollectionsQuery(filters),
})
Expand All @@ -201,18 +203,15 @@ export class CollectionAPI extends BaseGraphAPI {
)
}

fetchCollectionWithItem = async (
contractAddress: string,
tokenId: string
) => {
fetchCollectionWithItem = async (contractAddress: string, itemId: string) => {
const {
data: { collections = [], items = [] },
} = await this.query<{
collections: CollectionFragment[]
items: ItemFragment[]
}>({
query: getCollectionWithItemByIdsQuery(),
variables: { id: contractAddress.toLowerCase(), tokenId },
variables: { id: contractAddress.toLowerCase(), itemId },
})

return {
Expand Down

0 comments on commit 5e5d05b

Please sign in to comment.