feat: agregar soporte para cancelación de citas por parte del cliente en notificaciones
This commit is contained in:
@@ -46,6 +46,7 @@ export type SendAppointmentNotificationParams = {
|
|||||||
systemToken?: string;
|
systemToken?: string;
|
||||||
type: APPOINTMENT_NOTIFICATION_TYPE;
|
type: APPOINTMENT_NOTIFICATION_TYPE;
|
||||||
channel?: "whatsapp" | "email";
|
channel?: "whatsapp" | "email";
|
||||||
|
allowClientCancellation?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CreateImmediateAppointmentNotificationJobsParams = {
|
export type CreateImmediateAppointmentNotificationJobsParams = {
|
||||||
|
|||||||
@@ -2491,12 +2491,14 @@ public async updateAppointment(data: UpdateAppointmentParams): Promise<void> {
|
|||||||
sessionUser: data.sessionUser,
|
sessionUser: data.sessionUser,
|
||||||
type: APPOINTMENT_NOTIFICATION_TYPE.CANCELLATION,
|
type: APPOINTMENT_NOTIFICATION_TYPE.CANCELLATION,
|
||||||
channel: "email",
|
channel: "email",
|
||||||
|
allowClientCancellation: true,
|
||||||
});
|
});
|
||||||
const wapContent = await this.tryToSendNotification({
|
const wapContent = await this.tryToSendNotification({
|
||||||
appointmentId: String(checkAppointment._id),
|
appointmentId: String(checkAppointment._id),
|
||||||
sessionUser: data.sessionUser,
|
sessionUser: data.sessionUser,
|
||||||
type: APPOINTMENT_NOTIFICATION_TYPE.CANCELLATION,
|
type: APPOINTMENT_NOTIFICATION_TYPE.CANCELLATION,
|
||||||
channel: "whatsapp",
|
channel: "whatsapp",
|
||||||
|
allowClientCancellation: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.createCancellationNotificationJobs({
|
await this.createCancellationNotificationJobs({
|
||||||
@@ -2650,6 +2652,14 @@ public async updateAppointment(data: UpdateAppointmentParams): Promise<void> {
|
|||||||
throw new Error("La compañia no existe");
|
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);
|
const hasSystemToken = this.hasValidSystemToken(data.systemToken);
|
||||||
|
|
||||||
if (!hasSystemToken) {
|
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");
|
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());
|
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({
|
const checkEmployee = await EmployeesList.employees.findOne({
|
||||||
_id: String(checkAppointment.employeeId),
|
_id: String(checkAppointment.employeeId),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user