fix : bug in request

This commit is contained in:
2026-04-15 16:41:35 +03:30
parent 36c01fe01c
commit 44114b2436
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -129,7 +129,7 @@ export class ResellerController {
// ============Create WithDraw Request ============= // ============Create WithDraw Request =============
@ApiOperation({ summary: "Create Reseller/Agent withdraw request ==> reseller route" }) @ApiOperation({ summary: "Create Reseller/Agent withdraw request ==> reseller route" })
@ResellerRoute([ResellerType.agent]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Post('withdraw-request') @Post('withdraw-request')
withdrawRequest(@UserDec("id") userId: string, @Body() dto: CreateWithdrawRequestDto) { withdrawRequest(@UserDec("id") userId: string, @Body() dto: CreateWithdrawRequestDto) {
return this.resellerService.createWithdrawRequest(userId, dto.amount) return this.resellerService.createWithdrawRequest(userId, dto.amount)
+8 -1
View File
@@ -13,6 +13,8 @@ import { CreateUserBankAccountDto } from './dto/create-user-bank-account.dto';
import { UserBankAccountRepository } from './repositories/user-bank-account.repository'; import { UserBankAccountRepository } from './repositories/user-bank-account.repository';
import { ResellerType } from '../auth/DTO/verify-reseller-otp.dto'; import { ResellerType } from '../auth/DTO/verify-reseller-otp.dto';
import { PaginationDto } from '../../common/DTO/pagination.dto'; import { PaginationDto } from '../../common/DTO/pagination.dto';
import { WalletsService } from '../wallets/providers/wallets.service';
import Decimal from 'decimal.js';
@Injectable() @Injectable()
export class ResellerService { export class ResellerService {
@@ -23,6 +25,7 @@ export class ResellerService {
private readonly invoicesService: InvoicesService, private readonly invoicesService: InvoicesService,
private readonly withdrawRequestRepository: WithdrawRequestRepository, private readonly withdrawRequestRepository: WithdrawRequestRepository,
private readonly userBankAccountRepository: UserBankAccountRepository, private readonly userBankAccountRepository: UserBankAccountRepository,
private readonly walletsService: WalletsService,
) { } ) { }
async create(dto: CreateResellerDto) { async create(dto: CreateResellerDto) {
@@ -178,12 +181,16 @@ export class ResellerService {
} }
async createWithdrawRequest(userId: string, requestedAmount: number) { async createWithdrawRequest(userId: string, requestedAmount: number) {
const user = await this.usersService.findOneWithPhone(userId) const { user } = await this.usersService.findOneById(userId)
if (!user) { if (!user) {
throw new NotFoundException(AuthMessage.USER_NOT_FOUND) throw new NotFoundException(AuthMessage.USER_NOT_FOUND)
} }
const { balance } = await this.walletsService.getBalance(userId)
if (new Decimal(balance).lessThan(requestedAmount)) {
throw new BadRequestException("برداشت بیشتر از موجودی ممکن نیست")
}
const request = this.withdrawRequestRepository.create({ const request = this.withdrawRequestRepository.create({
requestedAmount, requestedAmount,
user user