Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions services/indexer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Fastify from 'fastify';
import cors from '@fastify/cors';
import crypto from 'crypto';
import { rpc } from '@stellar/stellar-sdk';
import { validateEnv, registerErrorHandler } from '@bettapay/validation';
import { validateEnv, registerErrorHandler, PaginationQuery } from '@bettapay/validation';

const env = validateEnv(process.env);
const PORT = Number(process.env.PORT ?? '3003');
Expand Down Expand Up @@ -50,7 +50,9 @@ fastify.get('/api/health', async (request, reply) => {
});

fastify.get('/api/events', async (request, reply) => {
return { events, total: events.length, latestLedgerCursor };
const { limit, offset } = PaginationQuery.parse(request.query ?? {});
const paginatedEvents = events.slice(offset, offset + limit);
return { events: paginatedEvents, total: events.length, latestLedgerCursor };
});

const server = new rpc.Server(env.STELLAR_RPC_URL, { allowHttp: true });
Expand Down
11 changes: 8 additions & 3 deletions services/settlement-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
CreateSettlementBody,
registerErrorHandler,
createErrorResponse,
ErrorCodes
ErrorCodes,
PaginationQuery
} from "@bettapay/validation";
import { Queue, Worker } from 'bullmq';
import { PrismaClient } from '@prisma/client';
Expand Down Expand Up @@ -237,11 +238,15 @@ fastify.get('/api/health', async (_request, reply) => {
});
});

fastify.get('/api/settlements', async (_request, reply) => {
fastify.get('/api/settlements', async (request, reply) => {
const { limit, offset } = PaginationQuery.parse(request.query ?? {});
const records = await prisma.settlement.findMany({
take: limit,
skip: offset,
orderBy: { initiatedAt: 'desc' },
});
return { settlements: records, total: records.length };
const total = await prisma.settlement.count();
return { settlements: records, total };
});

interface ReconcileQuery {
Expand Down
6 changes: 6 additions & 0 deletions shared/validation/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,9 @@ export type CreateSettlementBody = z.infer<typeof CreateSettlementBody>;
export type AuthTokenBody = z.infer<typeof AuthTokenBody>;
export type UpdatePaymentStatusBody = z.infer<typeof UpdatePaymentStatusBody>;
export type UpdateMerchantSettingsBody = z.infer<typeof UpdateMerchantSettingsBody>;

export const PaginationQuery = z.object({
limit: z.coerce.number().max(200).default(50),
offset: z.coerce.number().min(0).default(0),
});
export type PaginationQuery = z.infer<typeof PaginationQuery>;