Files
calendar/packages/app-store/salesforce/lib/routingFormBookingFormHandler.ts
T
Eunjae LeeGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
42a4a38939 refactor: rename eventType files to eventTypeRepository and eventTypeService (#22670)
- Rename packages/lib/server/repository/eventType.ts to eventTypeRepository.ts
- Rename packages/lib/server/service/eventType.ts to eventTypeService.ts
- Update all import statements across the codebase to use new filenames
- No functional changes, only file path updates

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2025-07-22 12:27:18 +00:00

45 lines
1.5 KiB
TypeScript

import { CredentialRepository } from "../../../lib/server/repository/credential";
import { EventTypeService } from "../../../lib/server/service/eventTypeService";
import type { AttributeRoutingConfig } from "../../routing-forms/types/types";
import SalesforceCRMService from "./CrmService";
import { SalesforceRecordEnum, RoutingReasons } from "./enums";
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;