28 lines
800 B
TypeScript
28 lines
800 B
TypeScript
import { Entity, Index, ManyToOne, Property } from '@mikro-orm/core';
|
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
|
import { Order } from './order.entity';
|
|
import { Product } from '../../products/entities/product.entity';
|
|
|
|
@Entity({ tableName: 'order_items' })
|
|
@Index({ properties: ['order'] })
|
|
@Index({ properties: ['product'] })
|
|
export class OrderItem extends BaseEntity {
|
|
@ManyToOne(() => Order)
|
|
order!: Order;
|
|
|
|
@ManyToOne(() => Product)
|
|
product!: Product;
|
|
|
|
@Property({ type: 'int' })
|
|
quantity!: number;
|
|
|
|
@Property({ type: 'decimal', precision: 10, scale: 0 })
|
|
unitPrice!: number;
|
|
|
|
@Property({ type: 'decimal', precision: 10, scale: 0, default: 0 })
|
|
discount: number = 0;
|
|
|
|
@Property({ type: 'decimal', precision: 10, scale: 0 })
|
|
totalPrice!: number;
|
|
}
|