Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
fix: timezone of default schedule should change if profile timezone i…
Browse files Browse the repository at this point in the history
…s updated (calcom#11533)

* change tz of default schedule

* make sure user has at least one schedule

---------

Co-authored-by: CarinaWolli <[email protected]>
  • Loading branch information
CarinaWolli and CarinaWolli authored Sep 26, 2023
1 parent 1d882e6 commit 79b60ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
},
};

data.timeZone = user.timeZone;

const schedule = await prisma.schedule.create({
data,
});
Expand Down

0 comments on commit 79b60ad

Please sign in to comment.