Skip to content

Commit

Permalink
fix: deleting logic if webhook subscriber method was called for anoth…
Browse files Browse the repository at this point in the history
…er trigger event than booking_created
  • Loading branch information
adnanalicic committed Jul 13, 2022
1 parent 83bad5d commit 352cc88
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,15 @@ public ResponseEntity<String> processBooking(CalcomWebhook calcomWebhook) {
CalcomWebhookPayload payload = calcomWebhook.getPayload();

if (payload != null) {
String askerId = payload.getMetadata().getUser();
Long bookingId = Long.valueOf(payload.getBookingId());

CalcomBookingToAsker userAssociation = new CalcomBookingToAsker(bookingId, askerId);

if (calcomWebhook.getTriggerEvent().equals("BOOKING_CREATED")) {
String askerId = payload.getMetadata().getUser();
CalcomBookingToAsker userAssociation = new CalcomBookingToAsker(bookingId, askerId);

calcomBookingToAskerRepository.save(userAssociation);

} else {
calcomBookingToAskerRepository.delete(userAssociation);
calcomBookingToAskerRepository.deleteByCalcomBookingId(bookingId);
}

return new ResponseEntity<>(String.valueOf(bookingId), HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
public interface CalcomBookingToAskerRepository extends JpaRepository<CalcomBookingToAsker, String> {

List<CalcomBookingToAsker> findByAskerId(String askerId);
void deleteByCalcomBookingId(Long calcomBookingId);
}

0 comments on commit 352cc88

Please sign in to comment.