change entity names
This commit is contained in:
@@ -2,7 +2,7 @@ import { BadRequestException, Injectable, NotFoundException } from '@nestjs/comm
|
||||
import { PaymentGatewayEnum, PaymentMethodEnum, PaymentStatusEnum } from '../interface/payment';
|
||||
import { Payment } from '../entities/payment.entity';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { Order } from '../../orders/entities/order.entity';
|
||||
import { Order } from '../../../orders/entities/order.entity';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { GatewayManager } from '../gateways/gateway.manager';
|
||||
import { WalletTransaction } from 'src/modules/users/entities/wallet-transaction.entity';
|
||||
@@ -53,7 +53,7 @@ export class PaymentsService {
|
||||
const order = await this.em.findOne(
|
||||
Order,
|
||||
{ id: orderId },
|
||||
{ populate: ['user', 'restaurant', 'paymentMethod', 'paymentMethod.restaurant'] },
|
||||
{ populate: ['user', 'shop', 'paymentMethod', 'paymentMethod.shop'] },
|
||||
);
|
||||
|
||||
if (!order) {
|
||||
@@ -72,7 +72,7 @@ export class PaymentsService {
|
||||
if (pm.method === PaymentMethodEnum.Online) {
|
||||
if (!pm.gateway) throw new BadRequestException(PaymentMessage.GATEWAY_REQUIRED);
|
||||
if (!pm.merchantId) throw new BadRequestException(PaymentMessage.MERCHANT_ID_REQUIRED);
|
||||
if (!pm.restaurant?.domain) throw new BadRequestException(PaymentMessage.RESTAURANT_DOMAIN_REQUIRED);
|
||||
if (!pm.shop?.domain) throw new BadRequestException(PaymentMessage.RESTAURANT_DOMAIN_REQUIRED);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -81,7 +81,7 @@ export class PaymentsService {
|
||||
method: pm.method,
|
||||
gateway: pm.gateway ?? null,
|
||||
merchantId: pm.merchantId ?? null,
|
||||
restaurantDomain: pm.restaurant.domain ?? null,
|
||||
restaurantDomain: pm.shop.domain ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ export class PaymentsService {
|
||||
// TODO clean this code and refactor it
|
||||
private async handleWalletPayment(ctx: OrderPaymentContext): Promise<void> {
|
||||
await this.em.transactional(async em => {
|
||||
const order = await em.findOne(Order, { id: ctx.order.id }, { populate: ['user', 'restaurant'] });
|
||||
const order = await em.findOne(Order, { id: ctx.order.id }, { populate: ['user', 'shop'] });
|
||||
if (!order) throw new NotFoundException(OrderMessage.NOT_FOUND);
|
||||
|
||||
if (order.status === OrderStatus.PAID) {
|
||||
@@ -105,7 +105,7 @@ export class PaymentsService {
|
||||
|
||||
const walletTransaction = await em.findOne(WalletTransaction, {
|
||||
user: { id: order.user.id },
|
||||
restaurant: { id: order.restaurant.id },
|
||||
shop: { id: order.shop.id },
|
||||
}, {
|
||||
orderBy: { createdAt: 'DESC' }
|
||||
});
|
||||
@@ -130,7 +130,7 @@ export class PaymentsService {
|
||||
|
||||
const newWalletTransaction = em.create(WalletTransaction, {
|
||||
user: order.user,
|
||||
restaurant: order.restaurant,
|
||||
shop: order.shop,
|
||||
amount: ctx.amount,
|
||||
type: WalletTransactionType.DEBIT,
|
||||
reason: WalletTransactionReason.ORDER_PAYMENT,
|
||||
@@ -146,7 +146,7 @@ export class PaymentsService {
|
||||
});
|
||||
this.eventEmitter.emit(
|
||||
paymentSucceedEvent.name,
|
||||
new paymentSucceedEvent(ctx.order.id, ctx.order.restaurant.id, String(ctx.order?.orderNumber) || '', ctx.method, ctx.amount),
|
||||
new paymentSucceedEvent(ctx.order.id, ctx.order.shop.id, String(ctx.order?.orderNumber) || '', ctx.method, ctx.amount),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ export class PaymentsService {
|
||||
});
|
||||
this.eventEmitter.emit(
|
||||
onlinePaymentSucceedEvent.name,
|
||||
new onlinePaymentSucceedEvent(payment.id, payment.order.id, payment.order.restaurant.id, String(payment.order?.orderNumber) || '', payment.amount),
|
||||
new onlinePaymentSucceedEvent(payment.id, payment.order.id, payment.order.shop.id, String(payment.order?.orderNumber) || '', payment.amount),
|
||||
);
|
||||
return payment;
|
||||
}
|
||||
@@ -236,7 +236,7 @@ export class PaymentsService {
|
||||
findAllPaymentsByRestaurantId(restId: string, userId: string) {
|
||||
return this.em.find(
|
||||
Payment,
|
||||
{ order: { restaurant: { id: restId }, user: { id: userId } } },
|
||||
{ order: { shop: { id: restId }, user: { id: userId } } },
|
||||
{ populate: ['order', 'order.paymentMethod'] },
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user