wallet creadit request list
This commit is contained in:
@@ -27,6 +27,7 @@ import { UpdateRestaurantBgDto } from '../dto/update-restaurant-bg.dto';
|
|||||||
import { ChargeRequestDto } from '../dto/charge-request.dto';
|
import { ChargeRequestDto } from '../dto/charge-request.dto';
|
||||||
import { FinishChargeRequestDto } from '../dto/finish-charge-request.dto';
|
import { FinishChargeRequestDto } from '../dto/finish-charge-request.dto';
|
||||||
import { FindRestaurantWalletTransactionsDto } from '../dto/find-restaurant-wallet-transactions.dto';
|
import { FindRestaurantWalletTransactionsDto } from '../dto/find-restaurant-wallet-transactions.dto';
|
||||||
|
import { FindRestaurantCreditRequestsDto } from '../dto/find-restaurant-credit-requests.dto';
|
||||||
|
|
||||||
@ApiTags('restaurants')
|
@ApiTags('restaurants')
|
||||||
@Controller()
|
@Controller()
|
||||||
@@ -122,6 +123,19 @@ export class RestaurantsController {
|
|||||||
return this.restaurantsService.getWalletTransactions(restId, query);
|
return this.restaurantsService.getWalletTransactions(restId, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@Permissions(Permission.UPDATE_RESTAURANT)
|
||||||
|
@ApiOperation({ summary: 'Get restaurant credit requests with pagination' })
|
||||||
|
@Get('admin/restaurants/charge-requests')
|
||||||
|
getCreditRequests(
|
||||||
|
@RestId() restId: string,
|
||||||
|
@Query(new ValidationPipe({ transform: true, whitelist: true }))
|
||||||
|
query: FindRestaurantCreditRequestsDto,
|
||||||
|
) {
|
||||||
|
return this.restaurantsService.getCreditRequests(restId, query);
|
||||||
|
}
|
||||||
|
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Permissions(Permission.UPDATE_RESTAURANT)
|
@Permissions(Permission.UPDATE_RESTAURANT)
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import { IsOptional, IsString, IsNumber, Min, IsIn, IsDateString } from 'class-validator';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
|
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
|
import { RestaurantCreditRequestStatus } from '../interface/restaurant-credit-request.interface';
|
||||||
|
|
||||||
|
const sortOrderOptions = ['asc', 'desc'] as const;
|
||||||
|
type SortOrder = (typeof sortOrderOptions)[number];
|
||||||
|
|
||||||
|
export class FindRestaurantCreditRequestsDto {
|
||||||
|
@ApiPropertyOptional({ description: 'Page number', type: Number, default: 1, minimum: 1 })
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Min(1)
|
||||||
|
@Type(() => Number)
|
||||||
|
page?: number = 1;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'Items per page', type: Number, default: 10, minimum: 1 })
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Min(1)
|
||||||
|
@Type(() => Number)
|
||||||
|
limit?: number = 10;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'Status filter', enum: RestaurantCreditRequestStatus })
|
||||||
|
@IsOptional()
|
||||||
|
@IsIn(Object.values(RestaurantCreditRequestStatus))
|
||||||
|
status?: RestaurantCreditRequestStatus;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'Invoice ID filter', type: String })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
invoiceId?: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'Start date filter (ISO 8601 format)', type: String })
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
startDate?: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'End date filter (ISO 8601 format)', type: String })
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
endDate?: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'Minimum amount filter', type: Number })
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Type(() => Number)
|
||||||
|
minAmount?: number;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'Maximum amount filter', type: Number })
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@Type(() => Number)
|
||||||
|
maxAmount?: number;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'Sort field', type: String, default: 'createdAt' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
orderBy?: string = 'createdAt';
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'Sort direction', enum: sortOrderOptions, default: 'desc' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsIn(sortOrderOptions)
|
||||||
|
order?: SortOrder = 'desc';
|
||||||
|
}
|
||||||
@@ -16,7 +16,9 @@ import { CreateExternalInvoice } from '../interface/external-invoice.interface';
|
|||||||
import { ChargeRequestDto } from '../dto/charge-request.dto';
|
import { ChargeRequestDto } from '../dto/charge-request.dto';
|
||||||
import { FinishChargeRequestDto } from '../dto/finish-charge-request.dto';
|
import { FinishChargeRequestDto } from '../dto/finish-charge-request.dto';
|
||||||
import { FindRestaurantWalletTransactionsDto } from '../dto/find-restaurant-wallet-transactions.dto';
|
import { FindRestaurantWalletTransactionsDto } from '../dto/find-restaurant-wallet-transactions.dto';
|
||||||
|
import { FindRestaurantCreditRequestsDto } from '../dto/find-restaurant-credit-requests.dto';
|
||||||
import { RestaurantCreditTransactionRepository } from '../repositories/restaurant-credit-transaction.repository';
|
import { RestaurantCreditTransactionRepository } from '../repositories/restaurant-credit-transaction.repository';
|
||||||
|
import { RestaurantCreditRequestRepository } from '../repositories/restaurant-credit-request.repository';
|
||||||
import { RestMessage } from 'src/common/enums/message.enum';
|
import { RestMessage } from 'src/common/enums/message.enum';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -28,6 +30,7 @@ export class RestaurantWalletService {
|
|||||||
private readonly httpService: HttpService,
|
private readonly httpService: HttpService,
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
private readonly restaurantCreditTransactionRepository: RestaurantCreditTransactionRepository,
|
private readonly restaurantCreditTransactionRepository: RestaurantCreditTransactionRepository,
|
||||||
|
private readonly restaurantCreditRequestRepository: RestaurantCreditRequestRepository,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async getCurrentBalance(restaurantId: string, em: EntityManager = this.defaultEm): Promise<number> {
|
async getCurrentBalance(restaurantId: string, em: EntityManager = this.defaultEm): Promise<number> {
|
||||||
@@ -44,6 +47,10 @@ export class RestaurantWalletService {
|
|||||||
return this.restaurantCreditTransactionRepository.findAllPaginated(restaurantId, dto);
|
return this.restaurantCreditTransactionRepository.findAllPaginated(restaurantId, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCreditRequests(restaurantId: string, dto: FindRestaurantCreditRequestsDto) {
|
||||||
|
return this.restaurantCreditRequestRepository.findAllPaginated(restaurantId, dto);
|
||||||
|
}
|
||||||
|
|
||||||
async createTransaction(params: {
|
async createTransaction(params: {
|
||||||
restaurant: Restaurant;
|
restaurant: Restaurant;
|
||||||
amount: number;
|
amount: number;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import { RestaurantWalletService } from './restaurant-wallet.service';
|
|||||||
import { ChargeRequestDto } from '../dto/charge-request.dto';
|
import { ChargeRequestDto } from '../dto/charge-request.dto';
|
||||||
import { FinishChargeRequestDto } from '../dto/finish-charge-request.dto';
|
import { FinishChargeRequestDto } from '../dto/finish-charge-request.dto';
|
||||||
import { FindRestaurantWalletTransactionsDto } from '../dto/find-restaurant-wallet-transactions.dto';
|
import { FindRestaurantWalletTransactionsDto } from '../dto/find-restaurant-wallet-transactions.dto';
|
||||||
|
import { FindRestaurantCreditRequestsDto } from '../dto/find-restaurant-credit-requests.dto';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -340,6 +341,10 @@ export class RestaurantsService {
|
|||||||
return this.restaurantWalletService.getTransactions(restId, dto);
|
return this.restaurantWalletService.getTransactions(restId, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCreditRequests(restId: string, dto: FindRestaurantCreditRequestsDto) {
|
||||||
|
return this.restaurantWalletService.getCreditRequests(restId, dto);
|
||||||
|
}
|
||||||
|
|
||||||
chargeRequest(restId: string, dto: ChargeRequestDto) {
|
chargeRequest(restId: string, dto: ChargeRequestDto) {
|
||||||
return this.restaurantWalletService.chargeRequest(restId, dto);
|
return this.restaurantWalletService.chargeRequest(restId, dto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { FilterQuery } from '@mikro-orm/core';
|
||||||
|
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
||||||
|
import { RestaurantCreditRequest } from '../entities/restaurant-credit-request.entity';
|
||||||
|
import { FindRestaurantCreditRequestsDto } from '../dto/find-restaurant-credit-requests.dto';
|
||||||
|
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class RestaurantCreditRequestRepository extends EntityRepository<RestaurantCreditRequest> {
|
||||||
|
constructor(readonly em: EntityManager) {
|
||||||
|
super(em, RestaurantCreditRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
async findAllPaginated(
|
||||||
|
restaurantId: string,
|
||||||
|
dto: FindRestaurantCreditRequestsDto,
|
||||||
|
): Promise<PaginatedResult<RestaurantCreditRequest>> {
|
||||||
|
const {
|
||||||
|
page = 1,
|
||||||
|
limit = 10,
|
||||||
|
status,
|
||||||
|
invoiceId,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
minAmount,
|
||||||
|
maxAmount,
|
||||||
|
orderBy = 'createdAt',
|
||||||
|
order = 'desc',
|
||||||
|
} = dto;
|
||||||
|
|
||||||
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
|
const where: FilterQuery<RestaurantCreditRequest> = {
|
||||||
|
restaurant: { id: restaurantId },
|
||||||
|
};
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
where.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (invoiceId) {
|
||||||
|
where.invoiceId = invoiceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startDate || endDate) {
|
||||||
|
where.createdAt = {};
|
||||||
|
if (startDate) {
|
||||||
|
where.createdAt.$gte = new Date(startDate);
|
||||||
|
}
|
||||||
|
if (endDate) {
|
||||||
|
where.createdAt.$lte = new Date(endDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minAmount !== undefined || maxAmount !== undefined) {
|
||||||
|
where.amount = {};
|
||||||
|
if (minAmount !== undefined) {
|
||||||
|
where.amount.$gte = minAmount;
|
||||||
|
}
|
||||||
|
if (maxAmount !== undefined) {
|
||||||
|
where.amount.$lte = maxAmount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [data, total] = await this.findAndCount(where, {
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
orderBy: { [orderBy]: order.toLowerCase() as 'asc' | 'desc' },
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
meta: {
|
||||||
|
total,
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
totalPages: Math.ceil(total / limit),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ import { UtilsModule } from '../utils/utils.module';
|
|||||||
import { Background } from './entities/background.entity';
|
import { Background } from './entities/background.entity';
|
||||||
import { BackgroundRepository } from './repositories/background.repository';
|
import { BackgroundRepository } from './repositories/background.repository';
|
||||||
import { RestaurantCreditTransactionRepository } from './repositories/restaurant-credit-transaction.repository';
|
import { RestaurantCreditTransactionRepository } from './repositories/restaurant-credit-transaction.repository';
|
||||||
|
import { RestaurantCreditRequestRepository } from './repositories/restaurant-credit-request.repository';
|
||||||
import { RestaurantCreditTransaction } from './entities/restaurant-credit-transaction.entity';
|
import { RestaurantCreditTransaction } from './entities/restaurant-credit-transaction.entity';
|
||||||
import { RestaurantCreditRequest } from './entities/restaurant-credit-request.entity';
|
import { RestaurantCreditRequest } from './entities/restaurant-credit-request.entity';
|
||||||
import { RestaurantWalletService } from './providers/restaurant-wallet.service';
|
import { RestaurantWalletService } from './providers/restaurant-wallet.service';
|
||||||
@@ -31,6 +32,7 @@ import { httpConfig } from 'src/config/http.config';
|
|||||||
RestaurantCrone,
|
RestaurantCrone,
|
||||||
BackgroundRepository,
|
BackgroundRepository,
|
||||||
RestaurantCreditTransactionRepository,
|
RestaurantCreditTransactionRepository,
|
||||||
|
RestaurantCreditRequestRepository,
|
||||||
RestaurantWalletService,
|
RestaurantWalletService,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
|
|||||||
Reference in New Issue
Block a user