From a537d5746654c945c26123481c1af0bf4ea9b01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Sant=C3=A1ngelo?= Date: Mon, 24 Jan 2022 13:11:45 -0300 Subject: [PATCH] fix: feedback --- src/Item/Item.service.ts | 5 ++--- src/ethereum/api/Bridge.ts | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Item/Item.service.ts b/src/Item/Item.service.ts index c8627bd7..761fd078 100644 --- a/src/Item/Item.service.ts +++ b/src/Item/Item.service.ts @@ -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[] diff --git a/src/ethereum/api/Bridge.ts b/src/ethereum/api/Bridge.ts index d7804859..8a16ff04 100644 --- a/src/ethereum/api/Bridge.ts +++ b/src/ethereum/api/Bridge.ts @@ -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 @@ -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 @@ -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}`) @@ -77,8 +77,11 @@ export class Bridge { (remoteItem) => remoteItem.urn === urn ) - return { item, remoteItem } - }) + return { + ...acc, + [urn]: { item, remoteItem }, + } + }, {} as Record) const tpItemURNs = Object.keys(itemsByURN) const tpCatalystItems = await peerAPI.fetchWearables(tpItemURNs) @@ -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 @@ -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 @@ -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` @@ -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 @@ -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 @@ -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