Trần Viết Sơn
feat: all thing about order
3367e34
raw
history blame
1.79 kB
import {
BaseEntity,
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
OneToMany,
OneToOne,
PrimaryGeneratedColumn,
Relation,
} from 'typeorm';
import { BranchEntity } from './branch.entity.js';
import { UserEntity } from './user.entity.js';
import { OrderType } from '../common/enums/OrderType.enum.js';
import { OrderStatus } from '../common/enums/OrderStatus.enum.js';
import { OrderItemEntity } from './order-item.entity.js';
import { PaymentEntity } from './payment.entity.js';
@Entity('orders')
export class OrderEntity extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ nullable: true })
customer_id: string;
@ManyToOne(() => UserEntity, { nullable: true })
@JoinColumn({ name: 'customer_id' })
customer: Relation<UserEntity>;
@Column()
branch_id: string;
@ManyToOne(() => BranchEntity)
@JoinColumn({ name: 'branch_id' })
branch: Relation<BranchEntity>;
@Column({ nullable: true })
staff_id: string;
@ManyToOne(() => UserEntity, { nullable: true })
@JoinColumn({ name: 'staff_id' })
staff: Relation<UserEntity>;
@Column({ nullable: true })
table_number: number;
@Column()
total_value: number;
@CreateDateColumn()
create_at: Date;
@Column({ type: 'enum', enum: OrderType, default: OrderType.ONLINE })
order_type: OrderType;
@Column({ type: 'enum', enum: OrderStatus, default: OrderStatus.PENDING })
order_status: OrderStatus;
@OneToMany(() => OrderItemEntity, (a) => a.order)
order_items: Relation<OrderItemEntity>[];
@Column({ nullable: true })
payment_id: number;
@OneToOne(() => PaymentEntity, (a) => a.order)
@JoinColumn({ name: 'payment_id' })
payment: Relation<PaymentEntity>;
}