This commit is contained in:
@@ -99,9 +99,9 @@ export class OrderController {
|
||||
|
||||
@Post('admin/orders/:orderId/print')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(PermissionEnum.ASSIGN_DESIGNER)
|
||||
@Permissions(PermissionEnum.MANAGE_PRINT)
|
||||
@ApiOperation({ summary: 'Create order print' })
|
||||
createPrint(@Param('orderId') orderId: string, @Body() body: CreateOrderPrintDto) {
|
||||
// return this.orderService.assignDesigner(orderId, body.designerId);
|
||||
return this.orderService.createPrint(orderId, body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export class OrderPrint extends BaseEntity {
|
||||
[OptionalProps]?: 'createdAt' | 'deletedAt'
|
||||
|
||||
@Property({ type: 'json', nullable: true })
|
||||
attributes?: IField[]
|
||||
fileds?: IField[]
|
||||
|
||||
|
||||
@OneToOne(() => Order, (order) => order.print, { mappedBy: 'print' })
|
||||
|
||||
@@ -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