* Revert "Revert "chore: rename DWD to DelegationCredential (#19703)" (#19734)"
This reverts commit 340b5ab061.
* chore: fix schema and types for now
* fix: domainWideDelegationCredentialId error type
56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { getFirstDelegationConferencingCredentialAppLocation } from "@calcom/lib/delegationCredential/server";
|
|
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,
|
|
});
|
|
|
|
firstDynamicGroupMemberDefaultLocationUrl =
|
|
firstDynamicGroupMemberMetadata?.defaultConferencingApp?.appLink ||
|
|
firstDynamicGroupMemberDelegationCredentialConferencingAppLocation;
|
|
|
|
locationBodyString = firstDynamicGroupMemberDefaultLocationUrl || locationBodyString;
|
|
}
|
|
|
|
return {
|
|
locationBodyString,
|
|
organizerOrFirstDynamicGroupMemberDefaultLocationUrl: firstDynamicGroupMemberDefaultLocationUrl,
|
|
};
|
|
};
|