Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass tenantId for booking created statistics #116

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions services/statisticsservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ components:
type: integer
adviceSeekerId:
type: string
tenantId:
type: integer
format: int64
description: The id of the tenant

BookingRescheduledStatisticsEventMessage:
type: object
Expand Down
11 changes: 11 additions & 0 deletions services/useradminservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,17 @@ components:
type: array
items:
$ref: './../services/agencyadminservice.yaml#/components/schemas/AgencyAdminResponseDTO'
isGroupchatConsultant:
$ref: '#/components/schemas/IsGroupchatConsultant'
tenantId:
type: integer
tenantName:
type: string

IsGroupchatConsultant:
type: boolean
example: true


AskerResponseDTO:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.vi.appointmentservice.model.CalcomUserToConsultant;
import com.vi.appointmentservice.repository.CalcomBookingToAskerRepository;
import com.vi.appointmentservice.repository.UserToConsultantRepository;
import com.vi.appointmentservice.useradminservice.generated.web.model.ConsultantDTO;
import com.vi.appointmentservice.userservice.generated.web.model.EnquiryAppointmentDTO;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -118,15 +119,17 @@ private EnquiryAppointmentDTO getEnquiryAppointmentDTO(CalcomWebhookInputPayload
}

private String getConsultantId(Integer bookingId) {
return getConsultantByBookingId(bookingId).getId();
}

private ConsultantDTO getConsultantByBookingId(Integer bookingId) {
CalcomBooking booking = calComBookingService.getBookingById(Long.valueOf(bookingId));
Optional<CalcomUserToConsultant> calcomUserToConsultant = this.userToConsultantRepository
.findByCalComUserId(
Long.valueOf(booking.getUserId()));
if (calcomUserToConsultant.isPresent()) {
String consultantId = calcomUserToConsultant.get().getConsultantId();
com.vi.appointmentservice.useradminservice.generated.web.model.ConsultantDTO consultant = null;
consultant = this.adminUserService.getConsultantById(consultantId);
return consultant.getId();
return this.adminUserService.getConsultantById(consultantId);
} else {
throw new InternalServerErrorException(
"Could not find calcomUserToConsultant for bookingId " + bookingId);
Expand Down Expand Up @@ -165,8 +168,10 @@ private void createBookingAskerRelation(CalcomWebhookInputPayload payload,
private void createStatisticsEvent(String eventType, CalcomWebhookInputPayload payload) {
switch (eventType) {
case "BOOKING_CREATED":
var consultant = this.getConsultantByBookingId(payload.getBookingId());
Long tenantId = consultant.getTenantId() != null ? consultant.getTenantId().longValue() : null;
statisticsService.fireEvent(new BookingCreatedStatisticsEvent(payload,
this.getConsultantId(payload.getBookingId())));
consultant.getId(), tenantId));
break;
case "BOOKING_RESCHEDULED":
statisticsService.fireEvent(new BookingRescheduledStatisticsEvent(payload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public class BookingCreatedStatisticsEvent implements StatisticsEvent {
private static final EventType EVENT_TYPE = EventType.BOOKING_CREATED;
private final CalcomWebhookInputPayload payload;
private final String consultantId;
private final Long tenantId;

public BookingCreatedStatisticsEvent(CalcomWebhookInputPayload payload, String consultantId){
public BookingCreatedStatisticsEvent(CalcomWebhookInputPayload payload, String consultantId, Long tenantId){
this.payload = payload;
this.consultantId = consultantId;
this.tenantId = tenantId;
OBJECT_MAPPER.registerModule(new JavaTimeModule());
OBJECT_MAPPER.registerModule(buildSimpleModule());
}
Expand Down Expand Up @@ -58,7 +60,8 @@ public Optional<String> getPayload() {
.endTime(toIsoTime(payload.getEndTime().toLocalDateTime()))
.uid(payload.getUid())
.bookingId(payload.getBookingId())
.adviceSeekerId(payload.getMetadata().getUser());
.adviceSeekerId(payload.getMetadata().getUser())
.tenantId(tenantId);

try {
return Optional.of(OBJECT_MAPPER.writeValueAsString(bookingCreatedStatisticsEventMessage));
Expand Down
Loading