* move types to types file * Create salesforce routing form components * Save salesforce data to routing form * Fixes * Add event type service * Change commenting * Pass data from routing form to CRM * Init Salesforce routing form booking form handler * Salesforce find user associated with lookup field * Add looking up the contact owner * If salesforce is disabled then don't change the Salesforce option * Small refactor * Refactor getting event type app metadata * Refactor eventType service * Type fix * Clean up * Add translations Co-authored-by: Alex van Andel <emrysal@users.noreply.github.com> --------- Co-authored-by: Alex van Andel <emrysal@users.noreply.github.com>
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { CredentialRepository } from "../../../lib/server/repository/credential";
|
|
import { EventTypeService } from "../../../lib/server/service/eventType";
|
|
import type { AttributeRoutingConfig } from "../../routing-forms/types/types";
|
|
import SalesforceCRMService from "./CrmService";
|
|
import { SalesforceRecordEnum } from "./enums";
|
|
|
|
const routingFormBookingFormHandler = async (
|
|
attendeeEmail: string,
|
|
attributeRoutingConfig: AttributeRoutingConfig,
|
|
eventTypeId: number
|
|
) => {
|
|
const salesforceSettings = attributeRoutingConfig?.salesforce;
|
|
|
|
if (
|
|
!salesforceSettings ||
|
|
!salesforceSettings.rrSkipToAccountLookupField ||
|
|
!salesforceSettings.rrSKipToAccountLookupFieldName
|
|
)
|
|
return { email: null };
|
|
|
|
const appData = await EventTypeService.getEventTypeAppDataFromId(eventTypeId, "salesforce");
|
|
|
|
const credentialId = appData.credentialId;
|
|
|
|
const credential = await CredentialRepository.findFirstByIdWithKeyAndUser({ id: credentialId });
|
|
|
|
if (!credential) return { email: null };
|
|
|
|
const crm = new SalesforceCRMService(credential, {});
|
|
|
|
const userLookupEmail = await crm.findUserEmailFromLookupField(
|
|
attendeeEmail,
|
|
salesforceSettings.rrSKipToAccountLookupFieldName,
|
|
SalesforceRecordEnum.ACCOUNT
|
|
);
|
|
|
|
return { email: userLookupEmail ?? null };
|
|
};
|
|
|
|
export default routingFormBookingFormHandler;
|