@@ -28,7 +28,7 @@ import { v4 as uuidv4 } from "uuid";
2828
2929import { Feedback , Publication , Purchase , Refund , Tester } from "../types/data" ;
3030
31- import { DATABASESCHEMA , FeedbackFlowDB , PurchaseStatus } from "./db" ;
31+ import { DATABASESCHEMA , FeedbackFlowDB , PurchaseStatus , PurchaseStatusResponse } from "./db" ;
3232
3333/**
3434 * In-memory database class for testing purposes
@@ -380,7 +380,7 @@ export class InMemoryDB implements FeedbackFlowDB {
380380 limit ?: number ,
381381 sort ?: string ,
382382 order ?: string ,
383- ) : Promise < PurchaseStatus [ ] > => {
383+ ) : Promise < PurchaseStatusResponse > => {
384384 if ( ! limitToNotRefunded ) {
385385 limitToNotRefunded = false ; // Default to false
386386 }
@@ -420,7 +420,7 @@ export class InMemoryDB implements FeedbackFlowDB {
420420 ) ;
421421
422422 // Build the status for each purchase
423- const result = testerPurchases
423+ let globalResult = testerPurchases
424424 . map ( ( purchase ) => {
425425 // Check for related feedback, publication, and refund
426426 const hasFeedback = this . data . feedbacks . find (
@@ -450,7 +450,13 @@ export class InMemoryDB implements FeedbackFlowDB {
450450 publicationScreenshot : hasPublication ?. screenshot ,
451451 purchaseSreenshot : purchase . screenshot ,
452452 } as PurchaseStatus ;
453- } )
453+ } ) ;
454+
455+ // Filter out refunded purchases if requested
456+ if ( limitToNotRefunded ) {
457+ globalResult = globalResult . filter ( ( purchase ) => ! purchase . refunded ) ;
458+ }
459+ const result = globalResult
454460 . slice ( offset , offset + limit )
455461 . sort ( ( a , b ) => {
456462 if ( sort === "date" ) {
@@ -468,13 +474,22 @@ export class InMemoryDB implements FeedbackFlowDB {
468474 }
469475 } ) ;
470476
471- // Filter out refunded purchases if requested
472- if ( limitToNotRefunded ) {
473- return result . filter ( ( purchase ) => ! purchase . refunded ) ;
474- }
475-
476- return result ;
477- } ,
477+ // Construct the response object with pagination info
478+ const pageInfo = {
479+ totalCount : globalResult . length ,
480+ totalPages : Math . ceil ( globalResult . length / limit ) ,
481+ currentPage : page ,
482+ hasNextPage : page < Math . ceil ( globalResult . length / limit ) ,
483+ hasPreviousPage : page > 1 ,
484+ nextPage : page < Math . ceil ( globalResult . length / limit ) ? page + 1 : null ,
485+ previousPage : page > 1 ? page - 1 : null ,
486+ } ;
487+ const response : PurchaseStatusResponse = {
488+ results : result ,
489+ pageInfo,
490+ } ;
491+ return response ;
492+ }
478493 } ;
479494
480495 /**
0 commit comments