* refactor: move repositories from lib to features domain folders - Move HolidayRepository to features/holidays/repositories - Move PrismaTrackingRepository to features/bookings/repositories - Move PrismaBookingPaymentRepository to features/bookings/repositories - Move PrismaRoutingFormResponseRepository to features/routing-forms/repositories - Move PrismaAssignmentReasonRepository to features/assignment-reason/repositories - Move VerificationTokenRepository to features/auth/repositories - Move WorkspacePlatformRepository to features/workspace-platform/repositories - Move DTO files to their respective feature domains - Merge lib DestinationCalendarRepository into features version - Merge lib SelectedCalendarRepository into features version - Update all import paths across the codebase This follows the vertical slice architecture pattern by organizing repositories by domain rather than by technical layer. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: update VerificationTokenService import path to new location Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: update test file imports to use new repository locations Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * mv * fix structure * fix * refactor: merge unit tests for SelectedCalendarRepository into single file Co-Authored-By: benny@cal.com <sldisek783@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import type { z } from "zod";
|
|
|
|
import { DelegationCredentialRepository } from "@calcom/features/delegation-credentials/repositories/DelegationCredentialRepository";
|
|
import { WorkspacePlatformRepository } from "@calcom/features/workspace-platform/repositories/WorkspacePlatformRepository";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { DelegationCredentialUpdateSchema } from "./schema";
|
|
import {
|
|
ensureDelegationCredentialNotAlreadyConfigured,
|
|
ensureNoServiceAccountKey,
|
|
handleDelegationCredentialError,
|
|
} from "./utils";
|
|
|
|
export default async function handler({
|
|
input,
|
|
ctx,
|
|
}: {
|
|
input: z.infer<typeof DelegationCredentialUpdateSchema>;
|
|
ctx: { user: { id: number; organizationId: number | null } };
|
|
}) {
|
|
const { id, workspacePlatformSlug, domain } = input;
|
|
const { user } = ctx;
|
|
const { organizationId } = user;
|
|
|
|
if (!organizationId) {
|
|
throw new TRPCError({
|
|
code: "UNAUTHORIZED",
|
|
message: "You must be part of an organization to update a delegation credential",
|
|
});
|
|
}
|
|
|
|
await ensureDelegationCredentialNotAlreadyConfigured({
|
|
domain,
|
|
currentOrganizationId: organizationId,
|
|
delegationCredentialBeingUpdatedId: id,
|
|
});
|
|
|
|
try {
|
|
const workspacePlatform = await WorkspacePlatformRepository.findBySlugIncludeSensitiveServiceAccountKey({
|
|
slug: workspacePlatformSlug,
|
|
});
|
|
|
|
if (!workspacePlatform) {
|
|
throw new TRPCError({
|
|
code: "NOT_FOUND",
|
|
message: `Workspace platform ${workspacePlatformSlug} not found`,
|
|
});
|
|
}
|
|
|
|
const updatedDelegation = await DelegationCredentialRepository.updateById({
|
|
id,
|
|
data: {
|
|
workspacePlatformId: workspacePlatform.id,
|
|
domain,
|
|
organizationId,
|
|
},
|
|
});
|
|
|
|
return ensureNoServiceAccountKey(updatedDelegation);
|
|
} catch (error) {
|
|
handleDelegationCredentialError(error);
|
|
}
|
|
}
|