diff --git a/src/logic/date.ts b/src/logic/date.ts index afab393..1b54a45 100644 --- a/src/logic/date.ts +++ b/src/logic/date.ts @@ -2,6 +2,10 @@ export function fromMillisecondsToSeconds(timeInMilliseconds: number): number { return Math.floor(timeInMilliseconds / 1000) } -export function fromSecondsToMilliseconds(timeInSeconds: number): number { - return timeInSeconds * 1000 +// it rounds the time to the nearest second since the trades are stored with a precision of milliseconds already +export function fromSecondsToMilliseconds(time: number): number { + if (time.toString().length <= 10) { + return Math.round(time * 1000) + } + return Math.round(time) } diff --git a/src/ports/nfts/landQueries.ts b/src/ports/nfts/landQueries.ts index 8294816..9ea5e1f 100644 --- a/src/ports/nfts/landQueries.ts +++ b/src/ports/nfts/landQueries.ts @@ -13,7 +13,7 @@ export function getNFTsSortBy(sortBy?: NFTSortBy) { case NFTSortBy.CHEAPEST: return SQL` ORDER BY price ASC ` case NFTSortBy.RECENTLY_LISTED: - return SQL` ORDER BY created_at DESC NULLS LAST ` + return SQL` ORDER BY order_created_at DESC NULLS LAST ` case NFTSortBy.RECENTLY_SOLD: return SQL` ORDER BY sold_at DESC ` default: diff --git a/test/unit/orders-adapters.spec.ts b/test/unit/orders-adapters.spec.ts index bc54f89..f97755f 100644 --- a/test/unit/orders-adapters.spec.ts +++ b/test/unit/orders-adapters.spec.ts @@ -1,5 +1,6 @@ import { ListingStatus, Network, NFTCategory, Order } from '@dcl/schemas' import { fromDBOrderToOrder } from '../../src/adapters/orders' +import { fromSecondsToMilliseconds } from '../../src/logic/date' import { DBOrder } from '../../src/ports/orders/types' import { SquidNetwork } from '../../src/types' @@ -14,7 +15,7 @@ describe('fromDBOrderToOrder', () => { buyer: '0xdef', price: '100', status: ListingStatus.OPEN, - expires_at: Date.now() / 1000, + expires_at: Math.round(Date.now() / 1000), created_at: Date.now() / 1000, updated_at: Date.now() / 1000, network: SquidNetwork.ETHEREUM, @@ -36,8 +37,8 @@ describe('fromDBOrderToOrder', () => { price: '100', status: ListingStatus.OPEN, expiresAt: dbOrder.expires_at, - createdAt: dbOrder.created_at * 1000, - updatedAt: dbOrder.updated_at * 1000, + createdAt: fromSecondsToMilliseconds(dbOrder.created_at), + updatedAt: fromSecondsToMilliseconds(dbOrder.updated_at), network: Network.ETHEREUM, chainId: 1, issuedId: 'abc123',