* Add booking incomplete actions table * Add incomplete booking page tab * Add `getincompleteBookingSettings` trpc endpoints * Add incomplete booking page * Abstract enabled apps array * Handle no enabled credentials and no actions * Add enabled field to incomplete booking action db record * Add new write record entries * UI add separation between switch and inputs * Fix typo * clean up * Add saveIncompleteBookingSettings endpoint * Save incomplete booking settings * Fix language around when to write to field * Add `credentialId` to action record * Choose which credential to assign to action * Save credential to action * Revert "Save credential to action" This reverts commit ba6a1c808baed54f6d3d4c6155cf192c813d0696. * Revert "Choose which credential to assign to action" This reverts commit 968f6e5295d098c64abe95268afd1fa139a175ba. * Revert "Add `credentialId` to action record" This reverts commit 579f9ff4167b65aa987659e4e8f8c26f9e773317. * Add credentialId to action record - rewrite migration file * Revert "Add credentialId to action record - rewrite migration file" This reverts commit 2843a92c61820e7f7a1614a557d3f7ea96342107. * Revert "Add booking incomplete actions table" This reverts commit 7ec75bef4a0f0a9d07be0142da64c49d739439ea. * Revert "Add enabled field to incomplete booking action db record" This reverts commit d279a1da05819eafa8fc5d664e3be733e0687e8d. * Write migration in single commit * Rename table * Rename table - remove underscores * Remove credential relationship * Type fix - changing table name * Fix table name * Change writeToRecordObject to object * Salesforce add incomplete booking, write to record * Add incomplete booking actions to `triggerFormSubmittedNoEventWebhooks` * Remove console.log * Type fixes * Type fixes * Iterate if incompleteBookingActions * Choose which credential to assign to action * Save credential to action * Fix getServerSideProp changes * Type fix * Type fix * Type fix * Type fix --------- Co-authored-by: Alex van Andel <me@alexvanandel.com>
97 lines
2.3 KiB
TypeScript
97 lines
2.3 KiB
TypeScript
import type { PrismaClient } from "@calcom/prisma";
|
|
import { TRPCError } from "@calcom/trpc/server";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import { enabledIncompleteBookingApps } from "../lib/enabledIncompleteBookingApps";
|
|
import type { TGetIncompleteBookingSettingsInputSchema } from "./getIncompleteBookingSettings.schema";
|
|
|
|
interface GetIncompleteBookingSettingsOptions {
|
|
ctx: {
|
|
prisma: PrismaClient;
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TGetIncompleteBookingSettingsInputSchema;
|
|
}
|
|
|
|
const getInCompleteBookingSettingsHandler = async (options: GetIncompleteBookingSettingsOptions) => {
|
|
const {
|
|
ctx: { prisma },
|
|
input,
|
|
} = options;
|
|
|
|
const [incompleteBookingActions, form] = await Promise.all([
|
|
prisma.app_RoutingForms_IncompleteBookingActions.findMany({
|
|
where: {
|
|
formId: input.formId,
|
|
},
|
|
}),
|
|
prisma.app_RoutingForms_Form.findFirst({
|
|
where: {
|
|
id: input.formId,
|
|
},
|
|
select: {
|
|
userId: true,
|
|
teamId: true,
|
|
},
|
|
}),
|
|
]);
|
|
|
|
if (!form) {
|
|
throw new TRPCError({
|
|
code: "NOT_FOUND",
|
|
message: "Form not found",
|
|
});
|
|
}
|
|
|
|
const teamId = form?.teamId;
|
|
const userId = form.userId;
|
|
|
|
if (teamId) {
|
|
// Need to get the credentials for the team and org
|
|
const orgQuery = await prisma.team.findFirst({
|
|
where: {
|
|
id: teamId,
|
|
},
|
|
select: {
|
|
parentId: true,
|
|
},
|
|
});
|
|
|
|
const credentials = await prisma.credential.findMany({
|
|
where: {
|
|
appId: {
|
|
in: enabledIncompleteBookingApps,
|
|
},
|
|
teamId: {
|
|
in: [teamId, ...(orgQuery?.parentId ? [orgQuery.parentId] : [])],
|
|
},
|
|
},
|
|
include: {
|
|
team: {
|
|
select: {
|
|
name: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return { incompleteBookingActions, credentials };
|
|
}
|
|
|
|
if (userId) {
|
|
// Assume that a user will have one credential per app
|
|
const credential = await prisma.credential.findFirst({
|
|
where: {
|
|
appId: {
|
|
in: enabledIncompleteBookingApps,
|
|
},
|
|
userId,
|
|
},
|
|
});
|
|
|
|
return { incompleteBookingActions, credentials: credential ? [{ ...credential, team: null }] : [] };
|
|
}
|
|
};
|
|
|
|
export default getInCompleteBookingSettingsHandler;
|