* fix: bulk-update-in-scheduleId-in-detailed-view * minor-change --------- Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
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, selectedDefaultScheduleId } = input;
|
|
const defaultScheduleId = ctx.user.defaultScheduleId;
|
|
|
|
if (!selectedDefaultScheduleId && !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: selectedDefaultScheduleId || defaultScheduleId,
|
|
},
|
|
});
|
|
};
|