diff --git a/src/Collection/Collection.service.ts b/src/Collection/Collection.service.ts index 42927979..5173221e 100644 --- a/src/Collection/Collection.service.ts +++ b/src/Collection/Collection.service.ts @@ -608,11 +608,35 @@ export class CollectionService { return acc }, {} as Record) const thirdPartyIds = Object.keys(thirdPartyById) - const allCollections = await Collection.findAll({ + let allCollections = await Collection.findAll({ ...params, thirdPartyIds, }) + // Verify collections ownership + if (params.address !== undefined) { + const collectionsIds = allCollections.map( + (collection) => collection.contract_address! + ) + const remoteCollections = await collectionAPI.fetchCollections({ + ids: collectionsIds, + }) + + if (remoteCollections.length > 0) { + // Create a map of remote collections for fast lookup + const remoteCollectionMap = Object.fromEntries( + remoteCollections.map(({ id, creator }) => [id, creator]) + ) + + // If exists the remote collection, filter by the creator field + allCollections = allCollections.filter( + ({ contract_address }) => + !remoteCollectionMap[contract_address!] || + remoteCollectionMap[contract_address!] === params.address + ) + } + } + // Set if the collection is programmatic for (const collection of allCollections) { if ( diff --git a/src/Item/Item.service.ts b/src/Item/Item.service.ts index 20b738b5..c966f8a7 100644 --- a/src/Item/Item.service.ts +++ b/src/Item/Item.service.ts @@ -98,10 +98,10 @@ export class ItemService { const [dbItemCollection, itemCollection] = await Promise.all([ collectionId - ? this.collectionService.getDBCollection(collectionId) + ? this.collectionService.getCollection(collectionId) : undefined, isMovingItemFromACollectionToAnother || isMovingOrphanItemIntoACollection - ? this.collectionService.getDBCollection(item.collection_id!) + ? this.collectionService.getCollection(item.collection_id!) : undefined, ]) diff --git a/src/ethereum/api/Bridge.ts b/src/ethereum/api/Bridge.ts index 3fbebf94..fd5cf8e6 100644 --- a/src/ethereum/api/Bridge.ts +++ b/src/ethereum/api/Bridge.ts @@ -406,6 +406,7 @@ export class Bridge { in_catalyst, is_published: true, is_approved: remoteCollection.isApproved, + eth_address: remoteCollection.creator, price: remoteItem.price, beneficiary: remoteItem.beneficiary, blockchain_item_id: remoteItem.blockchainId, diff --git a/src/ethereum/api/collection.ts b/src/ethereum/api/collection.ts index 2b2e77e4..9f8a5134 100644 --- a/src/ethereum/api/collection.ts +++ b/src/ethereum/api/collection.ts @@ -23,6 +23,7 @@ import { } from './BaseGraphAPI' export type CollectionQueryFilters = { + ids?: string[] isApproved?: boolean } @@ -35,9 +36,13 @@ const getCollectionByIdQuery = () => gql` ${collectionFragment()} ` -const getCollectionsQuery = ({ isApproved }: CollectionQueryFilters) => { +const getCollectionsQuery = ({ ids, isApproved }: CollectionQueryFilters) => { const where: string[] = [] + if (ids !== undefined && ids.length > 0) { + where.push(`id_in: ${JSON.stringify(ids)}`) + } + if (isApproved !== undefined) { where.push(`isApproved : ${isApproved}`) }