diff --git a/src/modules/order/controllers/order.controller.ts b/src/modules/order/controllers/order.controller.ts index a89c578..1917b21 100644 --- a/src/modules/order/controllers/order.controller.ts +++ b/src/modules/order/controllers/order.controller.ts @@ -38,7 +38,7 @@ export class OrderController { @UseGuards(AuthGuard) @ApiOperation({ summary: 'Get all orders with pagination and filters' }) findAll(@Query() dto: FindOrdersDto, @UserId() userId: string) { - return this.orderService.findUserOrders(userId, dto); + return this.orderService.findOrdersAsUser(userId, dto); } @Get('public/orders/:id') @@ -95,6 +95,12 @@ export class OrderController { return this.orderService.createOrderAsAdmin(adminId, body); } + @Get('admin/orders') + @UseGuards(AuthGuard) + @ApiOperation({ summary: 'Get all orders with pagination and filters' }) + findAllAsAdmin(@Query() dto: FindOrdersDto) { + return this.orderService.findOrdersAsAdmin(dto); + } @Get('admin/orders/:id') @UseGuards(AdminAuthGuard) diff --git a/src/modules/order/dto/create-order.dto.ts b/src/modules/order/dto/create-order.dto.ts index 8cff6ec..ce86aee 100644 --- a/src/modules/order/dto/create-order.dto.ts +++ b/src/modules/order/dto/create-order.dto.ts @@ -39,7 +39,7 @@ export class CreateOrderItemAsUserDto { export class CreateOrderItemDtoAsAdmin extends CreateOrderItemAsUserDto { @ApiPropertyOptional({ example: [] }) @IsArray() - print?: IField[] + printAttributes?: IField[] @ApiPropertyOptional({ example: [] }) @IsArray() @@ -101,7 +101,9 @@ export class CreateOrderAsAdminDto { print: [{ fieldId: '', value: '' }], printAttachments: [{ url: '', type: '' }], quantity: 100, - attributesValues: [] + attributes: [], + unitPrice:150000, + discount:20000 } ] }) diff --git a/src/modules/order/entities/order-item.entity.ts b/src/modules/order/entities/order-item.entity.ts index 2f81a39..680013a 100644 --- a/src/modules/order/entities/order-item.entity.ts +++ b/src/modules/order/entities/order-item.entity.ts @@ -60,7 +60,7 @@ export class OrderItem { @Property({ type: 'json', nullable: true }) - print?: IField[] // print form selected attributes + printAttributes?: IField[] // print form selected attributes @Property({ nullable: true, columnType: 'timestamptz' }) confirmedAt?: Date; diff --git a/src/modules/order/interface/order.interface.ts b/src/modules/order/interface/order.interface.ts index 166f255..30f0cba 100644 --- a/src/modules/order/interface/order.interface.ts +++ b/src/modules/order/interface/order.interface.ts @@ -41,7 +41,7 @@ export interface CreateOrderItem { unitPrice?: number discount?: number - print?: IField[] + printAttributes?: IField[] printAttachments?: IAttachment[] designerId?: string } diff --git a/src/modules/order/providers/order.service.ts b/src/modules/order/providers/order.service.ts index 2843fa9..e42da9e 100644 --- a/src/modules/order/providers/order.service.ts +++ b/src/modules/order/providers/order.service.ts @@ -196,11 +196,16 @@ export class OrderService { } - async findUserOrders(userId: string, dto: FindOrdersDto) { + async findOrdersAsUser(userId: string, dto: FindOrdersDto) { const orders = await this.orderRepository.findAllPaginated({ userId, ...dto }) return orders } + async findOrdersAsAdmin(dto: FindOrdersDto) { + const orders = await this.orderRepository.findAllPaginated(dto) + return orders + } + // async calculateOrder(inputOrder?: Order, orderId?: string) { // let order: undefined | Order = inputOrder @@ -316,7 +321,7 @@ export class OrderService { private async createOrderItemEntity(order: Order, dto: CreateOrderItemPopulated, em?: EntityManager) { const { attributes, description, quantity, attachments, discount, - unitPrice, product, designer, print, printAttachments } = dto + unitPrice, product, designer, printAttributes, printAttachments } = dto const eM = em ?? this.em return eM.create( @@ -331,7 +336,7 @@ export class OrderService { discount, unitPrice, product, - print, + printAttributes: printAttributes, printAttachments }) } @@ -441,7 +446,7 @@ export class OrderService { async updateOrderItem(orderItem: OrderItem, dto: UpdateOrderItem) { const { attributes, description, product, quantity, - attachments, discount, unitPrice, designer, print, printAttachments } = dto + attachments, discount, unitPrice, designer, printAttributes, printAttachments } = dto if (product && orderItem.product.id !== product.id) { orderItem.product = product @@ -475,8 +480,8 @@ export class OrderService { orderItem.unitPrice = unitPrice } - if (print != undefined) { - orderItem.print = print + if (printAttributes != undefined) { + orderItem.printAttributes = printAttributes } if (attributes != undefined) {