feat: round robin handover to specific host (#17215)
* frontend dialog * handler + fe calling handler * reafctors + start work on fix hosts tests * restore rr * update tests + fixing types * use a getRRHostsToReasign handler + error handle + i18n * typefixes * assert type * fix: adds missing translation * Update roundRobinManualReassignment.ts * Update roundRobinManualReassignment.ts * Update apps/web/components/dialog/ReassignDialog.tsx Co-authored-by: Carina Wollendorfer <[email protected]> * Update roundRobinManualReassignment.ts --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: zomars <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]>
This commit is contained in:
13 files changed
+1104
-79
No files matched your search
@@ -23,6 +23,8 @@ import { ZPublishInputSchema } from "./publish.schema";
|
||||
import { ZRemoveHostsFromEventTypes } from "./removeHostsFromEventTypes.schema";
|
||||
import { ZRemoveMemberInputSchema } from "./removeMember.schema";
|
||||
import { ZResendInvitationInputSchema } from "./resendInvitation.schema";
|
||||
import { ZGetRoundRobinHostsToReassignInputSchema } from "./roundRobin/getRoundRobinHostsToReasign.schema";
|
||||
import { ZRoundRobinManualReassignInputSchema } from "./roundRobin/roundRobinManualReassign.schema";
|
||||
import { ZRoundRobinReassignInputSchema } from "./roundRobin/roundRobinReassign.schema";
|
||||
import { ZSetInviteExpirationInputSchema } from "./setInviteExpiration.schema";
|
||||
import { ZUpdateInputSchema } from "./update.schema";
|
||||
@@ -181,6 +183,24 @@ export const viewerTeamsRouter = router({
|
||||
);
|
||||
return handler(opts);
|
||||
}),
|
||||
roundRobinManualReassign: authedProcedure
|
||||
.input(ZRoundRobinManualReassignInputSchema)
|
||||
.mutation(async (opts) => {
|
||||
const handler = await importHandler(
|
||||
namespaced("roundRobinManualReassign"),
|
||||
() => import("./roundRobin/roundRobinManualReassign.handler")
|
||||
);
|
||||
return handler(opts);
|
||||
}),
|
||||
getRoundRobinHostsToReassign: authedProcedure
|
||||
.input(ZGetRoundRobinHostsToReassignInputSchema)
|
||||
.query(async (opts) => {
|
||||
const handler = await importHandler(
|
||||
namespaced("getRoundRobinHostsToReassign"),
|
||||
() => import("./roundRobin/getRoundRobinHostsToReasign.handler")
|
||||
);
|
||||
return handler(opts);
|
||||
}),
|
||||
checkIfMembershipExists: authedProcedure
|
||||
.input(ZCheckIfMembershipExistsInputSchema)
|
||||
.mutation(async (opts) => {
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import type { TGetRoundRobinHostsToReassignInputSchema } from "./getRoundRobinHostsToReasign.schema";
|
||||
|
||||
type GetRoundRobinHostsToReassignOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
prisma: PrismaClient;
|
||||
};
|
||||
input: TGetRoundRobinHostsToReassignInputSchema;
|
||||
};
|
||||
|
||||
export const getRoundRobinHostsToReassign = async ({ ctx, input }: GetRoundRobinHostsToReassignOptions) => {
|
||||
const { prisma } = ctx;
|
||||
const { isOrgAdmin } = ctx.user.organization;
|
||||
const hasPermsToView = !ctx.user.organization.isPrivate || isOrgAdmin;
|
||||
|
||||
if (!hasPermsToView) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const booking = await prisma.booking.findUniqueOrThrow({
|
||||
where: { id: input.bookingId },
|
||||
select: {
|
||||
eventType: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!booking?.eventType) {
|
||||
throw new Error("Booking not found");
|
||||
}
|
||||
|
||||
// If input.exclude is "fixedHosts", exclude fixed hosts from the list
|
||||
const excludeFixedHosts = input.exclude === "fixedHosts";
|
||||
|
||||
const eventTypeHosts = await prisma.host.findMany({
|
||||
where: {
|
||||
eventTypeId: booking.eventType.id,
|
||||
isFixed: excludeFixedHosts ? false : undefined,
|
||||
},
|
||||
select: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const hosts = eventTypeHosts.map((host) => host.user);
|
||||
|
||||
return hosts;
|
||||
};
|
||||
|
||||
export default getRoundRobinHostsToReassign;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ZGetRoundRobinHostsToReassignInputSchema = z.object({
|
||||
bookingId: z.number(),
|
||||
exclude: z.enum(["fixedHosts"]).optional(),
|
||||
});
|
||||
|
||||
export type TGetRoundRobinHostsToReassignInputSchema = z.infer<
|
||||
typeof ZGetRoundRobinHostsToReassignInputSchema
|
||||
>;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import { roundRobinManualReassignment } from "@calcom/features/ee/round-robin/roundRobinManualReassignment";
|
||||
import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TRoundRobinManualReassignInputSchema } from "./roundRobinManualReassign.schema";
|
||||
|
||||
type RoundRobinManualReassignOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
};
|
||||
input: TRoundRobinManualReassignInputSchema;
|
||||
};
|
||||
|
||||
export const roundRobinManualReassignHandler = async ({ ctx, input }: RoundRobinManualReassignOptions) => {
|
||||
const { bookingId, teamMemberId } = input;
|
||||
|
||||
// Check if user has access to change booking
|
||||
const isAllowed = await BookingRepository.doesUserIdHaveAccessToBooking({ userId: ctx.user.id, bookingId });
|
||||
|
||||
if (!isAllowed) {
|
||||
throw new TRPCError({ code: "FORBIDDEN", message: "You do not have permission" });
|
||||
}
|
||||
|
||||
await roundRobinManualReassignment({ bookingId, newUserId: teamMemberId, orgId: ctx.user.organizationId });
|
||||
|
||||
return { success: true };
|
||||
};
|
||||
|
||||
export default roundRobinManualReassignHandler;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ZRoundRobinManualReassignInputSchema = z.object({
|
||||
bookingId: z.number(),
|
||||
teamMemberId: z.number(),
|
||||
});
|
||||
|
||||
export type TRoundRobinManualReassignInputSchema = z.infer<typeof ZRoundRobinManualReassignInputSchema>;
|
||||
Reference in new issue
Block a user