Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add URN to collection and item #286

Merged
merged 24 commits into from
Oct 7, 2021

Conversation

LautaroPetaccio
Copy link
Contributor

@LautaroPetaccio LautaroPetaccio commented Sep 29, 2021

This PR does the following:

  • Adds the urn_suffix column to the collection and the items.
  • Adds the logic to generate the URNs at the time of retrieving the collections and the items.
  • Adds the auth middleware for the (GET) /collections/:id path that was missing.
  • Adds tests for both the items and the collections

Closes #286

Copy link
Contributor

@nicosantangelo nicosantangelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

spec/utils.ts Outdated
@@ -37,6 +39,24 @@ export const wallet: Wallet = {
},
}

export const collectionAttributesMock: CollectionAttributes = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think it'd be a good idea to move this to a seed.ts file? I know it might be too soon but asking just in case we also want to move this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved most of the mocks and functions used to build the results to a mocks directory so we can re-use them afterwards. It is definitely tidier now.

@@ -36,6 +41,7 @@ export class CollectionRouter extends Router {
const withCollectionExists = withModelExists(Collection, 'id')
const withCollectionAuthorization = withModelAuthorization(Collection)
const withLowercasedAddress = withLowercasedParams(['address'])
console.log('Auth middleware created', withAuthentication)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whops! (was it on purpose?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL I completely forgot to remove this.

Comment on lines 18 to 19
lock: Date | null
reviewed_at: Date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, it was a mistake on my part because node-pg used to return undefined for NULL values. But while we're at it, you mind fixing the type for reviewed_at and forum_link? both are NULLABLE and are not set at first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

...dbCollection,
urn: getDecentralandCollectionURN(dbCollection.contract_address),
}
delete (fullCollection as FullCollection & { urn_suffix: unknown }).urn_suffix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could take advantage of decentraland-common's omit here if you like. Avoiding this delete for something like

  const fullCollection: FullCollection = {
    ...utils.omit(dbCollection, ['urn_suffix']),
    urn: getDecentralandCollectionURN(dbCollection.contract_address),
  }

or just

  const { urn_suffix, ...sufixlessDbCollection } = dbCollection
  const fullCollection: FullCollection = {
    ...sufixlessDbCollection,
    urn: getDecentralandCollectionURN(dbCollection.contract_address),
  }

but that might upset the linter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for toDBCollection with the urn!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

import { getCurrentNetworkURNProtocol } from '../ethereum/utils'
import { CollectionAttributes, FullCollection } from './Collection.types'

export function getDecentralandCollectionURN(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: You think any of these methods might make sense on the CollectionService class? I'm not entirely sure as of right now, but if no, maybe we can think about clear boundaries of these file and the service.

My first intuition is that utils is fine in these cases and if we wanted to extract this, it'd make more sense to do a CollectionBridge of sorts with these methods (overkill)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure where this should go, as I think that we would really need more methods like this to have a clear view on how to structure them. The main reason why I'm not sure about moving it into a service is because this method only builds a string that will be used for a collection, but it's not directly involved with collections at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, let's keep an eye out tho! maybe even for moving the service methods here!

// Build the full collection
return consolidatedCollections.map((collection) =>
toFullCollection(collection)
)
}

async getAddressCollections(req: AuthRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can go the Item.router.ts route (heh) here too and add return types to these methods, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 100% on board of typing return types. Done!

Comment on lines 146 to 149
const catalystItems =
remoteItems && remoteItems.length > 0
? await peerAPI.fetchWearables(remoteItems.map((item) => item.urn))
: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why's this necessary? can remoteItems be undefined? the type says Promise<ItemFragment[]>
peer.ts already has this check:

const wearables: PeerWearable[] =
  urns.length > 0
    ? await this.lambdasClient.fetchWearables({ wearableIds: urns })
    : []

same thing here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, there was no need to check for undefined. Removed it in both places.

in_catalyst: false,
is_approved: false,
is_published: false,
total_supply: 0,
}

delete (fullItem as FullItem & { urn_suffix: string | undefined })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use utils.omit or destructuring here and here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to utils.omit here. For the second one, I chose to use this toFullItem method, as there might be more changes in the future to the item.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1317804282

  • 59 of 74 (79.73%) changed or added relevant lines in 11 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+7.1%) to 49.496%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/Collection/utils.ts 7 8 87.5%
src/Item/Item.router.ts 4 6 66.67%
src/ethereum/api/Bridge.ts 6 8 75.0%
src/ethereum/utils.ts 8 10 80.0%
src/Item/utils.ts 2 5 40.0%
src/Collection/Collection.router.ts 16 21 76.19%
Files with Coverage Reduction New Missed Lines %
src/Collection/Collection.router.ts 1 41.34%
Totals Coverage Status
Change from base Build 1317667898: 7.1%
Covered Lines: 1163
Relevant Lines: 2087

💛 - Coveralls

@nicosantangelo nicosantangelo merged commit e83edaf into master Oct 7, 2021
@nicosantangelo nicosantangelo deleted the feat/add-urn-to-collection-and-item branch October 7, 2021 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants