Skip to content

Commit

Permalink
fix: ensure platform managed user has 1 schedule by default (#18719)
Browse files Browse the repository at this point in the history
* fix: ensure managed user has 1 schedule

* chore: bump platform libraries
  • Loading branch information
supalarry authored Jan 20, 2025
1 parent 02ef6dc commit bfeafaa
Show file tree
Hide file tree
Showing 5 changed files with 6,060 additions and 139 deletions.
2 changes: 1 addition & 1 deletion apps/api/v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@axiomhq/winston": "^1.2.0",
"@calcom/platform-constants": "*",
"@calcom/platform-enums": "*",
"@calcom/platform-libraries": "npm:@calcom/[email protected].85",
"@calcom/platform-libraries": "npm:@calcom/[email protected].86",
"@calcom/platform-libraries-0.0.2": "npm:@calcom/[email protected]",
"@calcom/platform-types": "*",
"@calcom/platform-utils": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ describe("OAuth Client Users Endpoints", () => {
await userConnectedToOAuth(responseBody.data.user.email);
await userHasDefaultEventTypes(responseBody.data.user.id);
await userHasDefaultSchedule(responseBody.data.user.id, responseBody.data.user.defaultScheduleId);
await userHasOnlyOneSchedule(responseBody.data.user.id);
});

async function userConnectedToOAuth(userEmail: string) {
Expand Down Expand Up @@ -260,6 +261,11 @@ describe("OAuth Client Users Endpoints", () => {
expect(schedule?.userId).toEqual(userId);
}

async function userHasOnlyOneSchedule(userId: number) {
const schedules = await schedulesRepositoryFixture.getByUserId(userId);
expect(schedules?.length).toEqual(1);
}

it(`should fail /POST using already used managed user email`, async () => {
const requestBody: CreateManagedUserInput = {
email: userEmail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ export class SchedulesRepositoryFixture {
async deleteAvailabilities(scheduleId: Schedule["id"]) {
return this.prismaWriteClient.availability.deleteMany({ where: { scheduleId } });
}

async getByUserId(userId: Schedule["userId"]) {
return this.prismaReadClient.schedule.findMany({ where: { userId } });
}
}
30 changes: 17 additions & 13 deletions packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,20 +346,24 @@ export async function createNewUsersConnectToOrgIfExists({
accepted: autoAccept, // If the user is invited to a child team, they are automatically accepted
},
},
schedules: {
create: {
name: t("default_schedule_name"),
availability: {
createMany: {
data: defaultAvailability.map((schedule) => ({
days: schedule.days,
startTime: schedule.startTime,
endTime: schedule.endTime,
})),
...(!isPlatformManaged
? {
schedules: {
create: {
name: t("default_schedule_name"),
availability: {
createMany: {
data: defaultAvailability.map((schedule) => ({
days: schedule.days,
startTime: schedule.startTime,
endTime: schedule.endTime,
})),
},
},
},
},
},
},
},
}
: {}),
},
});

Expand Down
Loading

0 comments on commit bfeafaa

Please sign in to comment.