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:
parent
1d882e6b3b
commit
79b60adf9b
|
@ -19,6 +19,7 @@ import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||||
|
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
|
|
||||||
|
import { getDefaultScheduleId } from "../viewer/availability/util";
|
||||||
import { updateUserMetadataAllowedKeys, type TUpdateProfileInputSchema } from "./updateProfile.schema";
|
import { updateUserMetadataAllowedKeys, type TUpdateProfileInputSchema } from "./updateProfile.schema";
|
||||||
|
|
||||||
type UpdateProfileOptions = {
|
type UpdateProfileOptions = {
|
||||||
|
@ -130,9 +131,40 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions)
|
||||||
name: true,
|
name: true,
|
||||||
createdDate: true,
|
createdDate: true,
|
||||||
locale: 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) {
|
if (hasEmailChangedOnNonCalProvider) {
|
||||||
// Because the email has changed, we are now attempting to use the CAL provider-
|
// 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.
|
// which has no password yet. We have to send the reset password email.
|
||||||
|
|
|
@ -54,6 +54,8 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
data.timeZone = user.timeZone;
|
||||||
|
|
||||||
const schedule = await prisma.schedule.create({
|
const schedule = await prisma.schedule.create({
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user