* move SystemField to features * migrate workflow service * merge two tests for team repository * update imports and migrate team repository * migrate delegation credential repository * migrate credential repository * migrate entityPermissionUtils * migrate hashedLink service and repository * migrate membership service * update imports * remove file * migrate buildEventUrlFromBooking * migrate getAllUserBookings to features * update imports * update organizationMock * migrate slots * migrate date-ranges to schedules dir * migrate getAggregatedAvailability * fix * refactor * migrate useCreateEventType hook to features * migrate assignValueToUser * migrate validateUsername to auth features * migrate system field back to lib * migrate getLabelValueMapFromResponses back to lib * update imports * use relative path * fix type checks * fix * fix * fix tests * update gh codeowners * fix * fix
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { CredentialRepository } from "@calcom/features/credentials/repositories/CredentialRepository";
|
|
|
|
import type { AttributeRoutingConfig } from "../../routing-forms/types/types";
|
|
import SalesforceCRMService from "./CrmService";
|
|
import { SalesforceRecordEnum, RoutingReasons } from "./enums";
|
|
import { EventTypeService } from "./eventTypeService";
|
|
|
|
const routingFormBookingFormHandler = async (
|
|
attendeeEmail: string,
|
|
attributeRoutingConfig: AttributeRoutingConfig,
|
|
eventTypeId: number
|
|
) => {
|
|
const salesforceSettings = attributeRoutingConfig?.salesforce;
|
|
|
|
if (
|
|
!salesforceSettings ||
|
|
!salesforceSettings.rrSkipToAccountLookupField ||
|
|
!salesforceSettings.rrSKipToAccountLookupFieldName
|
|
)
|
|
return { email: null, recordType: null, recordId: null };
|
|
|
|
const appData = await EventTypeService.getEventTypeAppDataFromId(eventTypeId, "salesforce");
|
|
|
|
const credentialId = appData.credentialId;
|
|
|
|
const credential = await CredentialRepository.findFirstByIdWithKeyAndUser({ id: credentialId });
|
|
|
|
if (!credential) return { email: null, recordType: null, recordId: null };
|
|
|
|
const crm = new SalesforceCRMService(credential, {});
|
|
|
|
const userLookupEmail = await crm.findUserEmailFromLookupField(
|
|
attendeeEmail,
|
|
salesforceSettings.rrSKipToAccountLookupFieldName,
|
|
SalesforceRecordEnum.ACCOUNT
|
|
);
|
|
|
|
return {
|
|
email: userLookupEmail?.email ?? null,
|
|
recordType: RoutingReasons.ACCOUNT_LOOKUP_FIELD as string,
|
|
recordId: null,
|
|
};
|
|
};
|
|
|
|
export default routingFormBookingFormHandler;
|