From c94c7d2ff1142d278f83583f1bf983c2ec544ae4 Mon Sep 17 00:00:00 2001 From: EjembiEmmanuel Date: Mon, 9 Sep 2024 16:36:31 +0100 Subject: [PATCH] feat: implement `get_onramp_quotes` endpoint --- backend/src/routes/getOnrampQuotes.ts | 19 +++++++++++++++++++ backend/src/routes/index.ts | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 backend/src/routes/getOnrampQuotes.ts diff --git a/backend/src/routes/getOnrampQuotes.ts b/backend/src/routes/getOnrampQuotes.ts new file mode 100644 index 0000000..26d0774 --- /dev/null +++ b/backend/src/routes/getOnrampQuotes.ts @@ -0,0 +1,19 @@ +import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify' +import { locked } from '@/db/schema' + +import type { Database } from '@/db/drizzle' + +export function getOnrampQuotes(fastify: FastifyInstance) { + fastify.get('/get-onramp-quotes', async (request, reply) => handleGetOnrampQuotes(fastify.db, request, reply)) +} + +async function handleGetOnrampQuotes(db: Database, _request: FastifyRequest, reply: FastifyReply) { + try { + const onRampQuotes = await db.select({ amount: locked.amount }).from(locked) + + return reply.send({ onRampQuotes }) + } catch (error) { + console.error(error) + return reply.status(500).send({ message: 'Internal server error' }) + } +} diff --git a/backend/src/routes/index.ts b/backend/src/routes/index.ts index c8bd697..16a42b4 100644 --- a/backend/src/routes/index.ts +++ b/backend/src/routes/index.ts @@ -1,7 +1,9 @@ import type { FastifyInstance } from 'fastify' import { getHealthRoute } from './getHealth' +import { getOnrampQuotes } from './getOnrampQuotes' export function declareRoutes(fastify: FastifyInstance) { getHealthRoute(fastify) + getOnrampQuotes(fastify) }