add printFormCreatedAt
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
import { Entity, Formula, Index, ManyToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core';
|
import { Entity, Formula, Index, ManyToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core';
|
||||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
|
||||||
import { Order } from './order.entity';
|
import { Order } from './order.entity';
|
||||||
import { Product } from 'src/modules/product/entities/product.entity';
|
import { Product } from 'src/modules/product/entities/product.entity';
|
||||||
import { IAttachment, IField } from '../interface/order.interface';
|
import { IAttachment, IField } from '../interface/order.interface';
|
||||||
import { Admin } from 'src/modules/admin/entities/admin.entity';
|
import { Admin } from 'src/modules/admin/entities/admin.entity';
|
||||||
// import { OrderItemStatus } from '../interface/order.interface';
|
|
||||||
|
|
||||||
@Entity({ tableName: 'order_items' })
|
@Entity({ tableName: 'order_items' })
|
||||||
@Index({ properties: ['order'] })
|
@Index({ properties: ['order'] })
|
||||||
@@ -55,16 +53,15 @@ export class OrderItem {
|
|||||||
@Property({ type: 'json', nullable: true })
|
@Property({ type: 'json', nullable: true })
|
||||||
attachments?: IAttachment[] // user attachments like voice and photos
|
attachments?: IAttachment[] // user attachments like voice and photos
|
||||||
|
|
||||||
// @Property({ type: 'json', nullable: true })
|
|
||||||
// printAttachments?: IAttachment[]
|
|
||||||
|
|
||||||
|
|
||||||
@Property({ type: 'json', nullable: true })
|
@Property({ type: 'json', nullable: true })
|
||||||
printAttributes?: IField[] // print form selected attributes
|
printAttributes?: IField[] // print form selected attributes
|
||||||
|
|
||||||
@Property({ nullable: true, columnType: 'timestamptz' })
|
@Property({ nullable: true, columnType: 'timestamptz' })
|
||||||
confirmedAt?: Date;
|
confirmedAt?: Date;
|
||||||
|
|
||||||
|
@Property({ nullable: true, columnType: 'timestamptz' })
|
||||||
|
printFormCreatedAt?: Date;
|
||||||
|
|
||||||
@Property({ defaultRaw: 'now()', columnType: 'timestamptz' })
|
@Property({ defaultRaw: 'now()', columnType: 'timestamptz' })
|
||||||
createdAt: Date = new Date();
|
createdAt: Date = new Date();
|
||||||
|
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ export interface CreateOrderItem {
|
|||||||
attachments?: IAttachment[]
|
attachments?: IAttachment[]
|
||||||
unitPrice?: number
|
unitPrice?: number
|
||||||
discount?: number
|
discount?: number
|
||||||
|
printFormCreatedAt?: Date
|
||||||
|
|
||||||
printAttributes?: IField[]
|
printAttributes?: IField[]
|
||||||
printAttachments?: IAttachment[]
|
|
||||||
designerId?: string
|
designerId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -240,11 +240,7 @@ export class OrderService {
|
|||||||
|
|
||||||
const orderItem = await this.findOrderItemOrFail(orderId, itemId)
|
const orderItem = await this.findOrderItemOrFail(orderId, itemId)
|
||||||
|
|
||||||
const updated = await this.updateOrderItem(orderItem, dto)
|
const updated = await this.updateOrderItem(orderItem, { ...dto, printFormCreatedAt: new Date() })
|
||||||
|
|
||||||
// await this.calculateOrder(undefined, orderId)
|
|
||||||
|
|
||||||
// await this.em.flush()
|
|
||||||
|
|
||||||
return updated
|
return updated
|
||||||
}
|
}
|
||||||
@@ -372,7 +368,6 @@ export class OrderService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async removeOrderAsUser(userId: string, orderId: string) {
|
async removeOrderAsUser(userId: string, orderId: string) {
|
||||||
const order = await this.findOrderOrFail(orderId)
|
const order = await this.findOrderOrFail(orderId)
|
||||||
|
|
||||||
@@ -415,7 +410,7 @@ export class OrderService {
|
|||||||
|
|
||||||
private async createOrderItemEntity(order: Order, dto: CreateOrderItemPopulated, em?: EntityManager) {
|
private async createOrderItemEntity(order: Order, dto: CreateOrderItemPopulated, em?: EntityManager) {
|
||||||
const { attributes, description, quantity, attachments, discount,
|
const { attributes, description, quantity, attachments, discount,
|
||||||
unitPrice, product, designer, printAttributes, printAttachments } = dto
|
unitPrice, product, designer, printAttributes } = dto
|
||||||
|
|
||||||
const eM = em ?? this.em
|
const eM = em ?? this.em
|
||||||
return eM.create(
|
return eM.create(
|
||||||
@@ -431,7 +426,6 @@ export class OrderService {
|
|||||||
unitPrice,
|
unitPrice,
|
||||||
product,
|
product,
|
||||||
printAttributes: printAttributes,
|
printAttributes: printAttributes,
|
||||||
// printAttachments
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,8 +534,8 @@ export class OrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateOrderItem(orderItem: OrderItem, dto: UpdateOrderItem) {
|
async updateOrderItem(orderItem: OrderItem, dto: UpdateOrderItem) {
|
||||||
const { attributes, description, product, quantity,
|
const { attributes, description, product, quantity, printFormCreatedAt,
|
||||||
attachments, discount, unitPrice, designer, printAttributes, printAttachments } = dto
|
attachments, discount, unitPrice, designer, printAttributes, } = dto
|
||||||
|
|
||||||
if (product && orderItem.product.id !== product.id) {
|
if (product && orderItem.product.id !== product.id) {
|
||||||
orderItem.product = product
|
orderItem.product = product
|
||||||
@@ -573,6 +567,10 @@ export class OrderService {
|
|||||||
orderItem.unitPrice = unitPrice
|
orderItem.unitPrice = unitPrice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (printFormCreatedAt != undefined) {
|
||||||
|
orderItem.printFormCreatedAt = printFormCreatedAt
|
||||||
|
}
|
||||||
|
|
||||||
if (printAttributes != undefined) {
|
if (printAttributes != undefined) {
|
||||||
orderItem.printAttributes = printAttributes
|
orderItem.printAttributes = printAttributes
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user