Skip to content

Commit

Permalink
Removed asset_ids parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelotfr committed Oct 27, 2023
1 parent 797af89 commit a0f0e81
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
9 changes: 1 addition & 8 deletions src/fetch/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)",
Expand Down
9 changes: 3 additions & 6 deletions src/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
});
5 changes: 3 additions & 2 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,15 +49,13 @@ 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}'`);
if (timestamp) where.push(`toUnixTimestamp(timestamp) == ${timestamp}`);
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 ')})`;
Expand Down

0 comments on commit a0f0e81

Please sign in to comment.