From a0f0e81f5adeb4047eb209fd8e6973a1e81c0a48 Mon Sep 17 00:00:00 2001 From: Pelotfr Date: Fri, 27 Oct 2023 19:02:22 +0200 Subject: [PATCH] Removed asset_ids parameter --- src/fetch/openapi.ts | 9 +-------- src/queries.spec.ts | 9 +++------ src/queries.ts | 5 +++-- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/fetch/openapi.ts b/src/fetch/openapi.ts index 9eaf9d4..f975dbe 100644 --- a/src/fetch/openapi.ts +++ b/src/fetch/openapi.ts @@ -59,7 +59,7 @@ export default new OpenApiBuilder() get: { tags: [TAGS.USAGE], summary: "Get sales", - description: "Get sales by `collection_name`, `sale_id`, `timestamp`, `block_number`, `listing_price_amount`, `listing_price_symcode`, `trx_id` or `asset_ids`", + description: "Get sales by `collection_name`, `sale_id`, `timestamp`, `block_number`, `listing_price_amount`, `listing_price_symcode`, `trx_id` or `asset_id_in_asset_ids`", parameters: [ { name: "collection_name", @@ -111,13 +111,6 @@ export default new OpenApiBuilder() required: false, schema: { type: "string" }, }, - { - name: "asset_ids", - description: "Filter by exact list of asset IDs in the sale (ex: [2199023842153])", - in: "query", - required: false, - schema: { type: "string", }, - }, { name: "asset_id_in_asset_ids", description: "Filter by asset ID in list of asset IDs in the sale (ex: 2199023842153)", diff --git a/src/queries.spec.ts b/src/queries.spec.ts index 7375ee3..60a16a0 100644 --- a/src/queries.spec.ts +++ b/src/queries.spec.ts @@ -12,14 +12,11 @@ test("getSalesCount", () => { test("getSale", () => { expect(getSale(new URLSearchParams({collection_name}))) - .toBe(`SELECT * FROM Sales WHERE (collection_name == '${collection_name}') ORDER BY sale_id DESC LIMIT 1`); + .toBe(`SELECT * FROM Sales JOIN blocks ON blocks.block_id = Sales.block_id WHERE (collection_name == '${collection_name}') ORDER BY sale_id DESC LIMIT 1`); expect(getSale(new URLSearchParams({collection_name, greater_or_equals_by_listing_price_amount: '15', limit: '10'}))) - .toBe(`SELECT * FROM Sales WHERE (listing_price_amount >= 15 AND collection_name == '${collection_name}') ORDER BY sale_id DESC LIMIT 10`); + .toBe(`SELECT * FROM Sales JOIN blocks ON blocks.block_id = Sales.block_id WHERE (listing_price_amount >= 15 AND collection_name == '${collection_name}') ORDER BY sale_id DESC LIMIT 10`); expect(getSale(new URLSearchParams({asset_id_in_asset_ids: '2199024044581'}))) - .toBe(`SELECT * FROM Sales WHERE (has(asset_ids, 2199024044581)) ORDER BY sale_id DESC LIMIT 1`); - - expect(getSale(new URLSearchParams({asset_ids: '[2199024044581]'}))) - .toBe(`SELECT * FROM Sales WHERE (asset_ids == '[2199024044581]') ORDER BY sale_id DESC LIMIT 1`); + .toBe(`SELECT * FROM Sales JOIN blocks ON blocks.block_id = Sales.block_id WHERE (has(asset_ids, 2199024044581)) ORDER BY sale_id DESC LIMIT 1`); }); \ No newline at end of file diff --git a/src/queries.ts b/src/queries.ts index b5cc2c1..7a65328 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -15,7 +15,10 @@ export interface Sale { export function getSale(searchParams: URLSearchParams) { // SQL Query let query = `SELECT * FROM Sales`; + + // JOIN block table const where = []; + query += ` JOIN blocks ON blocks.block_id = Sales.block_id`; // Clickhouse Operators // https://clickhouse.com/docs/en/sql-reference/operators @@ -46,7 +49,6 @@ export function getSale(searchParams: URLSearchParams) { const listing_price_amount = searchParams.get('listing_price_amount'); const listing_price_symcode = searchParams.get('listing_price_symcode'); const trx_id = searchParams.get('trx_id'); - const asset_ids = searchParams.get('asset_ids'); if (collection_name) where.push(`collection_name == '${collection_name}'`); if (sale_id) where.push(`sale_id == '${sale_id}'`); if (block_number) where.push(`block_number == '${block_number}'`); @@ -54,7 +56,6 @@ export function getSale(searchParams: URLSearchParams) { if (listing_price_amount) where.push(`listing_price_amount == ${listing_price_amount}`); if (listing_price_symcode) where.push(`listing_price_symcode == '${listing_price_symcode}'`); if (trx_id) where.push(`trx_id == '${trx_id}'`); - if (asset_ids) where.push(`asset_ids == '${asset_ids}'`); // Join WHERE statements with AND if ( where.length ) query += ` WHERE (${where.join(' AND ')})`;