add payment
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-07-19 10:18:33 +03:30
parent 17223ced06
commit d1f85d78f4
4 changed files with 80 additions and 0 deletions
@@ -29,6 +29,7 @@ import { AdminUpdateOrderFeesDto } from '../dto/admin-update-order-fees.dto';
import { AdminAddOrderItemDto } from '../dto/admin-add-order-item.dto';
import { AdminUpdateOrderItemDto } from '../dto/admin-update-order-item.dto';
import { AdminRefundOrderDto } from '../dto/admin-refund-order.dto';
import { AdminAddPaymentDto } from '../dto/admin-add-payment.dto';
import { FoodOrderReportDto, FoodOrderReportSortBy } from '../dto/food-order-report.dto';
import { DailyOrderReportDto, DailyOrderReportSortBy } from '../dto/daily-order-report.dto';
import { CashShiftsService } from './cash-shifts.service';
@@ -545,6 +546,52 @@ export class OrdersService {
return order;
}
async addPayment(orderId: string, restId: string, dto: AdminAddPaymentDto): Promise<Order> {
return this.em.transactional(async em => {
const order = await em.findOne(
Order,
{ id: orderId, restaurant: { id: restId } },
{ populate: ['payments', 'user', 'paymentMethod', 'deliveryMethod', 'items', 'items.food'] },
);
if (!order) {
throw new NotFoundException(OrderMessage.NOT_FOUND);
}
if (order.status === OrderStatus.CANCELED) {
throw new BadRequestException(OrderMessage.ADD_PAYMENT_NOT_ALLOWED);
}
const balance = Number(order.balance ?? 0);
if (balance <= 0) {
throw new BadRequestException(OrderMessage.ADD_PAYMENT_NO_BALANCE);
}
const amount = Number(dto.amount);
if (!amount || amount <= 0) {
throw new BadRequestException(PaymentMessage.AMOUNT_MUST_BE_GREATER_THAN_ZERO);
}
const payment = em.create(Payment, {
order,
amount,
method: PaymentMethodEnum.Cash,
gateway: null,
status: PaymentStatusEnum.Paid,
paidAt: new Date(),
description: dto.description?.trim() || null,
});
em.persist(payment);
await em.flush();
return em.findOneOrFail(
Order,
{ id: orderId },
{ populate: ['payments', 'user', 'paymentMethod', 'deliveryMethod', 'items', 'items.food'] },
);
});
}
async refundOrder(orderId: string, restId: string, dto: AdminRefundOrderDto): Promise<Order> {
return this.em.transactional(async em => {
const order = await em.findOne(