diff --git a/src/order/controllers/customer.controller.ts b/src/order/controllers/customer.controller.ts index 009b191..627747c 100644 --- a/src/order/controllers/customer.controller.ts +++ b/src/order/controllers/customer.controller.ts @@ -55,4 +55,16 @@ export class OrderCustomerController { const customerId = _.get(req, 'user._id') return await this.orderService.getPurchaseDetails(customerId, orderId) } + + @Get(':orderId/history') + @ApiOperation({ + summary: 'Get a customer order history' + }) + @ApiOkResponse({ type: DataResponse(OrderDto) }) + @ApiBadRequestResponse({ type: ErrorResponse }) + async getOrderHistory(@Req() req, @Param('orderId') orderId: string) { + const { _id: customerId } = _.get(req, 'user') + const result = await this.orderService.getOrderHistory(customerId, orderId) + return result + } } diff --git a/src/order/services/order.service.ts b/src/order/services/order.service.ts index aa535fc..41520c2 100644 --- a/src/order/services/order.service.ts +++ b/src/order/services/order.service.ts @@ -74,6 +74,17 @@ export class OrderService { }, projection: '+items' }) + } + + public async getOrderHistory(customerId: string, orderId: string) { + const order = await this.orderRepository.findOne({ + conditions: { + _id: orderId, + 'customer._id': customerId, + status: { $ne: OrderStatus.DELETED } + }, + projection: '+orderHistory' + }) if (!order) throw new AppException(Errors.ORDER_NOT_FOUND) @@ -229,7 +240,7 @@ export class OrderService { operations.push({ updateOne: { filter: { 'variants.sku': item.sku }, - update: { $inc: { 'variants.$.quantity': item.quantity }, }, + update: { $inc: { 'variants.$.quantity': item.quantity } }, session } }) @@ -239,7 +250,7 @@ export class OrderService { // 3. Send email/notification to customer // 4. Refund payment - + await session.commitTransaction() return new SuccessResponse(true) } catch (error) {