order
This commit is contained in:
@@ -92,6 +92,7 @@ export class OrderService {
|
|||||||
em.assign(order, rest)
|
em.assign(order, rest)
|
||||||
|
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
|
|
||||||
if (item.id) { // update
|
if (item.id) { // update
|
||||||
const currentItem = order.items.find(i => Number(i.id) == item.id)
|
const currentItem = order.items.find(i => Number(i.id) == item.id)
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ export class OrderService {
|
|||||||
|
|
||||||
const { designerId, productId, ...itemRest } = item
|
const { designerId, productId, ...itemRest } = item
|
||||||
|
|
||||||
let newProduct: Product | undefined
|
let newProduct=currentItem.product
|
||||||
|
|
||||||
if (productId && productId !== currentItem.product.id) {
|
if (productId && productId !== currentItem.product.id) {
|
||||||
|
|
||||||
@@ -145,11 +146,12 @@ export class OrderService {
|
|||||||
|
|
||||||
em.persist(newOrderItem)
|
em.persist(newOrderItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await em.flush()
|
await em.flush()
|
||||||
|
|
||||||
this.logger.log("Order updated as admin")
|
this.logger.log(`order #${order.orderNumber} was updated as Admin`)
|
||||||
|
|
||||||
return order
|
return order
|
||||||
})
|
})
|
||||||
@@ -444,6 +446,7 @@ export class OrderService {
|
|||||||
const admin = adminId ? await this.adminService.findOrFail(adminId) : undefined
|
const admin = adminId ? await this.adminService.findOrFail(adminId) : undefined
|
||||||
const products = await this.productService.findProductsByIds(items.map(item => item.productId))
|
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 desiners = await this.adminService.findByIds(items.map(item => item.designerId).filter(id => id != null))
|
||||||
|
|
||||||
const productMap = new Map(
|
const productMap = new Map(
|
||||||
products.map(p => [Number(p.id), p])
|
products.map(p => [Number(p.id), p])
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -94,9 +94,7 @@ export class ProductService {
|
|||||||
const products = await this.productRepository.find({
|
const products = await this.productRepository.find({
|
||||||
id: { $in: productIds }
|
id: { $in: productIds }
|
||||||
})
|
})
|
||||||
if (productIds.length !== products.length) {
|
|
||||||
throw new BadRequestException("some products not found")
|
|
||||||
}
|
|
||||||
return products
|
return products
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user