-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
…feat/add-urn-to-collection-and-item
…feat/add-urn-to-collection-and-item
…feat/add-urn-to-collection-and-item
…feat/add-urn-to-collection-and-item
…feat/add-urn-to-collection-and-item
…feat/add-urn-to-collection-and-item
There was a problem hiding this 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 = { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/Collection/Collection.router.ts
Outdated
@@ -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) |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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.
src/Collection/Collection.types.ts
Outdated
lock: Date | null | ||
reviewed_at: Date |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/Collection/utils.ts
Outdated
...dbCollection, | ||
urn: getDecentralandCollectionURN(dbCollection.contract_address), | ||
} | ||
delete (fullCollection as FullCollection & { urn_suffix: unknown }).urn_suffix |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
src/Item/Item.router.ts
Outdated
const catalystItems = | ||
remoteItems && remoteItems.length > 0 | ||
? await peerAPI.fetchWearables(remoteItems.map((item) => item.urn)) | ||
: [] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/ethereum/api/Bridge.ts
Outdated
in_catalyst: false, | ||
is_approved: false, | ||
is_published: false, | ||
total_supply: 0, | ||
} | ||
|
||
delete (fullItem as FullItem & { urn_suffix: string | undefined }) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…feat/add-urn-to-collection-and-item
Pull Request Test Coverage Report for Build 1317804282
💛 - Coveralls |
This PR does the following:
urn_suffix
column to the collection and the items./collections/:id
path that was missing.Closes #286