forked from wangziqi/gongxue-base
feat: support batch wallet balance changes
This commit is contained in:
@@ -6,7 +6,7 @@ import { Student } from '../entities/student.entity';
|
||||
import { StudentWallet } from '../entities/student-wallet.entity';
|
||||
import { WalletTransaction } from '../entities/wallet-transaction.entity';
|
||||
import { In } from 'typeorm';
|
||||
import { ChangeWalletBalanceDto } from './dto/wallet.dto';
|
||||
import { BatchChangeWalletBalanceDto, ChangeWalletBalanceDto } from './dto/wallet.dto';
|
||||
|
||||
const money = (value: number | string | null | undefined) => Number(Number(value || 0).toFixed(2));
|
||||
|
||||
@@ -92,6 +92,20 @@ export class WalletsService {
|
||||
});
|
||||
}
|
||||
|
||||
async batchChangeBalance(dto: BatchChangeWalletBalanceDto, recordedBy?: number) {
|
||||
const uniqueStudentIds = Array.from(new Set(dto.studentIds));
|
||||
const results: Awaited<ReturnType<WalletsService['changeBalance']>>[] = [];
|
||||
for (const studentId of uniqueStudentIds) {
|
||||
results.push(await this.changeBalance({
|
||||
studentId,
|
||||
amount: dto.amount,
|
||||
type: dto.type,
|
||||
description: dto.description,
|
||||
}, recordedBy));
|
||||
}
|
||||
return { count: uniqueStudentIds.length, results };
|
||||
}
|
||||
|
||||
async debitBill(manager: EntityManager, bill: Bill, recordedBy?: number) {
|
||||
if (bill.status === 'cancelled') return bill;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user