add:wallet
This commit is contained in:
@@ -1476,8 +1476,7 @@ export class InvoicesService {
|
|||||||
|
|
||||||
async findInvoicesByCustomerIds(custmerIds: string[], query: SearchResellerInvoicesQueryDto) {
|
async findInvoicesByCustomerIds(custmerIds: string[], query: SearchResellerInvoicesQueryDto) {
|
||||||
|
|
||||||
const [data, count] = await this.invoiceRepository.findPaginatedListByUserIds(query, custmerIds)
|
return this.invoiceRepository.findPaginatedListByUserIds(query, custmerIds)
|
||||||
|
|
||||||
return { data, count, paginate: true };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,9 +124,9 @@ export class ReferralsService {
|
|||||||
|
|
||||||
async findPaginatedReferedUsers(userIds: string[], query: SearchCustomersDto) {
|
async findPaginatedReferedUsers(userIds: string[], query: SearchCustomersDto) {
|
||||||
|
|
||||||
const [data, count] = await this.referralsRepository.findPaginatedList(userIds, query)
|
const [customers, count] = await this.referralsRepository.findPaginatedList(userIds, query)
|
||||||
|
|
||||||
return { data, count, paginate: true };
|
return { customers, count, paginate: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
async findReferedUsersIds(userIds: string[]) {
|
async findReferedUsersIds(userIds: string[]) {
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
import { ApiProperty } from "@nestjs/swagger";
|
||||||
|
import { IsInt, IsNotEmpty } from "class-validator";
|
||||||
|
|
||||||
|
export class CreateWithdrawRequestDto {
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsInt()
|
||||||
|
@ApiProperty()
|
||||||
|
amount: number;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -12,12 +12,16 @@ import { CreateResellerAgentDto } from './dto/create-reseller-agent.dto';
|
|||||||
import { SearchRewardsRequestQueryDto } from './dto/search-reward-requests.dto';
|
import { SearchRewardsRequestQueryDto } from './dto/search-reward-requests.dto';
|
||||||
import { SearchCustomersDto } from '../users/DTO/search-customers.dto';
|
import { SearchCustomersDto } from '../users/DTO/search-customers.dto';
|
||||||
import { SearchResellerInvoicesQueryDto } from './dto/search-reseller-invoices.dto';
|
import { SearchResellerInvoicesQueryDto } from './dto/search-reseller-invoices.dto';
|
||||||
|
import { PaginationDto } from '../../common/DTO/pagination.dto';
|
||||||
|
import { WalletsService } from '../wallets/providers/wallets.service';
|
||||||
|
import { CreateWithdrawRequestDto } from './dto/create-withdraw-request.dto';
|
||||||
|
|
||||||
@Controller('reseller')
|
@Controller('reseller')
|
||||||
@AuthGuards()
|
@AuthGuards()
|
||||||
export class ResellerController {
|
export class ResellerController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly resellerService: ResellerService,
|
private readonly resellerService: ResellerService,
|
||||||
|
private readonly walletsService: WalletsService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
|
||||||
@@ -94,4 +98,37 @@ export class ResellerController {
|
|||||||
return this.resellerService.findResellerAgentsRewards(userId, query)
|
return this.resellerService.findResellerAgentsRewards(userId, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============ Wallet Transactions =============
|
||||||
|
@ApiOperation({ summary: "get Reseller/Agent Wallet Transactions ==> reseller route" })
|
||||||
|
@ResellerRoute()
|
||||||
|
@Get('wallet/transaction')
|
||||||
|
getWalletTransactionss(@UserDec("id") userId: string, @Query() query: PaginationDto) {
|
||||||
|
return this.walletsService.getTransaction(userId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ Wallet Balance =============
|
||||||
|
|
||||||
|
@ApiOperation({ summary: "get Reseller/Agent Wallet Balance ==> reseller route" })
|
||||||
|
@ResellerRoute()
|
||||||
|
@Get('wallet/balance')
|
||||||
|
getWalletBalance(@UserDec("id") userId: string) {
|
||||||
|
return this.walletsService.getBalance(userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ WithDraw Request =============
|
||||||
|
@ApiOperation({ summary: "Create Reseller/Agent withdraw request ==> reseller route" })
|
||||||
|
@ResellerRoute()
|
||||||
|
@Post('wallet/withdraw')
|
||||||
|
withdrawRequest(@UserDec("id") userId: string, @Body() dto: CreateWithdrawRequestDto) {
|
||||||
|
return this.resellerService.createWithdrawRequest(userId, dto.amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ Remove WithDraw Request =============
|
||||||
|
@ApiOperation({ summary: "remove Reseller/Agent withdraw request ==> reseller route" })
|
||||||
|
@ResellerRoute()
|
||||||
|
@Delete('wallet/withdraw/:id')
|
||||||
|
removeWithdrawRequest(@UserDec("id") userId: string) {
|
||||||
|
return this.walletsService.getBalance(userId)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,15 @@ import { ReferralsModule } from '../referrals/referrals.module';
|
|||||||
import { InvoicesModule } from '../invoices/invoices.module';
|
import { InvoicesModule } from '../invoices/invoices.module';
|
||||||
import { RewardWithdrawRequest } from "../reseller/entities/rewards-withdraw-request.entity";
|
import { RewardWithdrawRequest } from "../reseller/entities/rewards-withdraw-request.entity";
|
||||||
import { WithdrawRequestRepository } from './repositories/withdraw-request.repository';
|
import { WithdrawRequestRepository } from './repositories/withdraw-request.repository';
|
||||||
|
import { WalletsModule } from '../wallets/wallets.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([Reseller, RewardWithdrawRequest]),
|
imports: [TypeOrmModule.forFeature([Reseller, RewardWithdrawRequest]),
|
||||||
UsersModule,
|
UsersModule,
|
||||||
ReferralsModule,
|
ReferralsModule,
|
||||||
InvoicesModule],
|
InvoicesModule,
|
||||||
|
WalletsModule
|
||||||
|
],
|
||||||
controllers: [ResellerController],
|
controllers: [ResellerController],
|
||||||
providers: [ResellerService, ResellerRepository, WithdrawRequestRepository],
|
providers: [ResellerService, ResellerRepository, WithdrawRequestRepository],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -110,7 +110,10 @@ export class ResellerService {
|
|||||||
|
|
||||||
const customerIds = await this.referralService.findReferedUsersIds(agentIds)
|
const customerIds = await this.referralService.findReferedUsersIds(agentIds)
|
||||||
|
|
||||||
return this.invoicesService.findInvoicesByCustomerIds(customerIds, query)
|
const [invoices, count] = await this.invoicesService.findInvoicesByCustomerIds(customerIds, query)
|
||||||
|
|
||||||
|
return { invoices, count, paginate: true };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async findResellerAgentsRewards(userId: string, query: SearchRewardsRequestQueryDto) {
|
async findResellerAgentsRewards(userId: string, query: SearchRewardsRequestQueryDto) {
|
||||||
@@ -127,4 +130,38 @@ export class ResellerService {
|
|||||||
|
|
||||||
return { requests, count, paginate: true };
|
return { requests, count, paginate: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async createWithdrawRequest(userId: string, requestedAmount: number) {
|
||||||
|
const user = await this.usersService.findOneWithPhone(userId)
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
throw new NotFoundException(AuthMessage.USER_NOT_FOUND)
|
||||||
|
}
|
||||||
|
|
||||||
|
const request = this.withdrawRequestRepository.create({
|
||||||
|
requestedAmount,
|
||||||
|
user
|
||||||
|
})
|
||||||
|
|
||||||
|
return this.withdrawRequestRepository.save(request)
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeWithdrawRequest(userId: string, withdrawRequestId: string) {
|
||||||
|
|
||||||
|
const request =await this.withdrawRequestRepository.findOne({
|
||||||
|
where: {
|
||||||
|
id: withdrawRequestId,
|
||||||
|
user: { id: userId }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if(!request){
|
||||||
|
throw new NotFoundException()
|
||||||
|
}
|
||||||
|
if(request.paidAt){
|
||||||
|
throw new BadRequestException("درخواست پرداخت شده قابل حذف نیست")
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.withdrawRequestRepository.remove(request)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user