33 Logger ,
44 NotFoundException ,
55 BadRequestException ,
6- Optional ,
76} from '@nestjs/common' ;
87import { PrismaService } from '../prisma/prisma.service' ;
98import { BalanceIndexerService } from '../balance-indexer/balance-indexer.service' ;
@@ -20,6 +19,7 @@ import {
2019 StellarNetworkReferences ,
2120} from './domain/transaction.model' ;
2221import { Transaction as TransactionEntity } from './entities/transaction.entity' ;
22+ import { PaginatedTransactionsDto } from './dto/paginated-transactions.dto' ;
2323import { InsufficientBalanceException } from './domain/insufficient-balance.exception' ;
2424import { WebhookEventEmitterService } from '../webhooks/webhook-event-emitter.service' ;
2525import { CacheService } from '../common/cache/cache.service' ;
@@ -140,15 +140,15 @@ export class TransactionsService {
140140 }
141141
142142 /**
143- * Find all transactions with optional filters
143+ * Find all transactions with optional filters, returns paginated response
144144 */
145145 async findAll ( filters ?: {
146146 senderWalletId ?: string ;
147147 receiverWalletId ?: string ;
148148 status ?: TransactionStatus ;
149149 limit ?: number ;
150150 offset ?: number ;
151- } ) : Promise < TransactionEntity [ ] > {
151+ } ) : Promise < PaginatedTransactionsDto > {
152152 const where : any = { } ;
153153
154154 if ( filters ?. senderWalletId ) {
@@ -163,14 +163,26 @@ export class TransactionsService {
163163 where . status = filters . status ;
164164 }
165165
166- const transactions = await this . prisma . transaction . findMany ( {
167- where,
168- orderBy : { createdAt : 'desc' } ,
169- take : filters ?. limit ,
170- skip : filters ?. offset ,
171- } ) ;
166+ const limit = filters ?. limit ?? 20 ;
167+ const offset = filters ?. offset ?? 0 ;
168+
169+ const [ transactions , total ] = await Promise . all ( [
170+ this . prisma . transaction . findMany ( {
171+ where,
172+ orderBy : { createdAt : 'desc' } ,
173+ take : limit ,
174+ skip : offset ,
175+ } ) ,
176+ this . prisma . transaction . count ( { where } ) ,
177+ ] ) ;
172178
173- return transactions . map ( ( t ) => this . mapPrismaToEntity ( t ) ) ;
179+ return {
180+ data : transactions . map ( ( t ) => this . mapPrismaToEntity ( t ) ) ,
181+ total,
182+ limit,
183+ offset,
184+ hasMore : offset + transactions . length < total ,
185+ } ;
174186 }
175187
176188 /**
@@ -294,12 +306,12 @@ export class TransactionsService {
294306 }
295307
296308 /**
297- * Find transactions by wallet ID with pagination
309+ * Find transactions by wallet ID with pagination metadata
298310 */
299311 async findByWallet (
300312 walletId : string ,
301313 pagination ?: { limit ?: number ; offset ?: number } ,
302- ) : Promise < TransactionEntity [ ] > {
314+ ) : Promise < PaginatedTransactionsDto > {
303315 const wallet = await this . prisma . wallet . findUnique ( {
304316 where : { id : walletId } ,
305317 } ) ;
@@ -308,16 +320,29 @@ export class TransactionsService {
308320 throw new NotFoundException ( `Wallet ${ walletId } not found` ) ;
309321 }
310322
311- const transactions = await this . prisma . transaction . findMany ( {
312- where : {
313- OR : [ { senderWalletId : walletId } , { receiverWalletId : walletId } ] ,
314- } ,
315- orderBy : { createdAt : 'desc' } ,
316- take : pagination ?. limit ,
317- skip : pagination ?. offset ,
318- } ) ;
323+ const limit = pagination ?. limit ?? 20 ;
324+ const offset = pagination ?. offset ?? 0 ;
325+ const where = {
326+ OR : [ { senderWalletId : walletId } , { receiverWalletId : walletId } ] ,
327+ } ;
328+
329+ const [ transactions , total ] = await Promise . all ( [
330+ this . prisma . transaction . findMany ( {
331+ where,
332+ orderBy : { createdAt : 'desc' } ,
333+ take : limit ,
334+ skip : offset ,
335+ } ) ,
336+ this . prisma . transaction . count ( { where } ) ,
337+ ] ) ;
319338
320- return transactions . map ( ( t ) => this . mapPrismaToEntity ( t ) ) ;
339+ return {
340+ data : transactions . map ( ( t ) => this . mapPrismaToEntity ( t ) ) ,
341+ total,
342+ limit,
343+ offset,
344+ hasMore : offset + transactions . length < total ,
345+ } ;
321346 }
322347
323348 /**
0 commit comments