import { Injectable } from '@nestjs/common'; import { EntityManager, EntityRepository } from '@mikro-orm/postgresql'; import { WalletTransaction } from '../entities/wallet-transaction.entity'; @Injectable() export class WalletTransactionRepository extends EntityRepository { constructor(readonly em: EntityManager) { super(em, WalletTransaction); } async getCurrentWalletBalance(userId: string, restaurantId: string): Promise { const walletTransaction = await this.em.findOne( WalletTransaction, { user: { id: userId }, restaurant: { id: restaurantId }, }, { orderBy: { createdAt: 'desc' } }, ); return walletTransaction?.balance || 0; } }