Skip to content

Commit

Permalink
fix: Get the creator from the graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
cyaiox committed Nov 29, 2024
1 parent cc7b592 commit 8aab203
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
26 changes: 25 additions & 1 deletion src/Collection/Collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,35 @@ export class CollectionService {
return acc
}, {} as Record<string, ThirdParty>)
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 (
Expand Down
4 changes: 2 additions & 2 deletions src/Item/Item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])

Expand Down
1 change: 1 addition & 0 deletions src/ethereum/api/Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/ethereum/api/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from './BaseGraphAPI'

export type CollectionQueryFilters = {
ids?: string[]
isApproved?: boolean
}

Expand All @@ -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}`)
}
Expand Down

0 comments on commit 8aab203

Please sign in to comment.