update inv entity

This commit is contained in:
2026-02-18 23:15:45 +03:30
parent 1bef27364d
commit 6b2aeddedd
4 changed files with 24 additions and 17 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
import { Index, Property, Filter, OptionalProps, PrimaryKey } from '@mikro-orm/core';
import { Property, Filter, PrimaryKey } from '@mikro-orm/core';
import { ulid } from 'ulid';
@@ -6,7 +6,7 @@ import { ulid } from 'ulid';
export abstract class BaseEntity {
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
id: string = ulid()
@Property({ defaultRaw: 'now()', columnType: 'timestamptz' })
createdAt: Date = new Date();
@@ -1,6 +1,5 @@
import { Entity, Enum, Index, ManyToOne, OptionalProps, Property } from '@mikro-orm/core';
import { Entity, ManyToOne, OptionalProps, Property } from '@mikro-orm/core';
import { Product } from 'src/modules/product/entities/product.entity';
import { IField } from 'src/modules/order/interface/order.interface';
import { BaseEntity } from 'src/common/entities/base.entity';
import { Invoice } from './invoice.entity';
@@ -15,8 +14,6 @@ export class InvoiceItem extends BaseEntity {
@ManyToOne(() => Product)
product!: Product;
@Property({ type: 'json', nullable: true })
attributes?: IField[]
@Property({ type: 'int' })
quantity!: number;
@@ -49,8 +46,15 @@ export class InvoiceItem extends BaseEntity {
@Property({ type: 'text', nullable: true })
description?: string;
@Property({ type: 'string', nullable: true })
paymentMethod?: string;
@Property({ nullable: true, columnType: 'timestamptz' })
confirmedAt?: Date;
@Property({ type: 'json', nullable: true })
attachments?: string[]
}
+12 -11
View File
@@ -13,23 +13,26 @@ import {
import { User } from '../../user/entities/user.entity';
import { Payment } from 'src/modules/payment/entities/payment.entity';
import { ulid } from 'ulid';
import { Admin } from 'src/modules/admin/entities/admin.entity';
import { BaseEntity } from 'src/common/entities/base.entity';
import { InvoiceStatusEnum } from '../enum/invoice-status.enum';
import { InvoiceItem } from './invoice-item.entity';
import { Request } from 'src/modules/request/entities/request.entity';
@Entity({ tableName: 'invoices' })
@Index({ properties: ['user'] })
export class Invoice extends BaseEntity {
[OptionalProps]?: 'createdAt' | 'deletedAt' | 'orderNumber'
[OptionalProps]?: 'createdAt' | 'deletedAt' | 'invoiceNumber'
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
id: string = ulid()
@ManyToOne(() => User)
user!: User;
@ManyToOne(() => Request)
request!: Request;
@OneToMany(() => Payment, payment => payment.order, {
cascade: [Cascade.ALL],
orphanRemoval: true,
@@ -42,8 +45,6 @@ export class Invoice extends BaseEntity {
})
items = new Collection<InvoiceItem>(this);
@ManyToOne(() => Admin, { nullable: true })
creator?: Admin
@Property({
type: 'int',
@@ -76,15 +77,15 @@ export class Invoice extends BaseEntity {
balance: number = 0;
@Property({ type: 'int', nullable: true })
estimatedDays?: number; // number of days to be done
@Enum(() => InvoiceStatusEnum)
status: InvoiceStatusEnum = InvoiceStatusEnum.PENDING;
// @Enum(() => InvoiceStatusEnum)
// status: InvoiceStatusEnum = InvoiceStatusEnum.PENDING;
@Property({ type: 'boolean', default: false })
enableTax?: boolean = false
@Property({ nullable: true, columnType: 'timestamptz' })
approvalDeadline?: Date;
}
@@ -15,6 +15,7 @@ import { ulid } from 'ulid';
import { BaseEntity } from 'src/common/entities/base.entity';
import { RequestItem } from './request-item.entity';
import { RequestStatusEnum } from '../enum/request';
import { Invoice } from 'src/modules/invoice/entities/invoice.entity';
@Entity({ tableName: 'requests' })
@Index({ properties: ['user'] })
@@ -28,6 +29,7 @@ export class Request extends BaseEntity {
@ManyToOne(() => User)
user!: User;
@OneToMany(()=>Invoice,(invoice)=>invoice.request)
@OneToMany(() => RequestItem, item => item.request, {
cascade: [Cascade.ALL],