user module
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
||||
import { CreditTransaction } from '../entities/credit-transaction.entity';
|
||||
|
||||
@Injectable()
|
||||
export class CreditTransactionRepository extends EntityRepository<CreditTransaction> {
|
||||
constructor(readonly em: EntityManager) {
|
||||
super(em, CreditTransaction);
|
||||
}
|
||||
async getCurrentCredit(userId: string,): Promise<number> {
|
||||
const lastRow = await this.em.findOne(
|
||||
CreditTransaction,
|
||||
{
|
||||
user: { id: userId },
|
||||
},
|
||||
{ orderBy: { createdAt: 'desc' } },
|
||||
);
|
||||
return lastRow?.balance || 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user