Files
calendar/packages/features/bookings/lib/handleNewBooking/getLocationValuesForDb.ts
T
98b6d63164 refactor: apply biome formatting to packages/features (#27844)
* refactor: apply biome formatting to packages/features (batch 1 - small subdirs)

Format small subdirectories in packages/features: di, flags, holidays, oauth,
settings, users, assignment-reason, selectedCalendar, hashedLink, host, form,
form-builder, availability, data-table, pbac, schedules, troubleshooter,
eventtypes, calendar-subscription, and root-level files.

Also includes straggler apps/web BookEventForm.tsx.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 2 - medium subdirs)

Format medium subdirectories in packages/features: auth, credentials,
calendars, routing-forms, routing-trace, attributes, watchlist, calAIPhone,
tasker, and webhooks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 3 - bookings + insights)

Format bookings and insights subdirectories in packages/features.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 4 - ee)

Format packages/features/ee subdirectory covering billing, workflows,
organizations, teams, managed-event-types, round-robin, dsync,
integration-attribute-sync, and payments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 5 - booking-audit part 1)

Format booking-audit di, actions, common, dto, repository, and types
subdirectories in packages/features/booking-audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 6 - booking-audit part 2)

Format booking-audit service subdirectory in packages/features/booking-audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 15:47:14 +01:00

65 lines
2.4 KiB
TypeScript

import { getFirstDelegationConferencingCredentialAppLocation } from "@calcom/app-store/delegationCredential";
import { withReporting } from "@calcom/lib/sentryWrapper";
import type { Prisma } from "@calcom/prisma/client";
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
import type { CredentialForCalendarService } from "@calcom/types/Credential";
const sortUsersByDynamicList = <TUser extends { username: string | null }>(
users: TUser[],
dynamicUserList: string[]
) => {
return users.sort((a, b) => {
const aIndex = (a.username && dynamicUserList.indexOf(a.username)) || 0;
const bIndex = (b.username && dynamicUserList.indexOf(b.username)) || 0;
return aIndex - bIndex;
});
};
export const _getLocationValuesForDb = <
TUser extends {
username: string | null;
metadata: Prisma.JsonValue;
credentials: CredentialForCalendarService[];
},
>({
dynamicUserList,
users,
location: locationBodyString,
}: {
dynamicUserList: string[];
users: TUser[];
location: string;
}) => {
const isDynamicGroupBookingCase = dynamicUserList.length > 1;
let firstDynamicGroupMemberDefaultLocationUrl;
// TODO: It's definition should be moved to getLocationValueForDb
if (isDynamicGroupBookingCase) {
users = sortUsersByDynamicList(users, dynamicUserList);
const firstDynamicGroupMember = users[0];
const firstDynamicGroupMemberMetadata = userMetadataSchema.parse(firstDynamicGroupMember.metadata);
const firstDynamicGroupMemberDelegationCredentialConferencingAppLocation =
getFirstDelegationConferencingCredentialAppLocation({
credentials: firstDynamicGroupMember.credentials,
});
const defaultConferencingApp = firstDynamicGroupMemberMetadata?.defaultConferencingApp;
const hasMemberSetConferencingPreference =
!!defaultConferencingApp?.appSlug || !!defaultConferencingApp?.appLink;
firstDynamicGroupMemberDefaultLocationUrl =
(hasMemberSetConferencingPreference
? defaultConferencingApp?.appLink
: firstDynamicGroupMemberDelegationCredentialConferencingAppLocation) ?? null;
locationBodyString = firstDynamicGroupMemberDefaultLocationUrl || locationBodyString;
}
return {
locationBodyString,
organizerOrFirstDynamicGroupMemberDefaultLocationUrl: firstDynamicGroupMemberDefaultLocationUrl,
};
};
export const getLocationValuesForDb = withReporting(_getLocationValuesForDb, "getLocationValuesForDb");