* move delegation credential repository to features * mv credential repository to features * update imports * mv * fix * fix * fix * fix * fix * update imports * update imports * update eslint rule * fix * fix * mv getConnectedDestinationCalendars * fix import errors * mv getCalendarsEvents * remove getUsersCredentials * wip * revert eslint rule change for now * fix type checks * fix * format * cleanup * fix * fix * fix * fix * fix tests * migrate getUserAvailability * migrate * fix tests * fix type checks * fix * fix * migrate crmManager * update imports * migrate raqbUtils to appstore * migrate getLuckyUser to features * migrate findTeamMembersMatchingAttributeLogic to appstore * update imports * fix * fix * fix test * fix unit tests * fix * fix * add eslint config
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import async from "async";
|
|
|
|
import { isDelegationCredential } from "@calcom/lib/delegationCredential";
|
|
import { buildAllCredentials } from "@calcom/app-store/delegationCredential";
|
|
import { withReporting } from "@calcom/lib/sentryWrapper";
|
|
import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
|
|
|
import { refreshCredential } from "./refreshCredential";
|
|
|
|
/**
|
|
* Refreshes the given set of credentials.
|
|
*
|
|
* @param credentials
|
|
*/
|
|
// Define the function with underscore prefix
|
|
const _refreshCredentials = async (
|
|
credentials: Array<CredentialForCalendarService>
|
|
): Promise<Array<CredentialForCalendarService>> => {
|
|
const nonDelegationCredentials = credentials.filter(
|
|
(cred) => !isDelegationCredential({ credentialId: cred.id })
|
|
);
|
|
const delegationCredentials = credentials.filter((cred) =>
|
|
isDelegationCredential({ credentialId: cred.id })
|
|
);
|
|
const refreshedDbCredentials = await async.mapLimit(nonDelegationCredentials, 5, refreshCredential);
|
|
return buildAllCredentials({ delegationCredentials, existingCredentials: refreshedDbCredentials });
|
|
};
|
|
|
|
export const refreshCredentials = withReporting(_refreshCredentials, "refreshCredentials");
|