add logs for charge wallet
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-07-04 14:53:42 +03:30
parent 1d855b45a7
commit 211c3f9807
2 changed files with 33 additions and 3 deletions
@@ -149,6 +149,8 @@ export class RestaurantWalletService {
}
async finishChargeRequest(dto: FinishChargeRequestDto): Promise<RestaurantCreditRequest> {
this.logger.log(`Processing finish charge request for invoice ${dto.invoiceId}`);
return this.defaultEm.transactional(async (em) => {
const creditRequest = await em.findOne(
RestaurantCreditRequest,
@@ -157,17 +159,30 @@ export class RestaurantWalletService {
);
if (!creditRequest) {
this.logger.warn(`Credit request not found for invoice ${dto.invoiceId}`);
throw new NotFoundException(RestMessage.NOT_FOUND);
}
const restaurantId = creditRequest.restaurant.id;
if (creditRequest.status === RestaurantCreditRequestStatus.PAID) {
this.logger.warn(
`Duplicate finish charge callback for invoice ${dto.invoiceId} (restaurant: ${restaurantId}, already PAID)`,
);
return creditRequest;
}
if (creditRequest.status !== RestaurantCreditRequestStatus.PENDING) {
this.logger.warn(
`Cannot finish charge for invoice ${dto.invoiceId} (restaurant: ${restaurantId}, status: ${creditRequest.status})`,
);
throw new BadRequestException('درخواست شارژ کیف پول قابل پردازش نیست');
}
this.logger.log(
`Crediting wallet for restaurant ${restaurantId}: amount=${creditRequest.amount}, invoice=${dto.invoiceId}`,
);
await this.createTransaction({
restaurant: creditRequest.restaurant,
amount: Number(creditRequest.amount),
@@ -179,6 +194,11 @@ export class RestaurantWalletService {
creditRequest.status = RestaurantCreditRequestStatus.PAID;
await em.flush();
const newBalance = await this.getCurrentBalance(restaurantId, em);
this.logger.log(
`Charge request completed for invoice ${dto.invoiceId} (restaurant: ${restaurantId}, credited: ${creditRequest.amount}, new balance: ${newBalance})`,
);
return creditRequest;
});
}
@@ -1,4 +1,4 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { BadRequestException, Injectable, Logger, NotFoundException } from '@nestjs/common';
import { SetupRestaurantDto } from '../dto/setup-restaurant.dto';
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
import { UpdateRestaurantBgDto } from '../dto/update-restaurant-bg.dto';
@@ -41,6 +41,8 @@ import { FindRestaurantCreditRequestsDto } from '../dto/find-restaurant-credit-r
@Injectable()
export class RestaurantsService {
private readonly logger = new Logger(RestaurantsService.name);
constructor(
private readonly em: EntityManager,
private readonly restRepository: RestRepository,
@@ -349,8 +351,16 @@ export class RestaurantsService {
return this.restaurantWalletService.chargeRequest(restId, dto);
}
finishChargeRequest(dto: FinishChargeRequestDto) {
return this.restaurantWalletService.finishChargeRequest(dto);
async finishChargeRequest(dto: FinishChargeRequestDto) {
this.logger.log(`Finishing charge request for invoice ${dto.invoiceId}`);
const creditRequest = await this.restaurantWalletService.finishChargeRequest(dto);
this.logger.log(
`Charge request finished for invoice ${dto.invoiceId} (restaurant: ${creditRequest.restaurant.id}, amount: ${creditRequest.amount}, status: ${creditRequest.status})`,
);
return creditRequest;
}
async updateBackground(id: string, dto: UpdateRestaurantBgDto): Promise<Restaurant> {