Skip to content

Commit

Permalink
Fixed issue with deleting by order
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed May 17, 2024
1 parent 7f523b5 commit d5aded0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/events/events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class EventService {
} catch (error) {
this.logger.error(`{startPaymentProcess} Fatal error: ${error}`);
if (await this.openOrdersService.existsByOrderId(order.id)) {
this.openOrdersService.delete(order.id);
this.openOrdersService.delete({ orderId: order.id });
}
this.publishPaymentFailedEvent(order);
}
Expand Down Expand Up @@ -130,7 +130,7 @@ export class EventService {
// get the order Context for the payment
const openOrder = await this.getOpenOrder(paymentId);
// delete the open order
this.openOrdersService.delete(paymentId);
this.openOrdersService.delete({ paymentId });
return this.publishPaymentProcessedEvent(openOrder.order);
}

Expand Down
10 changes: 4 additions & 6 deletions src/open-orders/open-orders.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@ export class OpenOrdersService {
* @returns A Promise that resolves to the deleted open order.
* @throws NotFoundException if the open order is not found.
*/
async delete(paymentId: string): Promise<OpenOrder> {
this.logger.log(`{delete} Deleting open order for payment: ${paymentId}`);
async delete(query: { paymentId: string } | { orderId: string }): Promise<OpenOrder> {
this.logger.log(`{delete} Deleting open order for: ${JSON.stringify(query)}`);

const deletedOrder = await this.openOrderModel.findOneAndDelete({
paymentId,
});
const deletedOrder = await this.openOrderModel.findOneAndDelete({ query });

if (!deletedOrder) {
throw new NotFoundException(
`Open order for payment: ${paymentId} not found`,
`Open order for ${JSON.stringify(query)} not found`,
);
}

Expand Down

0 comments on commit d5aded0

Please sign in to comment.