From 2e54d45e43a596fb5a5936835c4dc2780a5852f7 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Thu, 2 Jan 2025 16:49:24 +0100 Subject: [PATCH 1/2] fix: cancelled rentals missing --- src/controllers/handlers/utils.ts | 2 ++ src/ports/nfts/component.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/controllers/handlers/utils.ts b/src/controllers/handlers/utils.ts index cdd406b..3d8eed0 100644 --- a/src/controllers/handlers/utils.ts +++ b/src/controllers/handlers/utils.ts @@ -24,6 +24,8 @@ export const getItemsParams = (params: Params) => { const maxPrice = params.getString('maxPrice') const minPrice = params.getString('minPrice') return { + first: params.getNumber('first'), + skip: params.getNumber('skip'), category: params.getValue('category', NFTCategory), creator: params.getList('creator'), isSoldOut: params.getBoolean('isSoldOut'), diff --git a/src/ports/nfts/component.ts b/src/ports/nfts/component.ts index 7de2da5..42daffd 100644 --- a/src/ports/nfts/component.ts +++ b/src/ports/nfts/component.ts @@ -40,7 +40,9 @@ export function createNFTsComponent(components: Pick nft.category === NFTCategory.PARCEL || nft.category === NFTCategory.ESTATE) .map(nft => nft.id) - const listings = landNftIds.length ? await rentals.getRentalsListingsOfNFTs(landNftIds, RentalStatus.OPEN) : [] + const listings = landNftIds.length + ? await rentals.getRentalsListingsOfNFTs(landNftIds, filters.rentalStatus || RentalStatus.OPEN) + : [] return { data: fromNFTsAndOrdersToNFTsResult(nfts.rows, orders.rows, listings), From 066846a5fcbd274ea972ab5d74dbd943a259fd62 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Thu, 2 Jan 2025 20:02:18 +0100 Subject: [PATCH 2/2] fix: for ENS remove the trades CTE HAVING --- src/ports/nfts/ensQueries.ts | 3 ++- src/ports/nfts/queries.ts | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ports/nfts/ensQueries.ts b/src/ports/nfts/ensQueries.ts index d894ece..8f1db8e 100644 --- a/src/ports/nfts/ensQueries.ts +++ b/src/ports/nfts/ensQueries.ts @@ -44,7 +44,7 @@ export function getENSs(nftFilters: GetNFTsFilters): SQLStatement { ORDER BY created_at ) ` - .append(getTradesCTE(nftFilters)) + .append(getTradesCTE(nftFilters, false)) .append( SQL` ` @@ -96,6 +96,7 @@ export function getENSs(nftFilters: GetNFTsFilters): SQLStatement { LEFT JOIN trades ON (trades.assets -> 'sent' ->> 'token_id')::numeric = nft.token_id AND trades.assets -> 'sent' ->> 'contract_address' = nft.contract_address AND trades.status = 'open' + AND trades.signer || '-' || nft.network = nft.owner_id LEFT JOIN squid_marketplace.ens ens ON ens.id = nft.ens_id ` .append(isOnSale ? SQL`LEFT JOIN valid_orders orders ON orders.nft_id = nft.id` : SQL``) diff --git a/src/ports/nfts/queries.ts b/src/ports/nfts/queries.ts index 1c2fc69..9cef7a5 100644 --- a/src/ports/nfts/queries.ts +++ b/src/ports/nfts/queries.ts @@ -188,7 +188,7 @@ function getParcelEstateDataCTE(filters: GetNFTsFilters): SQLStatement { * const filters = { owner: '0x123...', tokenId: '1234' }; * const tradesCTE = getTradesCTE(filters); */ -export function getTradesCTE(filters: GetNFTsFilters): SQLStatement { +export function getTradesCTE(filters: GetNFTsFilters, addHavingStatement = true): SQLStatement { const FILTER_BY_OWNER = filters.owner ? SQL` t.signer = ${filters.owner.toLocaleLowerCase()} ` : null const FILTER_BY_TOKEN_ID = filters.tokenId ? SQL` (assets_with_values.nft_id = ${filters.tokenId}) ` : null const marketplacePolygon = getContract(ContractName.OffChainMarketplace, getPolygonChainId()) @@ -262,9 +262,20 @@ export function getTradesCTE(filters: GetNFTsFilters): SQLStatement { LEFT JOIN squid_trades.trade as trade_status ON trade_status.signature = t.hashed_signature LEFT JOIN squid_trades.signature_index as signer_signature_index ON LOWER(signer_signature_index.address) = LOWER(t.signer) LEFT JOIN (select * from squid_trades.signature_index signature_index where LOWER(signature_index.address) IN (${marketplaceEthereum.address.toLowerCase()}, ${marketplacePolygon.address.toLowerCase()})) as contract_signature_index ON t.network = contract_signature_index.network - `.append(where).append(SQL` + ` + .append(where) + .append( + SQL` GROUP BY t.id, t.created_at, t.network, t.chain_id, t.signer, t.checks, contract_signature_index.index, signer_signature_index.index + ` + ) + .append( + addHavingStatement + ? SQL` HAVING t.signer = ALL(ARRAY_AGG(assets_with_values.owner) FILTER (WHERE assets_with_values.owner IS NOT NULL AND assets_with_values.direction = 'sent')) + ` + : SQL`` + ).append(SQL` ) `) }