From 48d1f7fb14c2bb020774372bce6eb75fcf497f91 Mon Sep 17 00:00:00 2001 From: Pelotfr Date: Wed, 1 Nov 2023 13:21:28 +0100 Subject: [PATCH] Updated docs --- README.md | 1 + src/fetch/aggregate.ts | 18 ++++++++++++++++++ src/fetch/openapi.ts | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/fetch/aggregate.ts diff --git a/README.md b/README.md index 1751453..604587e 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ |-------------------------------------------|-----------------------| | GET `/health` | Health check | GET `/sales` | Get sales by `collection_name`, `sale_id`, `timestamp`, `block_number`, `template_id`, `listing_price_amount`, `listing_price_symcode`, `trx_id` or `asset_ids` +| GET `/sales/aggregate` | Get aggregate of sales filtered by `collection_name`, `timestamp` or `block_number` | GET `/metrics` | Prometheus metrics | GET `/openapi` | [OpenAPI v3 JSON](https://spec.openapis.org/oas/v3.0.0) diff --git a/src/fetch/aggregate.ts b/src/fetch/aggregate.ts new file mode 100644 index 0000000..673d993 --- /dev/null +++ b/src/fetch/aggregate.ts @@ -0,0 +1,18 @@ +import { makeQuery } from "../clickhouse/makeQuery.js"; +import { logger } from "../logger.js"; +import { getAggregate } from "../queries.js"; +import * as prometheus from "../prometheus.js"; + +export default async function (req: Request) { + try { + const { searchParams } = new URL(req.url); + logger.info({searchParams: Object.fromEntries(Array.from(searchParams))}); + const query = await getAggregate(searchParams); + const response = await makeQuery(query) + return new Response(JSON.stringify(response.data), { headers: { "Content-Type": "application/json" } }); + } catch (e: any) { + logger.error(e); + prometheus.request_error.inc({pathname: "/sales/aggregate", status: 400}); + return new Response(e.message, { status: 400 }); + } +} \ No newline at end of file diff --git a/src/fetch/openapi.ts b/src/fetch/openapi.ts index 0730013..e8f4950 100644 --- a/src/fetch/openapi.ts +++ b/src/fetch/openapi.ts @@ -159,7 +159,7 @@ export default new OpenApiBuilder() get: { tags: [TAGS.USAGE], summary: "Get aggregate of sales", - description: "Get aggregate of sales by `collection_name`, `timestamp` or `block_number`", + description: "Get aggregate of sales filtered by `collection_name`, `timestamp` or `block_number`", parameters: [ { name: "aggregate_function",