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

fix: items #21

Merged
merged 3 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ type NFT = {
- `isWearableHead`: Only return results that their category is `wearable` and are part of the avatar's head. Type `boolean`.
- `isWearableAccessory`: Only return results that their category is `wearable` and accessories (not a part of the body).
- `wearableCategory`: Filter results by `WearableCategory`. Possible values: `eyebrows`,`eyes`,`facial_hair`,`hair`,`mouth`,`upper_body`,`lower_body`,`feet`,`earring`,`eyewear`,`hat`,`helmet`,`mask`,`tiara`,`top_head`.
- `wearableRarity`: Filter results by `WearableRarity`. It supports multiple values by adding the query param multiple times. Possible values: `unique`, `mythic`, `legendary`, `epic`, `rare`, `uncommon`, `common`.
- `wearableGender`: Filter results by `WearableGender`. It supports multiple values by adding the query param multiple times. Possible values: `male`, `female`.
- `contractAddress`: Filter results by contract address. It supports multiple values by adding the query param multiple times. Type: `address`.
- `tokenId`: Filter results by `tokenId`. Type: `string`.
- `itemRarity`: Filter results by `Rarity`. It supports multiple values by adding the query param multiple times. Possible values: `unique`, `mythic`, `legendary`, `epic`, `rare`, `uncommon`, `common`.
- `itemId`: Filter results by `itemId`. Type `string`.
- `network`: Filter results by `Network`. Possible values: `ETHEREUM`, `MATIC`.

Expand All @@ -80,7 +80,7 @@ type Item = {
category: NFTCategory
contractAddress: string
itemId: string
rarity: WearableRarity
rarity: Rarity
price: string
available: number
creator: string
Expand All @@ -98,13 +98,13 @@ type Item = {
- `skip`: Skip results. Type: `number`.
- `sortBy`: Sort results. Possible values: `newest`, `name`, `cheapest`.
- `creator`: Filter by creator. Type: `address`.
- `rarity`: Filter results by `Rarity`. It supports multiple values by adding the query param multiple times. Possible values: `unique`, `mythic`, `legendary`, `epic`, `rare`, `uncommon`, `common`.
- `isSoldOut`: Only return results that are sold out (all NFTs have been minted). Type: `boolean`.
- `isOnSale`: Only return results that can be bought (`CollectionStore` has been added as minter, and there's still available supply to mint). Type: `boolean`.
- `search`: Free text search. Type: `string`.
- `isWearableHead`: Only return results that their category is `wearable` and are part of the avatar's head. Type `boolean`.
- `isWearableAccessory`: Only return results that their category is `wearable` and accessories (not a part of the body).
- `wearableCategory`: Filter results by `WearableCategory`. Possible values: `eyebrows`,`eyes`,`facial_hair`,`hair`,`mouth`,`upper_body`,`lower_body`,`feet`,`earring`,`eyewear`,`hat`,`helmet`,`mask`,`tiara`,`top_head`.
- `wearableRarity`: Filter results by `WearableRarity`. It supports multiple values by adding the query param multiple times. Possible values: `unique`, `mythic`, `legendary`, `epic`, `rare`, `uncommon`, `common`.
- `wearableGender`: Filter results by `WearableGender`. It supports multiple values by adding the query param multiple times. Possible values: `male`, `female`.
- `contractAddress`: Filter results by contract address. Type: `address`.
- `itemId`: Filter results by `itemId`. Type: `string`.
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"printWidth": 80
},
"dependencies": {
"@dcl/schemas": "^1.3.0",
"@dcl/schemas": "^1.4.0",
"@types/sqlite3": "^3.1.7",
"@well-known-components/env-config-provider": "^1.0.0",
"@well-known-components/http-server": "^1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/handlers/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function createItemsHandler(
'wearableCategory',
WearableCategory
)
const wearableRarities = params.getList<Rarity>('wearableRarity', Rarity)
const rarities = params.getList<Rarity>('rarity', Rarity)
const wearableGenders = params.getList<WearableGender>(
'wearableGender',
WearableGender
Expand All @@ -41,13 +41,13 @@ export function createItemsHandler(
skip,
sortBy,
creator,
rarities,
isSoldOut,
isOnSale,
search,
isWearableHead,
isWearableAccessory,
wearableCategory,
wearableRarities,
wearableGenders,
contractAddress,
itemId,
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/handlers/nfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export function createNFTsHandler(
'wearableCategory',
WearableCategory
)
const wearableRarities = params.getList<Rarity>('wearableRarity', Rarity)
const wearableGenders = params.getList<WearableGender>(
'wearableGender',
WearableGender
)
const contractAddresses = params.getAddressList('contractAddress')
const tokenId = params.getString('tokenId')
const itemRarities = params.getList<Rarity>('itemRarity', Rarity)
const itemId = params.getString('itemId')
const network = params.getValue<Network>('network', Network)

Expand All @@ -49,10 +49,10 @@ export function createNFTsHandler(
isWearableHead,
isWearableAccessory,
wearableCategory,
wearableRarities,
wearableGenders,
contractAddresses,
tokenId,
itemRarities,
itemId,
network,
})
Expand Down
7 changes: 4 additions & 3 deletions src/ports/items/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export type ItemFilters = {
skip?: number
sortBy?: ItemSortBy
creator?: string
rarities?: Rarity[]
isSoldOut?: boolean
isOnSale?: boolean
search?: string
isWearableHead?: boolean
isWearableAccessory?: boolean
wearableCategory?: WearableCategory
wearableRarities?: Rarity[]
wearableGenders?: WearableGender[]
contractAddress?: string
itemId?: string
Expand All @@ -43,8 +43,6 @@ export type ItemFragment = {
collection: {
id: string
creator: string
createdAt: string
updatedAt: string
}
metadata: {
wearable: {
Expand All @@ -54,6 +52,9 @@ export type ItemFragment = {
}
}
searchWearableBodyShapes: BodyShape[]
searchIsStoreMinter: boolean
createdAt: string
updatedAt: string
}

export interface IItemsComponent {
Expand Down
24 changes: 13 additions & 11 deletions src/ports/items/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function fromItemFragment(
rarity: fragment.rarity,
price: fragment.price,
available: +fragment.available,
isOnSale: fragment.searchIsStoreMinter && +fragment.available > 0,
creator: fragment.collection.creator,
data: {
wearable: {
Expand All @@ -31,8 +32,8 @@ export function fromItemFragment(
},
network,
chainId,
createdAt: +fragment.collection.createdAt * 1000,
updatedAt: +fragment.collection.updatedAt * 1000,
createdAt: +fragment.createdAt * 1000,
updatedAt: +fragment.updatedAt * 1000,
}

return item
Expand All @@ -49,8 +50,6 @@ export const getItemFragment = () => `
collection {
id
creator
createdAt
updatedAt
}
metadata {
wearable {
Expand All @@ -60,6 +59,9 @@ export const getItemFragment = () => `
}
}
searchWearableBodyShapes
searchIsStoreMinter
createdAt
updatedAt
}
`

Expand All @@ -69,13 +71,13 @@ export function getItemsQuery(filters: ItemFilters, isCount = false) {
skip,
sortBy,
creator,
rarities,
isSoldOut,
isOnSale,
search,
isWearableHead,
isWearableAccessory,
wearableCategory,
wearableRarities,
wearableGenders,
contractAddress,
itemId,
Expand Down Expand Up @@ -115,9 +117,9 @@ export function getItemsQuery(filters: ItemFilters, isCount = false) {
where.push('searchIsWearableAccessory: true')
}

if (wearableRarities && wearableRarities.length > 0) {
if (rarities && rarities.length > 0) {
where.push(
`searchWearableRarity_in: [${wearableRarities
`searchWearableRarity_in: [${rarities
.map((rarity) => `"${rarity}"`)
.join(',')}]`
)
Expand Down Expand Up @@ -162,8 +164,8 @@ export function getItemsQuery(filters: ItemFilters, isCount = false) {
let orderDirection: string
switch (sortBy || ITEM_DEFAULT_SORT_BY) {
case ItemSortBy.NEWEST:
orderBy = ''
orderDirection = ''
orderBy = 'createdAt'
orderDirection = 'desc'
break
case ItemSortBy.NAME:
orderBy = 'searchText'
Expand All @@ -174,8 +176,8 @@ export function getItemsQuery(filters: ItemFilters, isCount = false) {
orderDirection = 'asc'
break
default:
orderBy = ''
orderDirection = ''
orderBy = 'createdAt'
orderDirection = 'desc'
}

const query = `query Items {
Expand Down
2 changes: 1 addition & 1 deletion src/ports/nfts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export type NFTFilters = {
owner?: string
isOnSale?: boolean
search?: string
itemRarities?: Rarity[]
isLand?: boolean
isWearableHead?: boolean
isWearableAccessory?: boolean
wearableCategory?: WearableCategory
wearableRarities?: Rarity[]
wearableGenders?: WearableGender[]
contractAddresses?: string[]
tokenId?: string
Expand Down
4 changes: 2 additions & 2 deletions src/ports/nfts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ export function getFetchQuery(
where.push('searchIsWearableAccessory: $isWearableAccessory')
}

if (filters.wearableRarities && filters.wearableRarities.length > 0) {
if (filters.itemRarities && filters.itemRarities.length > 0) {
where.push(
`searchWearableRarity_in: [${filters.wearableRarities
`searchWearableRarity_in: [${filters.itemRarities
.map((rarity) => `"${rarity}"`)
.join(',')}]`
)
Expand Down