diff --git a/src/modules/order/providers/order.service.ts b/src/modules/order/providers/order.service.ts index b3cee87..0c1726d 100644 --- a/src/modules/order/providers/order.service.ts +++ b/src/modules/order/providers/order.service.ts @@ -63,7 +63,7 @@ export class OrderService { user = invoiceItem.invoice.user } - + if (!invoiceItem) { if (!dto.userId) { @@ -196,12 +196,7 @@ export class OrderService { await this.em.flush(); } - async updateStatusAsDesigner(orderId: string, dto: UpdateStatusAsDesignerDto): Promise { - const order = await this.findOrderOrFail(orderId); - order.status = dto.status; - await this.em.flush(); - return order - } + async updateStatus(orderId: string, adminId: string, dto: UpdateStatusDto): Promise { const permissions = await this.adminService.hasPermissions(adminId, @@ -215,17 +210,14 @@ export class OrderService { } if (permissions.includes(PermissionEnum.VIEW_ASSIGNED_ORDERS)) { + //TODO const order = await this.findOrderOrFailAssignedOrder(orderId, adminId); order.status = dto.status; await this.em.flush(); return order } - - const order = await this.findOrderOrFail(orderId); - - order.status = dto.status; - await this.em.flush(); - return order + + throw new ForbiddenException("You don't have permission to update order status") } async assignDesigner(orderId: string, designerId: string) { @@ -254,7 +246,7 @@ export class OrderService { return print; } - async getPrint(orderId:string){ + async getPrint(orderId: string) { const orderPrint = await this.orderPrintRepository.findOne({ order: { id: orderId } }); if (!orderPrint) { throw new NotFoundException(`Print with ID ${orderId} not found.`); @@ -264,7 +256,7 @@ export class OrderService { // -----------Hrlper Methods ----------- async findOrderOrFail(id: string): Promise { - const order = await this.em.findOne(Order, { id }, { populate: ['user', 'type', 'product', 'creator', 'print'] }); + const order = await this.em.findOne(Order, { id }, { populate: ['user', 'type', 'product', 'creator', 'designer'] }); if (!order) { throw new NotFoundException(`Order with ID ${id} not found.`); }