diff --git a/apps/api/src/bank-transactions/bank-transactions.service.ts b/apps/api/src/bank-transactions/bank-transactions.service.ts index 357a66982..99c004600 100644 --- a/apps/api/src/bank-transactions/bank-transactions.service.ts +++ b/apps/api/src/bank-transactions/bank-transactions.service.ts @@ -11,6 +11,7 @@ import { } from '@prisma/client' import { ExportService } from '../export/export.service' import { getTemplateByTable } from '../export/helpers/exportableData' +import { Prisma } from '@prisma/client' import { PrismaService } from '../prisma/prisma.service' import { Response } from 'express' import { CreateBankPaymentDto } from '../donations/dto/create-bank-payment.dto' @@ -35,6 +36,8 @@ export class BankTransactionsService { * @param search (Optional) Search by sender info or description * @param pageIndex (Optional) * @param pageSize (Optional) + * @param sortBy (Optional) Sort by a specific field + * @param sortOrder (Optional) Sort order (ascending or descending) */ async listBankTransactions( bankDonationStatus?: BankDonationStatus, @@ -47,6 +50,10 @@ export class BankTransactionsService { sortBy?: string, sortOrder?: string, ) { + const defaultSort: Prisma.BankTransactionOrderByWithRelationInput = { + transactionDate: 'desc', + } + const data = await this.prisma.bankTransaction.findMany({ where: { bankDonationStatus, @@ -67,11 +74,7 @@ export class BankTransactionsService { }, skip: pageIndex && pageSize ? pageIndex * pageSize : undefined, take: pageSize ? pageSize : undefined, - orderBy: [ - { - [sortBy as string]: sortOrder, - }, - ], + orderBy: [sortBy ? { [sortBy]: sortOrder ? sortOrder : 'desc' } : defaultSort], }) const count = await this.prisma.bankTransaction.count({