bugs
This commit is contained in:
+12
-12
@@ -1,6 +1,6 @@
|
||||
import { Controller, Get, Post, Param, UseGuards, Patch, Query, Body } from '@nestjs/common';
|
||||
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 { UserId } from '../../../common/decorators/user-id.decorator';
|
||||
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
||||
@@ -15,22 +15,22 @@ import { CreateInvoiceDto } from '../dto/create-invoice.dto';
|
||||
@ApiTags('orders')
|
||||
@ApiBearerAuth()
|
||||
@Controller()
|
||||
export class OrdersController {
|
||||
constructor(private readonly ordersService: OrdersService) { }
|
||||
export class OrderController {
|
||||
constructor(private readonly orderService: OrderService) { }
|
||||
|
||||
@Post('public/checkout')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Checkout : create order ' })
|
||||
@ApiBody({ type: CreateOrderDto })
|
||||
checkout(@UserId() userId: string, @Body() body: CreateOrderDto) {
|
||||
return this.ordersService.createOrder(userId, body);
|
||||
return this.orderService.createOrder(userId, body);
|
||||
}
|
||||
|
||||
@Get('public/orders')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||
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
|
||||
}
|
||||
|
||||
@@ -42,19 +42,19 @@ export class OrdersController {
|
||||
@Param('orderItemId') orderItemId: string,
|
||||
@UserId() userId: string
|
||||
) {
|
||||
return this.ordersService.confirmOrderItem(userId, orderId, +orderItemId);
|
||||
return this.orderService.confirmOrderItem(userId, orderId, +orderItemId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*========================== Admin Routes =====================*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*========================== Admin Routes =====================*/
|
||||
@Post('admin/orders/:orderId/create-invoice')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Create invoice for new order' })
|
||||
createInvoice(@Param('orderId') orderId: string, @Body() body: CreateInvoiceDto) {
|
||||
return this.ordersService.createInvoice(orderId, body);
|
||||
return this.orderService.createInvoice(orderId, body);
|
||||
}
|
||||
// @UseGuards(AdminAuthGuard)
|
||||
// @Permissions(Permission.MANAGE_ORDERS)
|
||||
@@ -61,8 +61,11 @@ export class Order extends BaseEntity {
|
||||
@Property({ type: 'decimal', precision: 10, scale: 0 })
|
||||
paidAmount!: number;
|
||||
|
||||
// balance!: number;
|
||||
@Property({ type: 'decimal', precision: 10, scale: 0 })
|
||||
balance!: number;
|
||||
get balance():number{
|
||||
return this.total- this.paidAmount
|
||||
}
|
||||
|
||||
// @Property({ type: 'text', nullable: true })
|
||||
// description?: string;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Module, forwardRef } from '@nestjs/common';
|
||||
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
||||
import { OrdersService } from './providers/orders.service';
|
||||
import { OrdersController } from './controllers/orders.controller';
|
||||
import { OrderService } from './providers/order.service';
|
||||
import { OrderController } from './controllers/order.controller';
|
||||
import { Order } from './entities/order.entity';
|
||||
import { OrderItem } from './entities/order-item.entity';
|
||||
import { AuthModule } from '../auth/auth.module';
|
||||
@@ -31,9 +31,9 @@ import { OrderItemRepository } from './repositories/order-item.repository';
|
||||
productModule,
|
||||
TicketModule
|
||||
],
|
||||
controllers: [OrdersController],
|
||||
providers: [OrdersService, OrderRepository, OrderListeners,
|
||||
controllers: [OrderController],
|
||||
providers: [OrderService, OrderRepository, OrderListeners,
|
||||
OrdersCrone, OrderItemRepository],
|
||||
exports: [OrderRepository, OrdersService],
|
||||
exports: [OrderRepository, OrderService],
|
||||
})
|
||||
export class OrderModule { }
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { Injectable, NotFoundException, BadRequestException, Logger } from '@nestjs/common';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { Order } from '../entities/order.entity';
|
||||
import { OrderItem } from '../entities/order-item.entity';
|
||||
import { User } from '../../user/entities/user.entity';
|
||||
import { PaymentMethodEnum, PaymentStatusEnum } from '../../payment/interface/payment';
|
||||
import { PaymentsService } from '../../payment/services/payments.service';
|
||||
import { PaymentService } from '../../payment/services/payments.service';
|
||||
import { OrderRepository } from '../repositories/order.repository';
|
||||
import { FindOrdersDto } from '../dto/find-orders.dto';
|
||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||
@@ -32,7 +29,7 @@ export class OrderService {
|
||||
private readonly em: EntityManager,
|
||||
private readonly orderRepository: OrderRepository,
|
||||
private readonly orderItemRepository: OrderItemRepository,
|
||||
private readonly paymentsService: PaymentsService,
|
||||
// private readonly paymentsService: PaymentService,
|
||||
private readonly userService: UserService,
|
||||
private readonly productService: ProductService,
|
||||
private readonly productRepository: ProductRepository,
|
||||
@@ -167,7 +164,7 @@ export class OrderService {
|
||||
}
|
||||
|
||||
async confirmOrderItem(userId: string, orderId: string, orderItemId: number) {
|
||||
|
||||
|
||||
const orderItem = await this.orderItemRepository.findOne({ id: orderItemId, order: { id: orderId } },
|
||||
{ populate: ['order', 'order.user'] })
|
||||
|
||||
@@ -179,7 +176,7 @@ export class OrderService {
|
||||
throw new BadRequestException("Order Item does not belong to you")
|
||||
}
|
||||
|
||||
orderItem.status=OrderItemStatus.CONFIRMED
|
||||
orderItem.status = OrderItemStatus.CONFIRMED
|
||||
|
||||
this.em.persistAndFlush(OrderItem)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user