Skip to content

Commit 68ce952

Browse files
authored
refactor: v2 schedules (#15403)
* refactor: platform-types schedule types * refactor: lib add bidirectional schedule transformers api <-> atom * refactor: trpc handlers use renamed lib transformers * refactor: platform-libraries export new bi-directional transformers * chore: v2 update platform-libraries * chore: enable also old platform-libraries * fix: platform-types support previous types * refactor: versioning date * chore: version old schedules as schedules_2024_04_15 module * chore: version old schedules as schedules_2024_04_15 module * feat: new 2024_06_11 schedules module * feat: atoms use refactored schedule api * refactor: remove ?for=atom in schedules hooks * fix: unit test
1 parent 357a42b commit 68ce952

File tree

79 files changed

+2664
-522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2664
-522
lines changed

apps/api/v2/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"dependencies": {
2727
"@calcom/platform-constants": "*",
2828
"@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2",
29+
"@calcom/platform-libraries-0.0.4": "npm:@calcom/platform-libraries@0.0.4",
2930
"@calcom/platform-types": "*",
3031
"@calcom/platform-utils": "*",
3132
"@calcom/prisma": "*",

apps/api/v2/src/app.ts

+2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export const bootstrap = (app: NestExpressApplication): NestExpressApplication =
3030
type: VersioningType.CUSTOM,
3131
extractor: (request: unknown) => {
3232
const headerVersion = (request as Request)?.headers[CAL_API_VERSION_HEADER] as string | undefined;
33+
console.log("asap header headerVersion", headerVersion);
3334
if (headerVersion && API_VERSIONS.includes(headerVersion as API_VERSIONS_ENUM)) {
35+
console.log("asap return header headerVersion", headerVersion);
3436
return headerVersion;
3537
}
3638
return VERSION_2024_04_15;

apps/api/v2/src/ee/bookings/controllers/bookings.controller.e2e-spec.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { bootstrap } from "@/app";
22
import { AppModule } from "@/app.module";
33
import { GetBookingOutput } from "@/ee/bookings/outputs/get-booking.output";
44
import { GetBookingsOutput } from "@/ee/bookings/outputs/get-bookings.output";
5-
import { CreateScheduleInput } from "@/ee/schedules/inputs/create-schedule.input";
6-
import { SchedulesModule } from "@/ee/schedules/schedules.module";
7-
import { SchedulesService } from "@/ee/schedules/services/schedules.service";
5+
import { CreateScheduleInput_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/inputs/create-schedule.input";
6+
import { SchedulesModule_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/schedules.module";
7+
import { SchedulesService_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/services/schedules.service";
88
import { PermissionsGuard } from "@/modules/auth/guards/permissions/permissions.guard";
9-
import { AvailabilitiesModule } from "@/modules/availabilities/availabilities.module";
109
import { PrismaModule } from "@/modules/prisma/prisma.module";
1110
import { UsersModule } from "@/modules/users/users.module";
1211
import { INestApplication } from "@nestjs/common";
@@ -29,7 +28,7 @@ describe("Bookings Endpoints", () => {
2928

3029
let userRepositoryFixture: UserRepositoryFixture;
3130
let bookingsRepositoryFixture: BookingsRepositoryFixture;
32-
let schedulesService: SchedulesService;
31+
let schedulesService: SchedulesService_2024_04_15;
3332
let eventTypesRepositoryFixture: EventTypesRepositoryFixture;
3433

3534
const userEmail = "bookings-controller-e2e@api.com";
@@ -43,7 +42,7 @@ describe("Bookings Endpoints", () => {
4342
const moduleRef = await withAccessTokenAuth(
4443
userEmail,
4544
Test.createTestingModule({
46-
imports: [AppModule, PrismaModule, AvailabilitiesModule, UsersModule, SchedulesModule],
45+
imports: [AppModule, PrismaModule, UsersModule, SchedulesModule_2024_04_15],
4746
})
4847
)
4948
.overrideGuard(PermissionsGuard)
@@ -55,13 +54,13 @@ describe("Bookings Endpoints", () => {
5554
userRepositoryFixture = new UserRepositoryFixture(moduleRef);
5655
bookingsRepositoryFixture = new BookingsRepositoryFixture(moduleRef);
5756
eventTypesRepositoryFixture = new EventTypesRepositoryFixture(moduleRef);
58-
schedulesService = moduleRef.get<SchedulesService>(SchedulesService);
57+
schedulesService = moduleRef.get<SchedulesService_2024_04_15>(SchedulesService_2024_04_15);
5958

6059
user = await userRepositoryFixture.create({
6160
email: userEmail,
6261
});
6362

64-
const userSchedule: CreateScheduleInput = {
63+
const userSchedule: CreateScheduleInput_2024_04_15 = {
6564
name: "working time",
6665
timeZone: "Europe/Rome",
6766
isDefault: true,

apps/api/v2/src/ee/me/me.controller.e2e-spec.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { bootstrap } from "@/app";
22
import { AppModule } from "@/app.module";
3-
import { SchedulesModule } from "@/ee/schedules/schedules.module";
3+
import { SchedulesModule_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/schedules.module";
44
import { PermissionsGuard } from "@/modules/auth/guards/permissions/permissions.guard";
5-
import { AvailabilitiesModule } from "@/modules/availabilities/availabilities.module";
65
import { PrismaModule } from "@/modules/prisma/prisma.module";
76
import { TokensModule } from "@/modules/tokens/tokens.module";
87
import { UpdateManagedUserInput } from "@/modules/users/inputs/update-managed-user.input";
@@ -34,14 +33,7 @@ describe("Me Endpoints", () => {
3433
const moduleRef = await withAccessTokenAuth(
3534
userEmail,
3635
Test.createTestingModule({
37-
imports: [
38-
AppModule,
39-
PrismaModule,
40-
AvailabilitiesModule,
41-
UsersModule,
42-
TokensModule,
43-
SchedulesModule,
44-
],
36+
imports: [AppModule, PrismaModule, UsersModule, TokensModule, SchedulesModule_2024_04_15],
4537
})
4638
)
4739
.overrideGuard(PermissionsGuard)
@@ -118,13 +110,13 @@ describe("Me Endpoints", () => {
118110
});
119111

120112
it("should not update user associated with access token given invalid time format", async () => {
121-
const bodyWithIncorrectTimeFormat: UpdateManagedUserInput = { timeFormat: 100 };
113+
const bodyWithIncorrectTimeFormat: UpdateManagedUserInput = { timeFormat: 100 as any };
122114

123115
return request(app.getHttpServer()).patch("/v2/me").send(bodyWithIncorrectTimeFormat).expect(400);
124116
});
125117

126118
it("should not update user associated with access token given invalid week start", async () => {
127-
const bodyWithIncorrectWeekStart: UpdateManagedUserInput = { weekStart: "waba luba dub dub" };
119+
const bodyWithIncorrectWeekStart: UpdateManagedUserInput = { weekStart: "waba luba dub dub" as any };
128120

129121
return request(app.getHttpServer()).patch("/v2/me").send(bodyWithIncorrectWeekStart).expect(400);
130122
});

apps/api/v2/src/ee/me/me.controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GetMeOutput } from "@/ee/me/outputs/get-me.output";
22
import { UpdateMeOutput } from "@/ee/me/outputs/update-me.output";
3-
import { SchedulesService } from "@/ee/schedules/services/schedules.service";
3+
import { SchedulesService_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/services/schedules.service";
44
import { API_VERSIONS_VALUES } from "@/lib/api-versions";
55
import { GetUser } from "@/modules/auth/decorators/get-user/get-user.decorator";
66
import { Permissions } from "@/modules/auth/decorators/permissions/permissions.decorator";
@@ -23,7 +23,7 @@ import { userSchemaResponse } from "@calcom/platform-types";
2323
export class MeController {
2424
constructor(
2525
private readonly usersRepository: UsersRepository,
26-
private readonly schedulesRepository: SchedulesService
26+
private readonly schedulesRepository: SchedulesService_2024_04_15
2727
) {}
2828

2929
@Get("/")

apps/api/v2/src/ee/me/me.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { MeController } from "@/ee/me/me.controller";
2-
import { SchedulesModule } from "@/ee/schedules/schedules.module";
2+
import { SchedulesModule_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/schedules.module";
33
import { TokensModule } from "@/modules/tokens/tokens.module";
44
import { UsersModule } from "@/modules/users/users.module";
55
import { Module } from "@nestjs/common";
66

77
@Module({
8-
imports: [UsersModule, SchedulesModule, TokensModule],
8+
imports: [UsersModule, SchedulesModule_2024_04_15, TokensModule],
99
controllers: [MeController],
1010
})
1111
export class MeModule {}

apps/api/v2/src/ee/platform-endpoints-module.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { EventTypesModule } from "@/ee/event-types/event-types.module";
44
import { GcalModule } from "@/ee/gcal/gcal.module";
55
import { MeModule } from "@/ee/me/me.module";
66
import { ProviderModule } from "@/ee/provider/provider.module";
7-
import { SchedulesModule } from "@/ee/schedules/schedules.module";
7+
import { SchedulesModule_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/schedules.module";
8+
import { SchedulesModule_2024_06_11 } from "@/ee/schedules/schedules_2024_06_11/schedules.module";
89
import { SlotsModule } from "@/modules/slots/slots.module";
910
import type { MiddlewareConsumer, NestModule } from "@nestjs/common";
1011
import { Module } from "@nestjs/common";
@@ -13,7 +14,8 @@ import { Module } from "@nestjs/common";
1314
imports: [
1415
GcalModule,
1516
ProviderModule,
16-
SchedulesModule,
17+
SchedulesModule_2024_04_15,
18+
SchedulesModule_2024_06_11,
1719
MeModule,
1820
EventTypesModule,
1921
CalendarsModule,

apps/api/v2/src/ee/schedules/schedules.module.ts

-16
This file was deleted.

apps/api/v2/src/ee/schedules/controllers/schedules.controller.e2e-spec.ts apps/api/v2/src/ee/schedules/schedules_2024_04_15/controllers/schedules.controller.e2e-spec.ts

+17-23
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { bootstrap } from "@/app";
22
import { AppModule } from "@/app.module";
3-
import { CreateScheduleInput } from "@/ee/schedules/inputs/create-schedule.input";
4-
import { CreateScheduleOutput } from "@/ee/schedules/outputs/create-schedule.output";
5-
import { GetSchedulesOutput } from "@/ee/schedules/outputs/get-schedules.output";
6-
import { UpdateScheduleOutput } from "@/ee/schedules/outputs/update-schedule.output";
7-
import { SchedulesModule } from "@/ee/schedules/schedules.module";
3+
import { CreateScheduleInput_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/inputs/create-schedule.input";
4+
import { CreateScheduleOutput_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/outputs/create-schedule.output";
5+
import { GetSchedulesOutput_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/outputs/get-schedules.output";
6+
import { UpdateScheduleOutput_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/outputs/update-schedule.output";
7+
import { SchedulesModule_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/schedules.module";
88
import { PermissionsGuard } from "@/modules/auth/guards/permissions/permissions.guard";
9-
import { AvailabilitiesModule } from "@/modules/availabilities/availabilities.module";
109
import { PrismaModule } from "@/modules/prisma/prisma.module";
1110
import { TokensModule } from "@/modules/tokens/tokens.module";
1211
import { UsersModule } from "@/modules/users/users.module";
@@ -19,8 +18,8 @@ import { SchedulesRepositoryFixture } from "test/fixtures/repository/schedules.r
1918
import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture";
2019
import { withAccessTokenAuth } from "test/utils/withAccessTokenAuth";
2120

22-
import { SUCCESS_STATUS } from "@calcom/platform-constants";
23-
import { UpdateScheduleInput } from "@calcom/platform-types";
21+
import { CAL_API_VERSION_HEADER, SUCCESS_STATUS, VERSION_2024_04_15 } from "@calcom/platform-constants";
22+
import { UpdateScheduleInput_2024_04_15 } from "@calcom/platform-types";
2423

2524
describe("Schedules Endpoints", () => {
2625
describe("User Authentication", () => {
@@ -32,7 +31,7 @@ describe("Schedules Endpoints", () => {
3231
const userEmail = "schedules-controller-e2e@api.com";
3332
let user: User;
3433

35-
let createdSchedule: CreateScheduleOutput["data"];
34+
let createdSchedule: CreateScheduleOutput_2024_04_15["data"];
3635
const defaultAvailabilityDays = [1, 2, 3, 4, 5];
3736
const defaultAvailabilityStartTime = "1970-01-01T09:00:00.000Z";
3837
const defaultAvailabilityEndTime = "1970-01-01T17:00:00.000Z";
@@ -41,14 +40,7 @@ describe("Schedules Endpoints", () => {
4140
const moduleRef = await withAccessTokenAuth(
4241
userEmail,
4342
Test.createTestingModule({
44-
imports: [
45-
AppModule,
46-
PrismaModule,
47-
AvailabilitiesModule,
48-
UsersModule,
49-
TokensModule,
50-
SchedulesModule,
51-
],
43+
imports: [AppModule, PrismaModule, UsersModule, TokensModule, SchedulesModule_2024_04_15],
5244
})
5345
)
5446
.overrideGuard(PermissionsGuard)
@@ -79,18 +71,19 @@ describe("Schedules Endpoints", () => {
7971
const scheduleTimeZone = "Europe/Rome";
8072
const isDefault = true;
8173

82-
const body: CreateScheduleInput = {
74+
const body: CreateScheduleInput_2024_04_15 = {
8375
name: scheduleName,
8476
timeZone: scheduleTimeZone,
8577
isDefault,
8678
};
8779

8880
return request(app.getHttpServer())
8981
.post("/api/v2/schedules")
82+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
9083
.send(body)
9184
.expect(201)
9285
.then(async (response) => {
93-
const responseData: CreateScheduleOutput = response.body;
86+
const responseData: CreateScheduleOutput_2024_04_15 = response.body;
9487
expect(responseData.status).toEqual(SUCCESS_STATUS);
9588
expect(responseData.data).toBeDefined();
9689
expect(responseData.data.isDefault).toEqual(isDefault);
@@ -117,7 +110,7 @@ describe("Schedules Endpoints", () => {
117110
.get("/api/v2/schedules/default")
118111
.expect(200)
119112
.then(async (response) => {
120-
const responseData: CreateScheduleOutput = response.body;
113+
const responseData: CreateScheduleOutput_2024_04_15 = response.body;
121114
expect(responseData.status).toEqual(SUCCESS_STATUS);
122115
expect(responseData.data).toBeDefined();
123116
expect(responseData.data.id).toEqual(createdSchedule.id);
@@ -137,7 +130,7 @@ describe("Schedules Endpoints", () => {
137130
.get(`/api/v2/schedules`)
138131
.expect(200)
139132
.then((response) => {
140-
const responseData: GetSchedulesOutput = response.body;
133+
const responseData: GetSchedulesOutput_2024_04_15 = response.body;
141134
expect(responseData.status).toEqual(SUCCESS_STATUS);
142135
expect(responseData.data).toBeDefined();
143136
expect(responseData.data?.[0].id).toEqual(createdSchedule.id);
@@ -155,16 +148,17 @@ describe("Schedules Endpoints", () => {
155148
it("should update schedule name", async () => {
156149
const newScheduleName = "new-schedule-name";
157150

158-
const body: UpdateScheduleInput = {
151+
const body: UpdateScheduleInput_2024_04_15 = {
159152
name: newScheduleName,
160153
};
161154

162155
return request(app.getHttpServer())
163156
.patch(`/api/v2/schedules/${createdSchedule.id}`)
157+
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
164158
.send(body)
165159
.expect(200)
166160
.then((response: any) => {
167-
const responseData: UpdateScheduleOutput = response.body;
161+
const responseData: UpdateScheduleOutput_2024_04_15 = response.body;
168162
expect(responseData.status).toEqual(SUCCESS_STATUS);
169163
expect(responseData.data).toBeDefined();
170164
expect(responseData.data.schedule.name).toEqual(newScheduleName);

0 commit comments

Comments
 (0)