diff --git a/spec/mocks/items.ts b/spec/mocks/items.ts index d19522cc..9b69c43c 100644 --- a/spec/mocks/items.ts +++ b/spec/mocks/items.ts @@ -2,9 +2,7 @@ import { constants } from 'ethers' import { Rarity, ThirdPartyWearable } from '@dcl/schemas' import { v4 as uuidv4 } from 'uuid' import { - ItemFragment, - ThirdPartyItemFragment, - ThirdPartyItemMetadataType, + ItemFragment } from '../../src/ethereum/api/fragments' import { Bridge } from '../../src/ethereum/api/Bridge' import { @@ -188,32 +186,6 @@ export const itemFragmentMock = { contentHash: '', } -export const thirdPartyItemFragmentMock: ThirdPartyItemFragment = { - urn: buildTPItemURN( - dbTPCollectionMock.third_party_id, - dbTPCollectionMock.urn_suffix, - dbTPItemMock.urn_suffix - ), - blockchainItemId: '1', - contentHash: '', - isApproved: true, - metadata: { - type: ThirdPartyItemMetadataType.third_party_v1, - itemWearable: { - name: 'Fragment Name', - description: null, - category: null, - bodyShapes: null, - }, - }, - thirdParty: { - id: dbTPCollectionMock.third_party_id, - }, - reviewedAt: toUnixTimestamp(dbTPCollectionMock.reviewed_at!), - updatedAt: toUnixTimestamp(dbTPCollectionMock.updated_at), - createdAt: toUnixTimestamp(dbTPCollectionMock.created_at), -} - export function convertItemDatesToISO( item: T ): Omit & { diff --git a/spec/mocks/peer.ts b/spec/mocks/peer.ts index 620eb1ab..f4183dd3 100644 --- a/spec/mocks/peer.ts +++ b/spec/mocks/peer.ts @@ -7,11 +7,7 @@ import { I18N, } from '@dcl/schemas' import { dbCollectionMock } from './collections' -import { - dbItemMock, - itemFragmentMock, - thirdPartyItemFragmentMock, -} from './items' +import { dbItemMock, itemFragmentMock } from './items' export const wearableMock: StandardWearable = { id: itemFragmentMock.urn, @@ -34,7 +30,7 @@ export const wearableMock: StandardWearable = { export const tpWearableMock: ThirdPartyWearable = { ...wearableMock, - id: thirdPartyItemFragmentMock.urn, + id: dbCollectionMock.contract_address + '-' + dbItemMock.blockchain_item_id, merkleProof: { proof: [], index: 0, diff --git a/src/Curation/Curation.router.spec.ts b/src/Curation/Curation.router.spec.ts index 15314e13..141d6948 100644 --- a/src/Curation/Curation.router.spec.ts +++ b/src/Curation/Curation.router.spec.ts @@ -2,12 +2,10 @@ import { ExpressApp } from '../common/ExpressApp' import { collectionFragmentMock, dbCollectionMock, - dbTPCollectionMock, } from '../../spec/mocks/collections' -import { dbItemMock, thirdPartyItemFragmentMock } from '../../spec/mocks/items' +import { dbItemMock } from '../../spec/mocks/items' import { thirdPartyAPI } from '../ethereum/api/thirdParty' import { collectionAPI } from '../ethereum/api/collection' -import { toUnixTimestamp } from '../utils/parse' import { Collection } from '../Collection' import { Item, ItemAttributes } from '../Item' import { isCommitteeMember } from '../Committee' @@ -92,52 +90,6 @@ describe('when handling a request', () => { ).rejects.toThrowError('Collection is not a third party collection') }) }) - - describe('when it is fetching items from a managed TP collection', () => { - let fetchItemsByCollectionSpy: jest.SpyInstance< - ReturnType - > - - beforeEach(() => { - mockServiceWithAccess(CollectionCuration, true) - - jest - .spyOn(Collection, 'findOne') - .mockResolvedValueOnce(dbTPCollectionMock) - - fetchItemsByCollectionSpy = fetchItemsByCollectionSpy = jest - .spyOn(thirdPartyAPI, 'fetchItemsByCollection') - .mockResolvedValueOnce([ - { ...thirdPartyItemFragmentMock }, // approved - { ...thirdPartyItemFragmentMock }, // approved - { - ...thirdPartyItemFragmentMock, - isApproved: false, - reviewedAt: toUnixTimestamp(new Date()), - }, // rejected - { ...thirdPartyItemFragmentMock, isApproved: false }, // under review - { ...thirdPartyItemFragmentMock, isApproved: false }, // under review - ]) - }) - - it('should fetch the items for the collection id and its third party id', async () => { - await router.getCollectionCurationItemStats(req) - expect(fetchItemsByCollectionSpy).toHaveBeenCalledWith( - dbTPCollectionMock.third_party_id, - req.params.id - ) - }) - - it('should use the fetched items to count and return an object with the values', async () => { - const stats = await router.getCollectionCurationItemStats(req) - expect(stats).toEqual({ - total: 5, - approved: 2, - rejected: 1, - needsReview: 2, - }) - }) - }) }) describe('when trying to obtain a list of collection curations', () => { diff --git a/src/Curation/Curation.router.ts b/src/Curation/Curation.router.ts index 87179824..9c92fca7 100644 --- a/src/Curation/Curation.router.ts +++ b/src/Curation/Curation.router.ts @@ -5,7 +5,6 @@ import { HTTPError, STATUS_CODES } from '../common/HTTPError' import { withAuthentication, AuthRequest } from '../middleware' import { isCommitteeMember } from '../Committee' import { collectionAPI } from '../ethereum/api/collection' -import { thirdPartyAPI } from '../ethereum/api/thirdParty' import { getValidator } from '../utils/validator' import { Collection, CollectionService } from '../Collection' import { NonExistentItemError, UnpublishedItemError } from '../Item/Item.errors' @@ -146,32 +145,14 @@ export class CurationRouter extends Router { ) } - // TODO: This request could be huge. The method should work, as it's fetching page after page of items but this endpoint should probably be paginated. - const publishedItems = await thirdPartyAPI.fetchItemsByCollection( - collection.third_party_id, - collectionId - ) - - const total = publishedItems.length - let approved = 0 - let rejected = 0 - let needsReview = 0 - - for (const item of publishedItems) { - if (item.isApproved) { - approved += 1 - } else if (item.createdAt === item.reviewedAt) { - needsReview += 1 - } else { - rejected += 1 - } - } + // This endpoint will return 0 on any stats until we implement it + // for the current TP implementation. return { - total, - approved, - rejected, - needsReview, + total: 0, + approved: 0, + rejected: 0, + needsReview: 0, } } diff --git a/src/Item/Item.router.spec.ts b/src/Item/Item.router.spec.ts index 85848ae2..0cac6f31 100644 --- a/src/Item/Item.router.spec.ts +++ b/src/Item/Item.router.spec.ts @@ -24,7 +24,6 @@ import { dbItemMock, dbTPItemMock, itemFragmentMock, - thirdPartyItemFragmentMock, ResultItem, toResultItem, toResultTPItem, @@ -109,7 +108,6 @@ describe('Item router', () => { } tpWearable = { ...tpWearableMock, - id: thirdPartyItemFragmentMock.urn, } dbItemNotPublished = { ...dbItem, @@ -303,9 +301,6 @@ describe('Item router', () => { ;(thirdPartyAPI.fetchThirdPartiesByManager as jest.Mock).mockResolvedValueOnce( [thirdPartyFragmentMock] ) - ;(thirdPartyAPI.fetchItemsByThirdParties as jest.Mock).mockResolvedValueOnce( - [thirdPartyItemFragmentMock] - ) ;(collectionAPI.fetchItemsByAuthorizedUser as jest.Mock).mockResolvedValueOnce( [itemFragment] ) diff --git a/src/ethereum/api/fragments.ts b/src/ethereum/api/fragments.ts index c8c89e69..7ba97695 100644 --- a/src/ethereum/api/fragments.ts +++ b/src/ethereum/api/fragments.ts @@ -65,29 +65,6 @@ export const thirdPartyFragment = () => gql` } ` -export const thirdPartyItemFragment = () => gql` - fragment thirdPartyItemFragment on Item { - urn - blockchainItemId - contentHash - isApproved - reviewedAt - updatedAt - createdAt - metadata { - itemWearable { - name - description - category - bodyShapes - } - } - thirdParty { - id - } - } -` - export const accountFragment = () => gql` fragment accountFragment on Account { id @@ -170,37 +147,11 @@ export type ThirdPartyFragment = { metadata: ThirdPartyMetadata } -type ThirdPartyItemWearableMetadata = { - name: string | null - description: string | null - category: WearableCategory | null - bodyShapes: BodyShape[] | null -} - -export type ThirdPartyItemFragment = { - urn: string - blockchainItemId: string - contentHash: string - isApproved: boolean - reviewedAt: string - updatedAt: string - createdAt: string - metadata: ThirdPartyItemMetadata - thirdParty: { - id: string - } -} - export type ThirdPartyMetadata = { type: ThirdPartyMetadataType thirdParty: { name: string; description: string } | null } -type ThirdPartyItemMetadata = { - type: ThirdPartyItemMetadataType | undefined - itemWearable: ThirdPartyItemWearableMetadata -} - export enum ThirdPartyMetadataType { THIRD_PARTY_V1 = 'third_party_v1', } @@ -210,11 +161,6 @@ export enum ThirdPartyItemMetadataType { item_wearable_v1 = 'item_wearable_v1', } -enum BodyShape { - BaseMale, - BaseFemale, -} - export type AccountFragment = { id: string address: string diff --git a/src/ethereum/api/thirdParty.ts b/src/ethereum/api/thirdParty.ts index 492d0d73..22f3c110 100644 --- a/src/ethereum/api/thirdParty.ts +++ b/src/ethereum/api/thirdParty.ts @@ -3,8 +3,6 @@ import { env } from 'decentraland-commons' import { thirdPartyFragment, ThirdPartyFragment, - ThirdPartyItemFragment, - thirdPartyItemFragment, tiersFragment, TierFragment, ReceiptFragment, @@ -44,24 +42,6 @@ const getThirdPartiesByManagerQuery = () => gql` ${thirdPartyFragment()} ` -const getItemsQuery = () => gql` - query getItems { - items { - ...thirdPartyItemFragment - } - } - ${thirdPartyItemFragment()} -` - -const getItemsByThirdPartyIdsQuery = () => gql` - query getItemsByThirdPartyIds(${PAGINATION_VARIABLES}, $thirdPartiesIds: [String!]) { - items(${PAGINATION_ARGUMENTS}, where: { thirdParty_in: $thirdPartiesIds }) { - ...thirdPartyItemFragment - } - } - ${thirdPartyItemFragment()} -` - const getThirdPartyMaxItems = () => gql` query getThirdPartyAvailableSlots($thirdPartyId: String!) { thirdParties(where: { id: $thirdPartyId }) { @@ -70,23 +50,6 @@ const getThirdPartyMaxItems = () => gql` } ` -const getItemsByCollectionQuery = () => gql` - query getItemsByCollection(${PAGINATION_VARIABLES}, $thirdPartiesId: String!, $collectionId: String!) { - items(${PAGINATION_ARGUMENTS}, where: { thirdParty: $thirdPartiesId, searchCollectionId: $collectionId }) { - ...thirdPartyItemFragment - } - } - ${thirdPartyFragment()} -` - -const getItemQuery = () => gql` - query getThirdPartyItem($urn: String) { - items(first: 1, where: { urn: $urn }) { - ...thirdPartyItemFragment - } - } -` - const isManagerQuery = () => gql` query isManager($thirdPartyId: String!, $managers: [String!]) { thirdParties( @@ -96,7 +59,6 @@ const isManagerQuery = () => gql` id } } - ${thirdPartyItemFragment()} ` const getTiersQuery = () => gql` @@ -153,25 +115,6 @@ export class ThirdPartyAPI extends BaseGraphAPI { }) } - fetchItemsByThirdParties = async ( - thirdPartyIds: string[] - ): Promise => { - return this.paginate(['items'], { - query: getItemsByThirdPartyIdsQuery(), - variables: { thirdPartyIds }, - }) - } - - fetchItemsByCollection = async ( - thirdPartyId: string, - collectionId: string - ): Promise => { - return this.paginate(['items'], { - query: getItemsByCollectionQuery(), - variables: { thirdPartyId, collectionId }, - }) - } - fetchReceiptById = async ( hash: string ): Promise => { @@ -197,27 +140,6 @@ export class ThirdPartyAPI extends BaseGraphAPI { return Number(thirdParties[0].maxItems) } - fetchItems = async (): Promise => { - return this.paginate(['items'], { - query: getItemsQuery(), - }) - } - - fetchItem = async ( - urn: string - ): Promise => { - const { - data: { items = [] }, - } = await this.query<{ - items: ThirdPartyItemFragment[] - }>({ - query: getItemQuery(), - variables: { urn }, - }) - - return items[0] - } - isManager = async ( thirdPartyId: string, manager: string