feat: update event types for default availability change (#13964)
* feat: update event types for default availability change * chore: add toast --------- Co-authored-by: sean-brydon <[email protected]> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
6 files changed
+111
-13
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import authedProcedure from "../../../../procedures/authedProcedure";
|
||||
import { router } from "../../../../trpc";
|
||||
import { ZBulkUpdateToDefaultAvailabilityInputSchema } from "./bulkUpdateDefaultAvailability.schema";
|
||||
import { ZCreateInputSchema } from "./create.schema";
|
||||
import { ZDeleteInputSchema } from "./delete.schema";
|
||||
import { ZScheduleDuplicateSchema } from "./duplicate.schema";
|
||||
@@ -16,6 +17,7 @@ type ScheduleRouterHandlerCache = {
|
||||
duplicate?: typeof import("./duplicate.handler").duplicateHandler;
|
||||
getScheduleByUserId?: typeof import("./getScheduleByUserId.handler").getScheduleByUserIdHandler;
|
||||
getScheduleByEventSlug?: typeof import("./getScheduleByEventTypeSlug.handler").getScheduleByEventSlugHandler;
|
||||
bulkUpdateToDefaultAvailability?: typeof import("./bulkUpdateDefaultAvailability.handler").bulkUpdateToDefaultAvailabilityHandler;
|
||||
};
|
||||
|
||||
const UNSTABLE_HANDLER_CACHE: ScheduleRouterHandlerCache = {};
|
||||
@@ -137,4 +139,22 @@ export const scheduleRouter = router({
|
||||
input,
|
||||
});
|
||||
}),
|
||||
bulkUpdateToDefaultAvailability: authedProcedure
|
||||
.input(ZBulkUpdateToDefaultAvailabilityInputSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
if (!UNSTABLE_HANDLER_CACHE.bulkUpdateToDefaultAvailability) {
|
||||
UNSTABLE_HANDLER_CACHE.bulkUpdateToDefaultAvailability = await import(
|
||||
"./bulkUpdateDefaultAvailability.handler"
|
||||
).then((mod) => mod.bulkUpdateToDefaultAvailabilityHandler);
|
||||
}
|
||||
|
||||
if (!UNSTABLE_HANDLER_CACHE.bulkUpdateToDefaultAvailability) {
|
||||
throw new Error("Failed to load handler");
|
||||
}
|
||||
|
||||
return UNSTABLE_HANDLER_CACHE.bulkUpdateToDefaultAvailability({
|
||||
ctx,
|
||||
input,
|
||||
});
|
||||
}),
|
||||
});
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
import { prisma } from "@calcom/prisma";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../../trpc";
|
||||
import type { TBulkUpdateToDefaultAvailabilityInputSchema } from "./bulkUpdateDefaultAvailability.schema";
|
||||
|
||||
type BulkUpdateToDefaultAvailabilityOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
};
|
||||
input: TBulkUpdateToDefaultAvailabilityInputSchema;
|
||||
};
|
||||
|
||||
export const bulkUpdateToDefaultAvailabilityHandler = async ({
|
||||
ctx,
|
||||
input,
|
||||
}: BulkUpdateToDefaultAvailabilityOptions) => {
|
||||
const { eventTypeIds } = input;
|
||||
const defaultScheduleId = ctx.user.defaultScheduleId;
|
||||
|
||||
if (!defaultScheduleId) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Default schedule not set",
|
||||
});
|
||||
}
|
||||
|
||||
return await prisma.eventType.updateMany({
|
||||
where: {
|
||||
id: {
|
||||
in: eventTypeIds,
|
||||
},
|
||||
userId: ctx.user.id,
|
||||
},
|
||||
data: {
|
||||
scheduleId: defaultScheduleId,
|
||||
},
|
||||
});
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ZBulkUpdateToDefaultAvailabilityInputSchema = z.object({
|
||||
eventTypeIds: z.array(z.number()),
|
||||
});
|
||||
|
||||
export type TBulkUpdateToDefaultAvailabilityInputSchema = z.infer<
|
||||
typeof ZBulkUpdateToDefaultAvailabilityInputSchema
|
||||
>;
|
||||
Reference in new issue
Block a user