fix: PATCH /me formatted timezone incorrectly (#15830)
This commit is contained in:
@@ -103,6 +103,21 @@ describe("Me Endpoints", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should update user associated with access token given badly formatted timezone", async () => {
|
||||
const bodyWithBadlyFormattedTimeZone: UpdateManagedUserInput = { timeZone: "America/New_york" };
|
||||
|
||||
return request(app.getHttpServer())
|
||||
.patch("/v2/me")
|
||||
.send(bodyWithBadlyFormattedTimeZone)
|
||||
.expect(200)
|
||||
.then(async (response) => {
|
||||
const responseBody: ApiSuccessResponse<UserResponse> = response.body;
|
||||
expect(responseBody.status).toEqual(SUCCESS_STATUS);
|
||||
|
||||
expect(responseBody.data.timeZone).toEqual("America/New_York");
|
||||
});
|
||||
});
|
||||
|
||||
it("should not update user associated with access token given invalid timezone", async () => {
|
||||
const bodyWithIncorrectTimeZone: UpdateManagedUserInput = { timeZone: "Narnia/Woods" };
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import { userSchemaResponse } from "@calcom/platform-types";
|
||||
export class MeController {
|
||||
constructor(
|
||||
private readonly usersRepository: UsersRepository,
|
||||
private readonly schedulesRepository: SchedulesService_2024_04_15
|
||||
private readonly schedulesService: SchedulesService_2024_04_15
|
||||
) {}
|
||||
|
||||
@Get("/")
|
||||
@@ -45,7 +45,7 @@ export class MeController {
|
||||
): Promise<UpdateMeOutput> {
|
||||
const updatedUser = await this.usersRepository.update(user.id, bodySchedule);
|
||||
if (bodySchedule.timeZone && user.defaultScheduleId) {
|
||||
await this.schedulesRepository.updateUserSchedule(user, user.defaultScheduleId, {
|
||||
await this.schedulesService.updateUserSchedule(user, user.defaultScheduleId, {
|
||||
timeZone: bodySchedule.timeZone,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -159,10 +159,6 @@ export class UsersRepository {
|
||||
if (userInput.weekStart) {
|
||||
userInput.weekStart = userInput.weekStart;
|
||||
}
|
||||
|
||||
if (userInput.timeZone) {
|
||||
userInput.timeZone = capitalizeTimezone(userInput.timeZone);
|
||||
}
|
||||
}
|
||||
|
||||
setDefaultSchedule(userId: number, scheduleId: number) {
|
||||
@@ -194,17 +190,3 @@ export class UsersRepository {
|
||||
return profiles.map((profile) => profile.user);
|
||||
}
|
||||
}
|
||||
|
||||
function capitalizeTimezone(timezone: string) {
|
||||
const segments = timezone.split("/");
|
||||
|
||||
const capitalizedSegments = segments.map((segment) => {
|
||||
return capitalize(segment);
|
||||
});
|
||||
|
||||
return capitalizedSegments.join("/");
|
||||
}
|
||||
|
||||
function capitalize(str: string) {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user