27 lines
1019 B
TypeScript
27 lines
1019 B
TypeScript
import { Cascade, Collection, Entity, EntityRepositoryType, Enum, ManyToOne, OneToMany, Property } from "@mikro-orm/core";
|
|
|
|
import { BaseEntity } from "../../../common/entities/base.entity";
|
|
import { Business } from "../../businesses/entities/business.entity";
|
|
import { Invoice } from "../../invoices/entities/invoice.entity";
|
|
import { BillType } from "../enums/bill-type.enum";
|
|
import { BillsRepository } from "../repositories/bill.repository";
|
|
|
|
@Entity({ repository: () => BillsRepository })
|
|
export class Bill extends BaseEntity {
|
|
@Enum({ items: () => BillType })
|
|
type: BillType;
|
|
|
|
@ManyToOne(() => Business, { nullable: false, deleteRule: "cascade" })
|
|
business!: Business;
|
|
|
|
@OneToMany(() => Invoice, (invoice) => invoice.bill, { cascade: [Cascade.PERSIST, Cascade.REMOVE], orphanRemoval: true })
|
|
invoices = new Collection<Invoice>(this);
|
|
|
|
/** Set by BillsRepository.getBillsList; not persisted. */
|
|
@Property({ persist: false })
|
|
invoiceCount?: number;
|
|
|
|
|
|
[EntityRepositoryType]?: BillsRepository;
|
|
}
|