feat: reprogramar trabajos de notificación tras el cambio de cita y manejar errores

This commit is contained in:
2026-08-29 11:28:10 -03:00
parent ee9da60b3b
commit 95b3e3698b
@@ -687,6 +687,47 @@ class AppointmentManager implements IAppointmentsManager {
// Update both heatmaps // Update both heatmaps
await this.updateHeatMap(originalConfig); await this.updateHeatMap(originalConfig);
await this.updateHeatMap(newConfig); await this.updateHeatMap(newConfig);
// Reprogram pending notification jobs for the new date/time. The appointment
// was already saved, so tryToSendNotification reads the new start date and
// builds the reminder content (email template included) from it.
try {
// Cancel the jobs scheduled for the original date/time so they don't fire late.
await this.jobService.cancelByAppointment(String(appointment._id));
const reminderEmailContent = await this.tryToSendNotification({
appointmentId: String(appointment._id),
sessionUser: data.sessionUser || "",
type: APPOINTMENT_NOTIFICATION_TYPE.REMINDER,
channel: "email",
});
const reminderWapContent = await this.tryToSendNotification({
appointmentId: String(appointment._id),
sessionUser: data.sessionUser || "",
type: APPOINTMENT_NOTIFICATION_TYPE.REMINDER,
channel: "whatsapp",
});
await this.createReminderNotificationJobs({
appointmentId: String(appointment._id),
companyId: String(appointment.companyId),
clientId: String(appointment.clientId),
clientUserId: reminderEmailContent.checkClient.userId
? String(reminderEmailContent.checkClient.userId)
: undefined,
clientEmail: reminderEmailContent.checkClient.email,
clientPhoneNumber: await this.getOptionalClientWapNumber(reminderEmailContent.checkClient),
companyOwnerId: String(reminderEmailContent.companyCheck.ownerId),
companyName: reminderEmailContent.companyCheck.name,
appointmentStart: appointment.start,
reminderEmailMessage: reminderEmailContent.message,
reminderWapMessage: reminderWapContent.message,
reminderEmailTemplateId: reminderEmailContent.emailTemplateId,
reminderEmailContext: reminderEmailContent.emailContext,
});
} catch (error) {
console.log("Error reprogramming notification jobs after move:", error);
}
} }
public async changeServiceForce(data: ChangeServiceParams): Promise<void> { public async changeServiceForce(data: ChangeServiceParams): Promise<void> {