fix: timezone of default schedule should change if profile timezone is updated (#11533)

* change tz of default schedule

* make sure user has at least one schedule

---------

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
This commit is contained in:
Carina Wollendorfer 2023-09-26 21:41:16 +02:00 committed by GitHub
parent 1d882e6b3b
commit 79b60adf9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import { TRPCError } from "@trpc/server";
import { getDefaultScheduleId } from "../viewer/availability/util";
import { updateUserMetadataAllowedKeys, type TUpdateProfileInputSchema } from "./updateProfile.schema";
type UpdateProfileOptions = {
@ -130,9 +131,40 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions)
name: true,
createdDate: true,
locale: true,
schedules: {
select: {
id: true,
},
},
},
});
if (user.timeZone !== data.timeZone && updatedUser.schedules.length > 0) {
// on timezone change update timezone of default schedule
const defaultScheduleId = await getDefaultScheduleId(user.id, prisma);
if (!user.defaultScheduleId) {
// set default schedule if not already set
await prisma.user.update({
where: {
id: user.id,
},
data: {
defaultScheduleId,
},
});
}
await prisma.schedule.updateMany({
where: {
id: defaultScheduleId,
},
data: {
timeZone: data.timeZone,
},
});
}
if (hasEmailChangedOnNonCalProvider) {
// Because the email has changed, we are now attempting to use the CAL provider-
// which has no password yet. We have to send the reset password email.

View File

@ -54,6 +54,8 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
},
};
data.timeZone = user.timeZone;
const schedule = await prisma.schedule.create({
data,
});