Files
calendar/packages/trpc/server/routers/viewer/availability/schedule/_router.tsx
T
a48d190af3 feat: #15416 Expand round robin availability beyond default schedule (#15618)
* add feature to change host schedule

* update for type-check:ci

* Update SingleForm.tsx for linterr

* update as per design review

* update for rerendering

* migration files

* On Delete set null for schedule

if schedule is deleted, no need to delete the host

* updated schema

* added testcases

* checking permissions before

* updated for comments

* update for initial value

* updated and cleanup

* set initial value

* update after merge

* updated nit style

* update for console warning and added comments

* nit/chore

* chore

* update for typechecks

* update for scheduleId param after merge

* update after merge or new changes in metadata.config

* update after weights functionality

* updated description text and column name as per review suggestion

* resolved merge conflicts

* fix typecheck due to changes in getScheduleSchema

* update after merge having refactor

* update refactored EventTypeWebWrapper after merge

* updated props

* updated trpc err code and added log

* update due to refactor in EventAvailabilityTab

* perf: Optimise TS type + select only the data that's needed for a specific function

---------

Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com>
Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
2024-10-15 17:36:00 +01:00

182 lines
6.4 KiB
TypeScript

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";
import { ZGetInputSchema } from "./get.schema";
import { ZGetAllByUserIdInputSchema } from "./getAllSchedulesByUserId.schema";
import { ZGetByEventSlugInputSchema } from "./getScheduleByEventTypeSlug.schema";
import { ZGetByUserIdInputSchema } from "./getScheduleByUserId.schema";
import { ZUpdateInputSchema } from "./update.schema";
type ScheduleRouterHandlerCache = {
get?: typeof import("./get.handler").getHandler;
create?: typeof import("./create.handler").createHandler;
delete?: typeof import("./delete.handler").deleteHandler;
update?: typeof import("./update.handler").updateHandler;
duplicate?: typeof import("./duplicate.handler").duplicateHandler;
getScheduleByUserId?: typeof import("./getScheduleByUserId.handler").getScheduleByUserIdHandler;
getAllSchedulesByUserId?: typeof import("./getAllSchedulesByUserId.handler").getAllSchedulesByUserIdHandler;
getScheduleByEventSlug?: typeof import("./getScheduleByEventTypeSlug.handler").getScheduleByEventSlugHandler;
bulkUpdateToDefaultAvailability?: typeof import("./bulkUpdateDefaultAvailability.handler").bulkUpdateToDefaultAvailabilityHandler;
};
const UNSTABLE_HANDLER_CACHE: ScheduleRouterHandlerCache = {};
export const scheduleRouter = router({
get: authedProcedure.input(ZGetInputSchema).query(async ({ input, ctx }) => {
if (!UNSTABLE_HANDLER_CACHE.get) {
UNSTABLE_HANDLER_CACHE.get = await import("./get.handler").then((mod) => mod.getHandler);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.get) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.get({
ctx,
input,
});
}),
create: authedProcedure.input(ZCreateInputSchema).mutation(async ({ input, ctx }) => {
if (!UNSTABLE_HANDLER_CACHE.create) {
UNSTABLE_HANDLER_CACHE.create = await import("./create.handler").then((mod) => mod.createHandler);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.create) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.create({
ctx,
input,
});
}),
delete: authedProcedure.input(ZDeleteInputSchema).mutation(async ({ input, ctx }) => {
if (!UNSTABLE_HANDLER_CACHE.delete) {
UNSTABLE_HANDLER_CACHE.delete = await import("./delete.handler").then((mod) => mod.deleteHandler);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.delete) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.delete({
ctx,
input,
});
}),
update: authedProcedure.input(ZUpdateInputSchema).mutation(async ({ input, ctx }) => {
if (!UNSTABLE_HANDLER_CACHE.update) {
UNSTABLE_HANDLER_CACHE.update = await import("./update.handler").then((mod) => mod.updateHandler);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.update) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.update({
ctx,
input,
});
}),
duplicate: authedProcedure.input(ZScheduleDuplicateSchema).mutation(async ({ input, ctx }) => {
if (!UNSTABLE_HANDLER_CACHE.duplicate) {
UNSTABLE_HANDLER_CACHE.duplicate = await import("./duplicate.handler").then(
(mod) => mod.duplicateHandler
);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.duplicate) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.duplicate({
ctx,
input,
});
}),
getScheduleByUserId: authedProcedure.input(ZGetByUserIdInputSchema).query(async ({ input, ctx }) => {
if (!UNSTABLE_HANDLER_CACHE.getScheduleByUserId) {
UNSTABLE_HANDLER_CACHE.getScheduleByUserId = await import("./getScheduleByUserId.handler").then(
(mod) => mod.getScheduleByUserIdHandler
);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.getScheduleByUserId) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.getScheduleByUserId({
ctx,
input,
});
}),
getAllSchedulesByUserId: authedProcedure.input(ZGetAllByUserIdInputSchema).query(async ({ input, ctx }) => {
if (!UNSTABLE_HANDLER_CACHE.getAllSchedulesByUserId) {
UNSTABLE_HANDLER_CACHE.getAllSchedulesByUserId = await import("./getAllSchedulesByUserId.handler").then(
(mod) => mod.getAllSchedulesByUserIdHandler
);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.getAllSchedulesByUserId) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.getAllSchedulesByUserId({
ctx,
input,
});
}),
getScheduleByEventSlug: authedProcedure.input(ZGetByEventSlugInputSchema).query(async ({ input, ctx }) => {
if (!UNSTABLE_HANDLER_CACHE.getScheduleByEventSlug) {
UNSTABLE_HANDLER_CACHE.getScheduleByEventSlug = await import(
"./getScheduleByEventTypeSlug.handler"
).then((mod) => mod.getScheduleByEventSlugHandler);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.getScheduleByEventSlug) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.getScheduleByEventSlug({
ctx,
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,
});
}),
});