schema created
This commit is contained in:
@@ -10,11 +10,12 @@ import {
|
||||
} from '../dto/create-order.dto';
|
||||
import { UserService } from 'src/modules/user/providers/user.service';
|
||||
import {
|
||||
OrderStatusEnum,
|
||||
OrderItemStatusEnum,
|
||||
CreateOrderWithItems,
|
||||
CreateOrderItemPopulated,
|
||||
UpdateOrder,
|
||||
UpdateOrderItem
|
||||
UpdateOrderItem,
|
||||
OrderStatusEnum
|
||||
} from '../interface/order.interface';
|
||||
import { OrderItemRepository } from '../repositories/order-item.repository';
|
||||
import { ProductService } from 'src/modules/product/providers/product.service';
|
||||
@@ -65,7 +66,7 @@ export class OrderService {
|
||||
}
|
||||
|
||||
async createOrderAsUser(userId: string, dto: CreateOrderAsUSerDto) {
|
||||
const order = await this.createOrder({ ...dto, userId, status: OrderStatusEnum.CREATED })
|
||||
const order = await this.createOrder({ ...dto, userId })
|
||||
this.logger.log("Order created as user")
|
||||
return order
|
||||
|
||||
@@ -145,7 +146,7 @@ export class OrderService {
|
||||
description: item.description,
|
||||
discount: item.discount,
|
||||
confirmedAt: item.confirmedAt,
|
||||
|
||||
status: OrderItemStatusEnum.CREATED
|
||||
})
|
||||
|
||||
em.persist(newOrderItem)
|
||||
@@ -167,9 +168,9 @@ export class OrderService {
|
||||
|
||||
const order = await this.findOrderOrFail(orderId)
|
||||
|
||||
if (order.status !== OrderStatusEnum.CREATED) {
|
||||
throw new BadRequestException(`You can not update when status is ${order.status}`)
|
||||
}
|
||||
// if (order.status !== OrderStatusEnum.CREATED) {
|
||||
// throw new BadRequestException(`You can not update when status is ${order.status}`)
|
||||
// }
|
||||
|
||||
if (order.user.id !== userId) {
|
||||
throw new BadRequestException(`This order doest belongs to you!`)
|
||||
@@ -214,9 +215,9 @@ export class OrderService {
|
||||
throw new BadRequestException(`This order doesnt belongs to you`)
|
||||
}
|
||||
|
||||
if (orderItem.order.status !== OrderStatusEnum.CREATED) {
|
||||
throw new BadRequestException(`You can not update when status is ${orderItem.order.status}`)
|
||||
}
|
||||
// if (orderItem.order.status !== OrderStatusEnum.CREATED) {
|
||||
// throw new BadRequestException(`You can not update when status is ${orderItem.order.status}`)
|
||||
// }
|
||||
|
||||
if (orderItem.confirmedAt) {
|
||||
throw new BadRequestException(`You can not update when item is confirmed`)
|
||||
@@ -270,9 +271,9 @@ export class OrderService {
|
||||
throw new BadRequestException(`this order is not belongs to you`)
|
||||
}
|
||||
|
||||
if (orderItem.order.status !== OrderStatusEnum.CREATED) {
|
||||
throw new BadRequestException(`You can not delete when order status is ${orderItem.order.status}`)
|
||||
}
|
||||
// if (orderItem.order.status !== OrderStatusEnum.CREATED) {
|
||||
// throw new BadRequestException(`You can not delete when order status is ${orderItem.order.status}`)
|
||||
// }
|
||||
|
||||
if (orderItem.confirmedAt) {
|
||||
throw new BadRequestException(`You can not delete when item is confirmed`)
|
||||
@@ -366,28 +367,28 @@ export class OrderService {
|
||||
throw new BadRequestException("this order doesnt belongs to you")
|
||||
}
|
||||
|
||||
if (![OrderStatusEnum.CREATED].includes(order.status)) {
|
||||
throw new BadRequestException("Order can not be deleted")
|
||||
}
|
||||
// if (![OrderStatusEnum.CREATED].includes(order.status)) {
|
||||
// throw new BadRequestException("Order can not be deleted")
|
||||
// }
|
||||
|
||||
return this.hardDeleteOrder(orderId)
|
||||
}
|
||||
|
||||
async updateStatus(orderId: string, newStatus: OrderStatusEnum) {
|
||||
// async updateStatus(orderId: string, newStatus: OrderStatusEnum) {
|
||||
|
||||
const order = await this.findOrderOrFail(orderId)
|
||||
// const order = await this.findOrderOrFail(orderId)
|
||||
|
||||
order.status = newStatus
|
||||
// // order.status = newStatus
|
||||
|
||||
await this.em.flush()
|
||||
// await this.em.flush()
|
||||
|
||||
return order
|
||||
}
|
||||
// return order
|
||||
// }
|
||||
|
||||
async createInvoice(orderId: string) {
|
||||
const order = await this.updateStatus(orderId, OrderStatusEnum.INVOICED)
|
||||
return order
|
||||
}
|
||||
// async createInvoice(orderId: string) {
|
||||
// const order = await this.updateStatus(orderId, OrderStatusEnum.INVOICED)
|
||||
// return order
|
||||
// }
|
||||
|
||||
async getOrderAsUser(userId: string, orderId: string) {
|
||||
const order = await this.findOrderOrFail(orderId)
|
||||
@@ -401,7 +402,7 @@ export class OrderService {
|
||||
|
||||
private async createOrderItemEntity(order: Order, dto: CreateOrderItemPopulated, em?: EntityManager) {
|
||||
const { attributes, description, quantity, attachments, discount,
|
||||
unitPrice, product, designer, printAttributes } = dto
|
||||
unitPrice, product, designer, printAttributes, status } = dto
|
||||
|
||||
const eM = em ?? this.em
|
||||
return eM.create(
|
||||
@@ -417,6 +418,7 @@ export class OrderService {
|
||||
unitPrice,
|
||||
product,
|
||||
printAttributes: printAttributes,
|
||||
status
|
||||
})
|
||||
}
|
||||
|
||||
@@ -424,7 +426,7 @@ export class OrderService {
|
||||
|
||||
async createOrder(dto: CreateOrderWithItems) {
|
||||
const { items, userId, enableTax,
|
||||
estimatedDays, paymentMethod, status, adminId } = dto
|
||||
estimatedDays, paymentMethod, adminId } = dto
|
||||
|
||||
// Validate and fetch all required entities
|
||||
const user = await this.userService.findOrFail(userId)
|
||||
@@ -447,7 +449,7 @@ export class OrderService {
|
||||
enableTax,
|
||||
estimatedDays,
|
||||
paymentMethod,
|
||||
status,
|
||||
status: OrderStatusEnum.REQUEST,
|
||||
})
|
||||
|
||||
em.persist(order)
|
||||
@@ -486,7 +488,7 @@ export class OrderService {
|
||||
|
||||
async updateOrder(order: Order, param: UpdateOrder) {
|
||||
const { adminId, enableTax,
|
||||
estimatedDays, paymentMethod, status, userId } = param
|
||||
estimatedDays, paymentMethod, userId } = param
|
||||
|
||||
|
||||
if (userId) {
|
||||
@@ -513,13 +515,13 @@ export class OrderService {
|
||||
order.paymentMethod = paymentMethod
|
||||
}
|
||||
|
||||
if (status != undefined) {
|
||||
order.status = status
|
||||
// if (status != undefined) {
|
||||
// order.status = status
|
||||
|
||||
if (status === OrderStatusEnum.INVOICED && !order.invoicedAt) {
|
||||
order.invoicedAt = new Date()
|
||||
}
|
||||
}
|
||||
// if (status === OrderStatusEnum.INVOICED && !order.invoicedAt) {
|
||||
// order.invoicedAt = new Date()
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user