fix bugs
This commit is contained in:
@@ -23,6 +23,7 @@ export class OrderController {
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'create order ' })
|
||||
createOrder(@UserId() userId: string, @Body() body: CreateOrderDto) {
|
||||
console.log(userId)
|
||||
return this.orderService.createOrderAsUser(userId, body);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ export class OrderItem extends BaseEntity {
|
||||
@ManyToOne(() => Product)
|
||||
product!: Product;
|
||||
|
||||
@Property({ type: 'json' })
|
||||
attributes: IAttribute[]
|
||||
@Property({ type: 'json', nullable: true })
|
||||
attributes?: IAttribute[]
|
||||
|
||||
@Property({ type: 'int' })
|
||||
quantity!: number;
|
||||
|
||||
@@ -76,7 +76,7 @@ export class Order {
|
||||
// subTotal?: number;
|
||||
@Formula(alias => `
|
||||
(
|
||||
SELECT COALESCE(SUM(oi.sub_total), 0)
|
||||
SELECT COALESCE(SUM(COALESCE(oi.unit_price, 0) * oi.quantity), 0)
|
||||
FROM order_items oi
|
||||
WHERE oi.order_id = ${alias}.id
|
||||
)
|
||||
@@ -91,7 +91,7 @@ export class Order {
|
||||
CASE
|
||||
WHEN ${alias}.enable_tax = true THEN
|
||||
(
|
||||
SELECT COALESCE(SUM(oi.sub_total), 0)
|
||||
SELECT COALESCE(SUM(COALESCE(oi.unit_price, 0) * oi.quantity), 0)
|
||||
FROM order_items oi
|
||||
WHERE oi.order_id = ${alias}.id
|
||||
) * 0.1
|
||||
@@ -108,7 +108,7 @@ export class Order {
|
||||
@Formula(alias => `
|
||||
(
|
||||
(
|
||||
SELECT COALESCE(SUM(oi.sub_total), 0)
|
||||
SELECT COALESCE(SUM(COALESCE(oi.unit_price, 0) * oi.quantity), 0)
|
||||
FROM order_items oi
|
||||
WHERE oi.order_id = ${alias}.id
|
||||
)
|
||||
@@ -122,7 +122,7 @@ export class Order {
|
||||
CASE
|
||||
WHEN ${alias}.enable_tax = true THEN
|
||||
(
|
||||
SELECT COALESCE(SUM(oi.sub_total), 0)
|
||||
SELECT COALESCE(SUM(COALESCE(oi.unit_price, 0) * oi.quantity), 0)
|
||||
FROM order_items oi
|
||||
WHERE oi.order_id = ${alias}.id
|
||||
) * 0.1
|
||||
@@ -158,7 +158,7 @@ export class Order {
|
||||
(
|
||||
(
|
||||
(
|
||||
SELECT COALESCE(SUM(oi.sub_total), 0)
|
||||
SELECT COALESCE(SUM(COALESCE(oi.unit_price, 0) * oi.quantity), 0)
|
||||
FROM order_items oi
|
||||
WHERE oi.order_id = ${alias}.id
|
||||
)
|
||||
@@ -172,7 +172,7 @@ export class Order {
|
||||
CASE
|
||||
WHEN ${alias}.enable_tax = true THEN
|
||||
(
|
||||
SELECT COALESCE(SUM(oi.sub_total), 0)
|
||||
SELECT COALESCE(SUM(COALESCE(oi.unit_price, 0) * oi.quantity), 0)
|
||||
FROM order_items oi
|
||||
WHERE oi.order_id = ${alias}.id
|
||||
) * 0.1
|
||||
@@ -227,7 +227,7 @@ export class Order {
|
||||
|
||||
const maxOrder = await em.findOne(
|
||||
Order,
|
||||
{},
|
||||
{ id: { $ne: null } },
|
||||
{
|
||||
orderBy: { orderNumber: 'DESC' },
|
||||
fields: ['orderNumber'],
|
||||
|
||||
@@ -80,7 +80,7 @@ export class OrderService {
|
||||
}
|
||||
}
|
||||
|
||||
const order = await this.em.transactional(async (em) => {
|
||||
return this.em.transactional(async (em) => {
|
||||
|
||||
const order = this.orderRepository.create({
|
||||
creator: admin,
|
||||
@@ -96,6 +96,7 @@ export class OrderService {
|
||||
em.persist(order)
|
||||
|
||||
const productIds = items.map(item => item.productId)
|
||||
|
||||
const products = await this.productRepository.find({
|
||||
id: { $in: productIds }
|
||||
})
|
||||
@@ -104,19 +105,18 @@ export class OrderService {
|
||||
}
|
||||
|
||||
for (const item of items) {
|
||||
this.persistOrderItem(order, item)
|
||||
await this.persistOrderItem(order, item)
|
||||
}
|
||||
|
||||
// TODO : calculation must be done after create order
|
||||
|
||||
// await this.calculateOrder(order)
|
||||
|
||||
// await em.flush()
|
||||
await em.flush()
|
||||
|
||||
return order
|
||||
})
|
||||
|
||||
return order
|
||||
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ export class OrderService {
|
||||
if (found) {
|
||||
throw new BadRequestException(`Product already exists`)
|
||||
}
|
||||
|
||||
console.log(productId)
|
||||
const product = await this.productRepository.findOne({ id: productId })
|
||||
if (!product) {
|
||||
throw new BadRequestException(`Product not found`)
|
||||
|
||||
Reference in New Issue
Block a user