Skip to content

Commit

Permalink
Merge pull request #26 from erik1110/feature/api
Browse files Browse the repository at this point in the history
[fix] fix delete order
  • Loading branch information
erik1110 committed Feb 6, 2024
2 parents 2cfefb7 + bdbc976 commit f7c6477
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/features/order/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ export class OrderService {
}

async deleteMyOrder(id: string, req: Request) {
const existingOrder = await this.orderModel.findOne({
_id: id,
orderUserId: req['user']._id,
});

if (!existingOrder) {
throw new AppError(HttpStatus.NOT_FOUND, 'UserError', '此訂單不存在');
}

if (existingOrder.status == -1) {
throw new AppError(HttpStatus.NOT_FOUND, 'UserError', '此訂單已被刪除');
}

const result = await this.orderModel.findByIdAndUpdate(
{
_id: id,
Expand All @@ -110,11 +123,7 @@ export class OrderService {
runValidators: true,
},
);
if (!result) {
throw new AppError(HttpStatus.NOT_FOUND, 'UserError', '此訂單不存在');
} else if (result.status == -1) {
throw new AppError(HttpStatus.NOT_FOUND, 'UserError', '此訂單已被刪除');
}

return getHttpResponse.successResponse({
message: '刪除訂單',
});
Expand Down

0 comments on commit f7c6477

Please sign in to comment.