bugs
This commit is contained in:
+7
-7
@@ -1,6 +1,6 @@
|
|||||||
import { Controller, Get, Post, Param, UseGuards, Patch, Query, Body } from '@nestjs/common';
|
import { Controller, Get, Post, Param, UseGuards, Patch, Query, Body } from '@nestjs/common';
|
||||||
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiHeader, ApiBody, ApiQuery } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiHeader, ApiBody, ApiQuery } from '@nestjs/swagger';
|
||||||
import { OrdersService } from '../providers/orders.service';
|
import { OrderService } from '../providers/order.service';
|
||||||
import { AuthGuard } from '../../auth/guards/auth.guard';
|
import { AuthGuard } from '../../auth/guards/auth.guard';
|
||||||
import { UserId } from '../../../common/decorators/user-id.decorator';
|
import { UserId } from '../../../common/decorators/user-id.decorator';
|
||||||
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
||||||
@@ -15,22 +15,22 @@ import { CreateInvoiceDto } from '../dto/create-invoice.dto';
|
|||||||
@ApiTags('orders')
|
@ApiTags('orders')
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Controller()
|
@Controller()
|
||||||
export class OrdersController {
|
export class OrderController {
|
||||||
constructor(private readonly ordersService: OrdersService) { }
|
constructor(private readonly orderService: OrderService) { }
|
||||||
|
|
||||||
@Post('public/checkout')
|
@Post('public/checkout')
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
@ApiOperation({ summary: 'Checkout : create order ' })
|
@ApiOperation({ summary: 'Checkout : create order ' })
|
||||||
@ApiBody({ type: CreateOrderDto })
|
@ApiBody({ type: CreateOrderDto })
|
||||||
checkout(@UserId() userId: string, @Body() body: CreateOrderDto) {
|
checkout(@UserId() userId: string, @Body() body: CreateOrderDto) {
|
||||||
return this.ordersService.createOrder(userId, body);
|
return this.orderService.createOrder(userId, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('public/orders')
|
@Get('public/orders')
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||||
async findAll(@Query() dto: FindOrdersDto, @UserId() userId: string) {
|
async findAll(@Query() dto: FindOrdersDto, @UserId() userId: string) {
|
||||||
const orders = await this.ordersService.findAllForUser(userId, dto);
|
const orders = await this.orderService.findAllForUser(userId, dto);
|
||||||
return orders
|
return orders
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ export class OrdersController {
|
|||||||
@Param('orderItemId') orderItemId: string,
|
@Param('orderItemId') orderItemId: string,
|
||||||
@UserId() userId: string
|
@UserId() userId: string
|
||||||
) {
|
) {
|
||||||
return this.ordersService.confirmOrderItem(userId, orderId, +orderItemId);
|
return this.orderService.confirmOrderItem(userId, orderId, +orderItemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ export class OrdersController {
|
|||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
@ApiOperation({ summary: 'Create invoice for new order' })
|
@ApiOperation({ summary: 'Create invoice for new order' })
|
||||||
createInvoice(@Param('orderId') orderId: string, @Body() body: CreateInvoiceDto) {
|
createInvoice(@Param('orderId') orderId: string, @Body() body: CreateInvoiceDto) {
|
||||||
return this.ordersService.createInvoice(orderId, body);
|
return this.orderService.createInvoice(orderId, body);
|
||||||
}
|
}
|
||||||
// @UseGuards(AdminAuthGuard)
|
// @UseGuards(AdminAuthGuard)
|
||||||
// @Permissions(Permission.MANAGE_ORDERS)
|
// @Permissions(Permission.MANAGE_ORDERS)
|
||||||
@@ -61,8 +61,11 @@ export class Order extends BaseEntity {
|
|||||||
@Property({ type: 'decimal', precision: 10, scale: 0 })
|
@Property({ type: 'decimal', precision: 10, scale: 0 })
|
||||||
paidAmount!: number;
|
paidAmount!: number;
|
||||||
|
|
||||||
|
// balance!: number;
|
||||||
@Property({ type: 'decimal', precision: 10, scale: 0 })
|
@Property({ type: 'decimal', precision: 10, scale: 0 })
|
||||||
balance!: number;
|
get balance():number{
|
||||||
|
return this.total- this.paidAmount
|
||||||
|
}
|
||||||
|
|
||||||
// @Property({ type: 'text', nullable: true })
|
// @Property({ type: 'text', nullable: true })
|
||||||
// description?: string;
|
// description?: string;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Module, forwardRef } from '@nestjs/common';
|
import { Module, forwardRef } from '@nestjs/common';
|
||||||
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
||||||
import { OrdersService } from './providers/orders.service';
|
import { OrderService } from './providers/order.service';
|
||||||
import { OrdersController } from './controllers/orders.controller';
|
import { OrderController } from './controllers/order.controller';
|
||||||
import { Order } from './entities/order.entity';
|
import { Order } from './entities/order.entity';
|
||||||
import { OrderItem } from './entities/order-item.entity';
|
import { OrderItem } from './entities/order-item.entity';
|
||||||
import { AuthModule } from '../auth/auth.module';
|
import { AuthModule } from '../auth/auth.module';
|
||||||
@@ -31,9 +31,9 @@ import { OrderItemRepository } from './repositories/order-item.repository';
|
|||||||
productModule,
|
productModule,
|
||||||
TicketModule
|
TicketModule
|
||||||
],
|
],
|
||||||
controllers: [OrdersController],
|
controllers: [OrderController],
|
||||||
providers: [OrdersService, OrderRepository, OrderListeners,
|
providers: [OrderService, OrderRepository, OrderListeners,
|
||||||
OrdersCrone, OrderItemRepository],
|
OrdersCrone, OrderItemRepository],
|
||||||
exports: [OrderRepository, OrdersService],
|
exports: [OrderRepository, OrderService],
|
||||||
})
|
})
|
||||||
export class OrderModule { }
|
export class OrderModule { }
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import { Injectable, NotFoundException, BadRequestException, Logger } from '@nestjs/common';
|
import { Injectable, NotFoundException, BadRequestException, Logger } from '@nestjs/common';
|
||||||
import { EntityManager } from '@mikro-orm/postgresql';
|
import { EntityManager } from '@mikro-orm/postgresql';
|
||||||
import { Order } from '../entities/order.entity';
|
|
||||||
import { OrderItem } from '../entities/order-item.entity';
|
import { OrderItem } from '../entities/order-item.entity';
|
||||||
import { User } from '../../user/entities/user.entity';
|
import { PaymentService } from '../../payment/services/payments.service';
|
||||||
import { PaymentMethodEnum, PaymentStatusEnum } from '../../payment/interface/payment';
|
|
||||||
import { PaymentsService } from '../../payment/services/payments.service';
|
|
||||||
import { OrderRepository } from '../repositories/order.repository';
|
import { OrderRepository } from '../repositories/order.repository';
|
||||||
import { FindOrdersDto } from '../dto/find-orders.dto';
|
import { FindOrdersDto } from '../dto/find-orders.dto';
|
||||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||||
@@ -32,7 +29,7 @@ export class OrderService {
|
|||||||
private readonly em: EntityManager,
|
private readonly em: EntityManager,
|
||||||
private readonly orderRepository: OrderRepository,
|
private readonly orderRepository: OrderRepository,
|
||||||
private readonly orderItemRepository: OrderItemRepository,
|
private readonly orderItemRepository: OrderItemRepository,
|
||||||
private readonly paymentsService: PaymentsService,
|
// private readonly paymentsService: PaymentService,
|
||||||
private readonly userService: UserService,
|
private readonly userService: UserService,
|
||||||
private readonly productService: ProductService,
|
private readonly productService: ProductService,
|
||||||
private readonly productRepository: ProductRepository,
|
private readonly productRepository: ProductRepository,
|
||||||
@@ -179,7 +176,7 @@ export class OrderService {
|
|||||||
throw new BadRequestException("Order Item does not belong to you")
|
throw new BadRequestException("Order Item does not belong to you")
|
||||||
}
|
}
|
||||||
|
|
||||||
orderItem.status=OrderItemStatus.CONFIRMED
|
orderItem.status = OrderItemStatus.CONFIRMED
|
||||||
|
|
||||||
this.em.persistAndFlush(OrderItem)
|
this.em.persistAndFlush(OrderItem)
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -1,5 +1,5 @@
|
|||||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Query } from '@nestjs/common';
|
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Query } from '@nestjs/common';
|
||||||
import { PaymentsService } from '../services/payments.service';
|
import { PaymentService } from '../services/payments.service';
|
||||||
import {
|
import {
|
||||||
ApiTags,
|
ApiTags,
|
||||||
ApiOperation,
|
ApiOperation,
|
||||||
@@ -23,9 +23,9 @@ import { PayOrderDto } from '../dto/pay-order.dto';
|
|||||||
|
|
||||||
@ApiTags('payments')
|
@ApiTags('payments')
|
||||||
@Controller()
|
@Controller()
|
||||||
export class PaymentsController {
|
export class PaymentController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly paymentsService: PaymentsService,
|
private readonly paymentsService: PaymentService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ export class PaymentsController {
|
|||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@ApiOperation({ summary: 'Pay for an order' })
|
@ApiOperation({ summary: 'Pay for an order' })
|
||||||
payAnOrder(@Param('orderId') orderId: string,@Body() dto :PayOrderDto) {
|
payAnOrder(@Param('orderId') orderId: string, @Body() dto: PayOrderDto) {
|
||||||
return this.paymentsService.payOrder(orderId,dto);
|
return this.paymentsService.payOrder(orderId, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Post('public/payments/verify')
|
// @Post('public/payments/verify')
|
||||||
@@ -6,7 +6,7 @@ import { Permission } from 'src/common/enums/permission.enum';
|
|||||||
import { NotifTitleEnum } from 'src/modules/notification/interfaces/notification.interface';
|
import { NotifTitleEnum } from 'src/modules/notification/interfaces/notification.interface';
|
||||||
import { NotificationService } from 'src/modules/notification/services/notification.service';
|
import { NotificationService } from 'src/modules/notification/services/notification.service';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { OrdersService } from 'src/modules/order/providers/orders.service';
|
import { OrderService } from 'src/modules/order/providers/order.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PaymentListeners {
|
export class PaymentListeners {
|
||||||
@@ -17,7 +17,7 @@ export class PaymentListeners {
|
|||||||
private readonly adminService: AdminRepository,
|
private readonly adminService: AdminRepository,
|
||||||
private readonly notificationService: NotificationService,
|
private readonly notificationService: NotificationService,
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
private readonly orderService: OrdersService,
|
private readonly orderService: OrderService,
|
||||||
) {
|
) {
|
||||||
this.orderCreatedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ORDER_CREATED') ?? '123';
|
this.orderCreatedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ORDER_CREATED') ?? '123';
|
||||||
this.paymentSucceedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ONLINE_PAYMENT_SUCCEED') ?? '123';
|
this.paymentSucceedSmsTemplateId = this.configService.get<string>('SMS_PATTERN_ONLINE_PAYMENT_SUCCEED') ?? '123';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Module, forwardRef } from '@nestjs/common';
|
import { Module, forwardRef } from '@nestjs/common';
|
||||||
import { PaymentsService } from './services/payments.service';
|
import { PaymentService } from './services/payments.service';
|
||||||
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
||||||
import { PaymentsController } from './controllers/payments.controller';
|
import { PaymentController } from './controllers/payment.controller';
|
||||||
import { AuthModule } from '../auth/auth.module';
|
import { AuthModule } from '../auth/auth.module';
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
import { Payment } from './entities/payment.entity';
|
import { Payment } from './entities/payment.entity';
|
||||||
@@ -12,17 +12,29 @@ import { PaymentListeners } from './listeners/payment.listeners';
|
|||||||
import { AdminModule } from '../admin/admin.module';
|
import { AdminModule } from '../admin/admin.module';
|
||||||
import { NotificationsModule } from '../notification/notifications.module';
|
import { NotificationsModule } from '../notification/notifications.module';
|
||||||
import { OrderModule } from '../order/order.module';
|
import { OrderModule } from '../order/order.module';
|
||||||
|
import { UserModule } from '../user/user.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [MikroOrmModule.forFeature([Payment]),
|
imports: [
|
||||||
AuthModule, JwtModule, AdminModule, NotificationsModule,
|
MikroOrmModule.forFeature([Payment]),
|
||||||
forwardRef(() => OrderModule)],
|
AuthModule,
|
||||||
controllers: [PaymentsController],
|
JwtModule,
|
||||||
providers: [PaymentsService,
|
AdminModule,
|
||||||
PaymentRepository, ZarinpalGateway, GatewayManager, PaymentListeners],
|
NotificationsModule,
|
||||||
|
forwardRef(() => OrderModule),
|
||||||
|
UserModule
|
||||||
|
],
|
||||||
|
controllers: [PaymentController],
|
||||||
|
providers: [
|
||||||
|
PaymentService,
|
||||||
|
PaymentRepository,
|
||||||
|
ZarinpalGateway,
|
||||||
|
GatewayManager,
|
||||||
|
PaymentListeners
|
||||||
|
],
|
||||||
exports: [
|
exports: [
|
||||||
PaymentRepository,
|
PaymentRepository,
|
||||||
PaymentsService,
|
PaymentService,
|
||||||
// PaymentGatewayService,
|
// PaymentGatewayService,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ import { Payment } from '../entities/payment.entity';
|
|||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PaymentsService {
|
export class PaymentService {
|
||||||
private readonly logger = new Logger(PaymentsService.name);
|
private readonly logger = new Logger(PaymentService.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly em: EntityManager,
|
private readonly em: EntityManager,
|
||||||
@@ -211,7 +211,6 @@ export class PaymentsService {
|
|||||||
// TODO : use decimal js
|
// TODO : use decimal js
|
||||||
// does need persist or not
|
// does need persist or not
|
||||||
payment.order.paidAmount += payment.amount
|
payment.order.paidAmount += payment.amount
|
||||||
payment.order.balance = payment.order.total - payment.order.paidAmount
|
|
||||||
|
|
||||||
await em.flush();
|
await em.flush();
|
||||||
return payment;
|
return payment;
|
||||||
@@ -249,7 +248,6 @@ export class PaymentsService {
|
|||||||
|
|
||||||
// TODO : use decimal js
|
// TODO : use decimal js
|
||||||
payment.order.paidAmount += payment.amount
|
payment.order.paidAmount += payment.amount
|
||||||
payment.order.balance = payment.order.total - payment.order.paidAmount
|
|
||||||
|
|
||||||
em.persist(payment);
|
em.persist(payment);
|
||||||
em.persist(payment.order);
|
em.persist(payment.order);
|
||||||
@@ -259,57 +257,5 @@ export class PaymentsService {
|
|||||||
return payment;
|
return payment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private markPaid(payment: Payment, referenceId: string) {
|
|
||||||
// payment.status = PaymentStatusEnum.Paid;
|
|
||||||
// payment.paidAt = new Date();
|
|
||||||
// payment.referenceId = referenceId;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private failPayment(payment: Payment) {
|
|
||||||
// payment.status = PaymentStatusEnum.Failed;
|
|
||||||
// payment.failedAt = new Date();
|
|
||||||
// payment.order.status = OrderStatus.CANCELED;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// private async getOrCreateLatestPendingPayment(
|
|
||||||
// orderId: string,
|
|
||||||
// params: {
|
|
||||||
// amount: number;
|
|
||||||
// method: PaymentMethodEnum;
|
|
||||||
// gateway: PaymentGatewayEnum | null;
|
|
||||||
// em?: EntityManager;
|
|
||||||
// },
|
|
||||||
// ): Promise<Payment> {
|
|
||||||
// const em = params.em ?? this.em;
|
|
||||||
|
|
||||||
// const existing = await em.findOne(
|
|
||||||
// Payment,
|
|
||||||
// { order: { id: orderId }, status: PaymentStatusEnum.Pending },
|
|
||||||
// { orderBy: { createdAt: 'DESC' } },
|
|
||||||
// );
|
|
||||||
|
|
||||||
// if (existing) {
|
|
||||||
// if (existing.method !== params.method) {
|
|
||||||
// throw new BadRequestException(PaymentMessage.EXISTING_PENDING_PAYMENT_MISMATCH);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return existing;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const orderRef = em.getReference(Order, orderId);
|
|
||||||
// const payment = em.create(Payment, {
|
|
||||||
// amount: params.amount,
|
|
||||||
// order: orderRef,
|
|
||||||
// method: params.method,
|
|
||||||
// gateway: params.gateway,
|
|
||||||
// transactionId: null,
|
|
||||||
// status: PaymentStatusEnum.Pending,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// em.persist(payment);
|
|
||||||
// await em.flush();
|
|
||||||
// return payment;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user