Skip to content

Commit

Permalink
fix: feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo committed Jan 24, 2022
1 parent 3417c6a commit a537d57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/Item/Item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,8 @@ export class ItemService {
}

/**
*
* @param allItems
* @returns
* Takes a list of items and returns an object containing two sets, one of standard items and the other of TP items
* @param allItems - Items to split, can be any combination of item types
*/
public splitItems(
allItems: ItemAttributes[]
Expand Down
27 changes: 15 additions & 12 deletions src/ethereum/api/Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { isTPCollection } from '../../Collection/utils'

export class Bridge {
/**
* Takes TP collections found in the database and merges each one with the data from the last published (blockchain) item it has.
* Takes TP collections found in the database and combines each one with the data from the last published (blockchain) item it has.
* If no published item is found or a non-TP collection is supplied, it'll be returned as-is.
* For more info on what data is updated from the published item, see `Bridge.mergeTPCollection`
* @param dbCollections - TP collections from the database
Expand Down Expand Up @@ -46,7 +46,7 @@ export class Bridge {

/**
* Takes TP items found in the database and remote items from the blockchain.
* If the remote data exists it'll also fetch the catalyst item and merges all data.
* If the remote data exists it'll also fetch the catalyst item and combines all data.
* If remote data is found the item will just be converted to FullItem and returned as-is.
* For more info on how a full item looks, see `Bridge.toFullItem`. For more info on the merge see `Bridge.mergeTPItem`
* @param dbItems - Database TP items
Expand All @@ -61,7 +61,7 @@ export class Bridge {

const dbTPCollectionsIndex = this.indexById(dbTPCollections)

const itemsByURN = dbItems.map((item) => {
const itemsByURN = dbItems.reduce((acc, item) => {
const collection = dbTPCollectionsIndex[item.collection_id!]
if (!collection || !isTPCollection(collection)) {
throw new Error(`Could not find a valid collection for item ${item.id}`)
Expand All @@ -77,8 +77,11 @@ export class Bridge {
(remoteItem) => remoteItem.urn === urn
)

return { item, remoteItem }
})
return {
...acc,
[urn]: { item, remoteItem },
}
}, {} as Record<string, { item: ItemAttributes; remoteItem?: ThirdPartyItemFragment }>)

const tpItemURNs = Object.keys(itemsByURN)
const tpCatalystItems = await peerAPI.fetchWearables(tpItemURNs)
Expand All @@ -105,8 +108,8 @@ export class Bridge {
}

/**
* Merges the remote data, which comes from the blockchain, and the catalyst data (if it exists) *into* the db data
* The db item is first converted to a full item and then get's the appropiate data merged into it
* Combines the remote data (item from the blockchain), the catalyst data (if it exists) and the item's DB data *into* a FullItem.
* The db item is first converted to a FullItem and then the appropiate data is merged into it
* @param dbItem - Database TP item
* @param remoteItem - Blockchain item
* @param catalystItem - Catalyst item
Expand Down Expand Up @@ -150,7 +153,7 @@ export class Bridge {
}

/**
* Takes collections found in the database and merges each one with the data from the remote published (blockchain) collection counterpart
* Takes collections found in the database and combines each one with the data from the remote published (blockchain) collection counterpart
* If no published collection is found, it'll be returned as-is.
* For more info on what data is updated from the published item, see `Bridge.mergeCollection`
* @param dbCollections - DB standard collections
Expand Down Expand Up @@ -194,7 +197,7 @@ export class Bridge {
}

/**
* Takes items found in the database and merges each one with the data from the remote published (blockchain) item counterpart
* Takes items found in the database and combines each one with the data from the remote published (blockchain) item counterpart
* If the published item exists it'll fech the Catalyst item and use its data for the merge aswell.
* If no published item is found, it'll be returned as-is.
* For more info on what data is updated from the published item, see `Bridge.mergeItem`
Expand Down Expand Up @@ -273,7 +276,7 @@ export class Bridge {
}

/**
* Takes a db standard collection and a published (blockchain) collection and merges the remote data *into* the db object
* Takes a db standard collection and a published (blockchain) collection and combines the remote data *into* the db object
* to get the updated information we don't store in the database (like if the collection is approved)
* @param dbCollection - DB standard collection
* @param remoteCollection - Blockchain collection
Expand All @@ -298,7 +301,7 @@ export class Bridge {
}

/**
* Takes a db TP collection and its last published (blockchain) item and merges the remote data *into* the db object
* Takes a db TP collection and its last published (blockchain) item and combines the remote data *into* the db object
* to get the updated information we don't store in the database (like reviewed at)
* @param collection - TP db collection
* @param lastItem - Last blockchain item
Expand All @@ -321,7 +324,7 @@ export class Bridge {
}

/**
* Takes a db standard item, a published (blockchain) data and the catalyst item and merges the remote data *into* the db object
* Takes a db standard item, a published (blockchain) data and the catalyst item and combines the remote data *into* the db object
* to get the updated information we don't store in the database (like the price or if it's approved)
* @param dbItem - DB standard item
* @param remoteItem - Blockchain item
Expand Down

0 comments on commit a537d57

Please sign in to comment.