Files
dpage-api/src/modules/users/repositories/wallet-transaction.repository.ts
T
2026-03-09 11:38:43 +03:30

22 lines
732 B
TypeScript

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<WalletTransaction> {
constructor(readonly em: EntityManager) {
super(em, WalletTransaction);
}
async getCurrentWalletBalance(userId: string, restaurantId: string): Promise<number> {
const walletTransaction = await this.em.findOne(
WalletTransaction,
{
user: { id: userId },
restaurant: { id: restaurantId },
},
{ orderBy: { createdAt: 'desc' } },
);
return walletTransaction?.balance || 0;
}
}