This commit is contained in:
2026-02-22 11:41:44 +03:30
parent bada696f78
commit 973a4596af
4 changed files with 25 additions and 6 deletions
+20 -1
View File
@@ -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.`);
}