48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { Entity, Enum, Index, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
|
import { Order } from './order.entity';
|
|
import { Product } from 'src/modules/product/entities/product.entity';
|
|
// import { OrderItemStatus } from '../interface/order.interface';
|
|
|
|
@Entity({ tableName: 'order_items' })
|
|
@Index({ properties: ['order'] })
|
|
@Index({ properties: ['product'] })
|
|
export class OrderItem extends BaseEntity {
|
|
@PrimaryKey({ type: 'bigint', autoincrement: true })
|
|
id: bigint
|
|
|
|
@ManyToOne(() => Order)
|
|
order!: Order;
|
|
|
|
@ManyToOne(() => Product)
|
|
product!: Product;
|
|
|
|
@Property({ type: 'json' })
|
|
attributesValues: string[]
|
|
|
|
@Property({ type: 'int' })
|
|
quantity!: number;
|
|
|
|
@Property({ type: 'decimal', precision: 10, scale: 0 })
|
|
unitPrice!: number;
|
|
|
|
get subTotal(): number {
|
|
return Number(this.unitPrice) * (this.quantity)
|
|
}
|
|
|
|
@Property({ type: 'decimal', precision: 10, scale: 0, default: 0 })
|
|
discount: number = 0;
|
|
|
|
get total(): number {
|
|
return Number(this.subTotal) - Number(this.discount || 0)
|
|
}
|
|
|
|
@Property({ nullable: true })
|
|
description?: string;
|
|
|
|
// @Enum(() => OrderItemStatus)
|
|
// status!: OrderItemStatus;
|
|
@Property({ nullable: true, columnType: 'timestamptz' })
|
|
confirmedAt?: Date;
|
|
}
|