This commit is contained in:
@@ -27,6 +27,8 @@ import { InvoiceItem } from 'src/modules/invoice/entities/invoice-item.entity';
|
||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||
import { UpdateStatusAsDesignerDto } from '../dto/update-status-as-designer.dto';
|
||||
import { UpdateStatusDto } from '../dto/update-status.dto';
|
||||
import { CreateOrderPrintDto } from '../dto/create-order-print.dto';
|
||||
import { OrderPrint } from '../entities/print.entity';
|
||||
|
||||
@Injectable()
|
||||
export class OrderService {
|
||||
@@ -233,9 +235,26 @@ export class OrderService {
|
||||
return order
|
||||
}
|
||||
|
||||
async createPrint(orderId: string, dto: CreateOrderPrintDto): Promise<OrderPrint> {
|
||||
const order = await this.findOrderOrFail(orderId);
|
||||
|
||||
if (order.print) {
|
||||
order.print.fileds = dto.fields;
|
||||
await this.em.flush();
|
||||
return order.print;
|
||||
}
|
||||
|
||||
const print = this.em.create(OrderPrint, {
|
||||
order,
|
||||
fileds: dto.fields,
|
||||
});
|
||||
await this.em.persistAndFlush(print);
|
||||
return print;
|
||||
}
|
||||
|
||||
// -----------Hrlper Methods -----------
|
||||
async findOrderOrFail(id: string): Promise<Order> {
|
||||
const order = await this.em.findOne(Order, { id }, { populate: ['user', 'type', 'product', 'creator'] });
|
||||
const order = await this.em.findOne(Order, { id }, { populate: ['user', 'type', 'product', 'creator', 'print'] });
|
||||
if (!order) {
|
||||
throw new NotFoundException(`Order with ID ${id} not found.`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user