@lautmaler/crm-connectors
Version:
Provides connectors to various CRM systems and calendar services.
64 lines (52 loc) • 1.95 kB
text/typescript
import { CRMBackendFactory } from "./backends/Factory.js";
import { Appointment, CRMBackend } from "./crm.interfaces.js";
import { SupportedBackends } from "./crm.types.js";
// Base CRM class
export class CRMConnector {
/*
* The backend property is an instance of the CRMBackend interface.
* It is created by calling the CRMBackendFactory function with the backendName parameter.
* The backendName parameter is a string that specifies the name of the backend to use.
* The CRMConnector class provides methods for interacting with the CRM system.
*/
private backend: CRMBackend;
constructor(backendName: SupportedBackends) {
this.backend = CRMBackendFactory(backendName);
}
async fetchAppointmentTypes(): Promise<string[]> {
return this.backend.fetchAppointmentTypes();
}
async fetchAvailableSlots(
timestamp: string,
attendees: string[],
): Promise<string[]> {
return this.backend.fetchAvailableSlots(timestamp, attendees);
}
async bookAppointment(appointment: Appointment): Promise<string> {
if (process.env.APP_ENV === "test") {
return "success"
}
return this.backend.bookAppointment(appointment);
}
async modifyAppointment(
id: string,
updatedInfo: Partial<Appointment>,
): Promise<Appointment> {
return this.backend.modifyAppointment(id, updatedInfo);
}
async findAppointmentByContactName(name: string): Promise<Appointment> {
return this.backend.findAppointmentByContactName(name);
}
async findAppointmentByTimestamp(
timestamp: string,
): Promise<Appointment | null> {
return this.backend.findAppointmentByTimestamp(timestamp);
}
async findAppointmentById(id: string): Promise<Appointment | null> {
return this.backend.findAppointmentById(id);
}
async createEventToSms(appointment: Appointment): Promise<string> {
return this.backend.createEventToSms(appointment);
}
}
export default CRMConnector;