feat: agregar soporte para cancelación de citas por parte del cliente en notificaciones
This commit is contained in:
@@ -2491,12 +2491,14 @@ public async updateAppointment(data: UpdateAppointmentParams): Promise<void> {
|
||||
sessionUser: data.sessionUser,
|
||||
type: APPOINTMENT_NOTIFICATION_TYPE.CANCELLATION,
|
||||
channel: "email",
|
||||
allowClientCancellation: true,
|
||||
});
|
||||
const wapContent = await this.tryToSendNotification({
|
||||
appointmentId: String(checkAppointment._id),
|
||||
sessionUser: data.sessionUser,
|
||||
type: APPOINTMENT_NOTIFICATION_TYPE.CANCELLATION,
|
||||
channel: "whatsapp",
|
||||
allowClientCancellation: true,
|
||||
});
|
||||
|
||||
await this.createCancellationNotificationJobs({
|
||||
@@ -2650,6 +2652,14 @@ public async updateAppointment(data: UpdateAppointmentParams): Promise<void> {
|
||||
throw new Error("La compañia no existe");
|
||||
}
|
||||
|
||||
const checkClient = await ClientsManager.clients.findOne({
|
||||
_id: String(checkAppointment.clientId),
|
||||
});
|
||||
|
||||
if (!checkClient) {
|
||||
throw new Error("El cliente no existe");
|
||||
}
|
||||
|
||||
const hasSystemToken = this.hasValidSystemToken(data.systemToken);
|
||||
|
||||
if (!hasSystemToken) {
|
||||
@@ -2657,19 +2667,19 @@ public async updateAppointment(data: UpdateAppointmentParams): Promise<void> {
|
||||
throw new Error("No se ha encontrado el usuario o no tiene permisos para realizar esta acción");
|
||||
}
|
||||
|
||||
if (!(await EmployeesList.checkPermission(companyCheck, data.sessionUser, EmployeeRoles.ADMIN))) {
|
||||
const isAuthorizedClientCancellation =
|
||||
data.allowClientCancellation === true &&
|
||||
data.type === APPOINTMENT_NOTIFICATION_TYPE.CANCELLATION &&
|
||||
String(checkClient.userId) === data.sessionUser;
|
||||
|
||||
if (
|
||||
!isAuthorizedClientCancellation &&
|
||||
!(await EmployeesList.checkPermission(companyCheck, data.sessionUser, EmployeeRoles.ADMIN))
|
||||
) {
|
||||
throw new Error(NoPermissionMessage());
|
||||
}
|
||||
}
|
||||
|
||||
const checkClient = await ClientsManager.clients.findOne({
|
||||
_id: String(checkAppointment.clientId),
|
||||
});
|
||||
|
||||
if (!checkClient) {
|
||||
throw new Error("El cliente no existe");
|
||||
}
|
||||
|
||||
const checkEmployee = await EmployeesList.employees.findOne({
|
||||
_id: String(checkAppointment.employeeId),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user