order item
This commit is contained in:
@@ -131,7 +131,7 @@ export class CreateOrderAsAdminDto {
|
||||
|
||||
@ApiProperty({})
|
||||
@IsBoolean()
|
||||
enableTax: Boolean
|
||||
enableTax: boolean
|
||||
|
||||
@ApiProperty({})
|
||||
@IsInt()
|
||||
|
||||
@@ -8,7 +8,7 @@ import { BaseEntity } from 'src/common/entities/base.entity';
|
||||
|
||||
@Entity({ tableName: 'order_items' })
|
||||
@Index({ properties: ['order'] })
|
||||
export class OrderItem extends BaseEntity{
|
||||
export class OrderItem extends BaseEntity {
|
||||
[OptionalProps]?: 'createdAt' | 'deletedAt' | 'subTotal' | 'total';
|
||||
|
||||
@ManyToOne(() => Order)
|
||||
@@ -29,18 +29,34 @@ export class OrderItem extends BaseEntity{
|
||||
@Property({ type: 'decimal', precision: 10, scale: 0, nullable: true, })
|
||||
unitPrice?: number;
|
||||
|
||||
@Formula(alias => `
|
||||
COALESCE(${alias}.unit_price, 0) * ${alias}.quantity
|
||||
`)
|
||||
// @Formula(alias => `
|
||||
// COALESCE(${alias}.unit_price, 0) * ${alias}.quantity
|
||||
// `)
|
||||
@Property({
|
||||
type: 'decimal', precision: 10,
|
||||
columnType: 'numeric(10,0) GENERATED ALWAYS AS (COALESCE(unit_price, 0) * quantity) STORED',
|
||||
persist: false,
|
||||
scale: 0,
|
||||
nullable: true
|
||||
})
|
||||
subTotal!: number;
|
||||
|
||||
@Property({ type: 'decimal', precision: 10, scale: 0, nullable: true })
|
||||
@Property({
|
||||
type: 'decimal', precision: 10,
|
||||
scale: 0, nullable: true
|
||||
})
|
||||
discount?: number;
|
||||
|
||||
@Formula(alias => `
|
||||
(COALESCE(${alias}.unit_price, 0) * ${alias}.quantity)
|
||||
- COALESCE(${alias}.discount, 0)
|
||||
`)
|
||||
// @Formula(alias => `
|
||||
// (COALESCE(${alias}.unit_price, 0) * ${alias}.quantity)
|
||||
// - COALESCE(${alias}.discount, 0)
|
||||
// `)
|
||||
@Property({
|
||||
type: 'decimal', precision: 10,
|
||||
scale: 0, nullable: true,
|
||||
columnType: 'numeric(10,0) GENERATED ALWAYS AS ((COALESCE(unit_price, 0) * quantity) - COALESCE(discount, 0)) STORED',
|
||||
persist: false
|
||||
})
|
||||
total!: number;
|
||||
|
||||
@Property({ type: 'text', nullable: true })
|
||||
|
||||
@@ -54,7 +54,7 @@ export type CreateOrderItemPopulated = Omit<CreateOrderItem, 'productId' | 'desi
|
||||
export interface CreateOrder {
|
||||
userId: string
|
||||
status: OrderStatusEnum
|
||||
enableTax?: Boolean
|
||||
enableTax?: boolean
|
||||
paymentMethod?: string
|
||||
adminId?: string
|
||||
estimatedDays?: number
|
||||
|
||||
@@ -85,7 +85,7 @@ export class OrderService {
|
||||
// return updateOrder
|
||||
}
|
||||
|
||||
//TODO : clean
|
||||
|
||||
async updateOrderAsAdmin2(orderId: string, dto: UpdateOrderAsAdminDto) {
|
||||
const order = await this.findOrderOrFail(orderId)
|
||||
|
||||
@@ -324,44 +324,6 @@ export class OrderService {
|
||||
return orders
|
||||
}
|
||||
|
||||
// async calculateOrder(inputOrder?: Order, orderId?: string) {
|
||||
// let order: undefined | Order = inputOrder
|
||||
|
||||
// if (!order && orderId) {
|
||||
// order = await this.findOneOrFail(orderId)
|
||||
// }
|
||||
|
||||
// if (!order) {
|
||||
// throw new BadRequestException("Order not found")
|
||||
// }
|
||||
// // calculate order financials
|
||||
// const subTotal = order.items.reduce((sum, item) => {
|
||||
// return sum + item.subTotal
|
||||
// }, 0)
|
||||
|
||||
// const totalDiscount = order.items.reduce((sum, item) => {
|
||||
// return sum + Number(item.discount)
|
||||
// }, 0)
|
||||
|
||||
|
||||
// const totalBeforeTax = subTotal - totalDiscount
|
||||
// let tax = 0
|
||||
|
||||
// if (order.enableTax) {
|
||||
// tax = 0.1 * totalBeforeTax
|
||||
// }
|
||||
|
||||
// const total = totalBeforeTax + tax
|
||||
|
||||
// // Update Order financial values
|
||||
// // order.subTotal = subTotal
|
||||
// // order.discount = totalDiscount
|
||||
// // order.taxAmount = tax
|
||||
// // order.total = total
|
||||
// // order.balance = total - paidAmount
|
||||
|
||||
// return order
|
||||
// }
|
||||
|
||||
async confirmOrderItem(userId: string, orderId: string, orderItemId: string) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user