diff --git a/src/modules/order/providers/order.service.ts b/src/modules/order/providers/order.service.ts index 1ecd5e8..f26a060 100644 --- a/src/modules/order/providers/order.service.ts +++ b/src/modules/order/providers/order.service.ts @@ -92,6 +92,7 @@ export class OrderService { em.assign(order, rest) for (const item of items) { + if (item.id) { // update const currentItem = order.items.find(i => Number(i.id) == item.id) @@ -101,7 +102,7 @@ export class OrderService { const { designerId, productId, ...itemRest } = item - let newProduct: Product | undefined + let newProduct=currentItem.product if (productId && productId !== currentItem.product.id) { @@ -145,11 +146,12 @@ export class OrderService { em.persist(newOrderItem) } + } await em.flush() - this.logger.log("Order updated as admin") + this.logger.log(`order #${order.orderNumber} was updated as Admin`) return order }) @@ -444,6 +446,7 @@ export class OrderService { const admin = adminId ? await this.adminService.findOrFail(adminId) : undefined const products = await this.productService.findProductsByIds(items.map(item => item.productId)) const desiners = await this.adminService.findByIds(items.map(item => item.designerId).filter(id => id != null)) + const productMap = new Map( products.map(p => [Number(p.id), p]) ); diff --git a/src/modules/product/providers/product.service.ts b/src/modules/product/providers/product.service.ts index 9f203c3..f705a9f 100644 --- a/src/modules/product/providers/product.service.ts +++ b/src/modules/product/providers/product.service.ts @@ -94,9 +94,7 @@ export class ProductService { const products = await this.productRepository.find({ id: { $in: productIds } }) - if (productIds.length !== products.length) { - throw new BadRequestException("some products not found") - } + return products }