Skip to content

Commit

Permalink
[Implement][Order] Get a customer order history
Browse files Browse the repository at this point in the history
  • Loading branch information
nghiavohuynhdai committed Feb 7, 2024
1 parent 9047d4d commit ef5b3c2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/order/controllers/customer.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
15 changes: 13 additions & 2 deletions src/order/services/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
})
Expand All @@ -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) {
Expand Down

0 comments on commit ef5b3c2

Please sign in to comment.