Revert "refactor: api v2 schedules (#14870)" (#15130)

This reverts commit c25c835b76.
This commit is contained in:
Lauris Skraucis authored and GitHub committed 2024-05-20 16:26:48 +00:00
1 parent 98235d00c8
commit 5ee3744015
55 files changed
+1211 -1393

No files matched your search

@@ -2,9 +2,11 @@ import { bootstrap } from "@/app";
import { AppModule } from "@/app.module";
import { GetBookingOutput } from "@/ee/bookings/outputs/get-booking.output";
import { GetBookingsOutput } from "@/ee/bookings/outputs/get-bookings.output";
import { CreateScheduleInput } from "@/ee/schedules/inputs/create-schedule.input";
import { SchedulesModule } from "@/ee/schedules/schedules.module";
import { SchedulesService } from "@/ee/schedules/services/schedules.service";
import { PermissionsGuard } from "@/modules/auth/guards/permissions/permissions.guard";
import { AvailabilitiesModule } from "@/modules/availabilities/availabilities.module";
import { PrismaModule } from "@/modules/prisma/prisma.module";
import { UsersModule } from "@/modules/users/users.module";
import { INestApplication } from "@nestjs/common";
@@ -19,7 +21,6 @@ import { withAccessTokenAuth } from "test/utils/withAccessTokenAuth";
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
import { handleNewBooking } from "@calcom/platform-libraries";
import { CreateScheduleInput } from "@calcom/platform-types";
import { ApiSuccessResponse, ApiResponse } from "@calcom/platform-types";
describe("Bookings Endpoints", () => {
@@ -42,7 +43,7 @@ describe("Bookings Endpoints", () => {
const moduleRef = await withAccessTokenAuth(
userEmail,
Test.createTestingModule({
imports: [AppModule, PrismaModule, UsersModule, SchedulesModule],
imports: [AppModule, PrismaModule, AvailabilitiesModule, UsersModule, SchedulesModule],
})
)
.overrideGuard(PermissionsGuard)
@@ -2,6 +2,7 @@ import { bootstrap } from "@/app";
import { AppModule } from "@/app.module";
import { SchedulesModule } from "@/ee/schedules/schedules.module";
import { PermissionsGuard } from "@/modules/auth/guards/permissions/permissions.guard";
import { AvailabilitiesModule } from "@/modules/availabilities/availabilities.module";
import { PrismaModule } from "@/modules/prisma/prisma.module";
import { TokensModule } from "@/modules/tokens/tokens.module";
import { UpdateManagedUserInput } from "@/modules/users/inputs/update-managed-user.input";
@@ -33,7 +34,14 @@ describe("Me Endpoints", () => {
const moduleRef = await withAccessTokenAuth(
userEmail,
Test.createTestingModule({
imports: [AppModule, PrismaModule, UsersModule, TokensModule, SchedulesModule],
imports: [
AppModule,
PrismaModule,
AvailabilitiesModule,
UsersModule,
TokensModule,
SchedulesModule,
],
})
)
.overrideGuard(PermissionsGuard)
@@ -110,13 +118,13 @@ describe("Me Endpoints", () => {
});
it("should not update user associated with access token given invalid time format", async () => {
const bodyWithIncorrectTimeFormat = { timeFormat: 100 };
const bodyWithIncorrectTimeFormat: UpdateManagedUserInput = { timeFormat: 100 };
return request(app.getHttpServer()).patch("/v2/me").send(bodyWithIncorrectTimeFormat).expect(400);
});
it("should not update user associated with access token given invalid week start", async () => {
const bodyWithIncorrectWeekStart = { weekStart: "waba luba dub dub" };
const bodyWithIncorrectWeekStart: UpdateManagedUserInput = { weekStart: "waba luba dub dub" };
return request(app.getHttpServer()).patch("/v2/me").send(bodyWithIncorrectWeekStart).expect(400);
});
+1 -1
View File
@@ -44,7 +44,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.id, user.defaultScheduleId, {
await this.schedulesRepository.updateUserSchedule(user, user.defaultScheduleId, {
timeZone: bodySchedule.timeZone,
});
}
@@ -1,7 +1,12 @@
import { bootstrap } from "@/app";
import { AppModule } from "@/app.module";
import { CreateScheduleInput } from "@/ee/schedules/inputs/create-schedule.input";
import { CreateScheduleOutput } from "@/ee/schedules/outputs/create-schedule.output";
import { GetSchedulesOutput } from "@/ee/schedules/outputs/get-schedules.output";
import { UpdateScheduleOutput } from "@/ee/schedules/outputs/update-schedule.output";
import { SchedulesModule } from "@/ee/schedules/schedules.module";
import { PermissionsGuard } from "@/modules/auth/guards/permissions/permissions.guard";
import { AvailabilitiesModule } from "@/modules/availabilities/availabilities.module";
import { PrismaModule } from "@/modules/prisma/prisma.module";
import { TokensModule } from "@/modules/tokens/tokens.module";
import { UsersModule } from "@/modules/users/users.module";
@@ -15,14 +20,6 @@ import { UserRepositoryFixture } from "test/fixtures/repository/users.repository
import { withAccessTokenAuth } from "test/utils/withAccessTokenAuth";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import {
CreateScheduleInput,
CreateScheduleOutput,
GetScheduleOutput,
GetSchedulesOutput,
ScheduleOutput,
UpdateScheduleOutput,
} from "@calcom/platform-types";
import { UpdateScheduleInput } from "@calcom/platform-types";
describe("Schedules Endpoints", () => {
@@ -35,27 +32,23 @@ describe("Schedules Endpoints", () => {
const userEmail = "[email protected]";
let user: User;
const createScheduleInput: CreateScheduleInput = {
name: "work",
timeZone: "Europe/Rome",
isDefault: true,
};
const defaultAvailability: CreateScheduleInput["availability"] = [
{
days: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
startTime: "09:00",
endTime: "17:00",
},
];
let createdSchedule: CreateScheduleOutput["data"];
const defaultAvailabilityDays = [1, 2, 3, 4, 5];
const defaultAvailabilityStartTime = "1970-01-01T09:00:00.000Z";
const defaultAvailabilityEndTime = "1970-01-01T17:00:00.000Z";
beforeAll(async () => {
const moduleRef = await withAccessTokenAuth(
userEmail,
Test.createTestingModule({
imports: [AppModule, PrismaModule, UsersModule, TokensModule, SchedulesModule],
imports: [
AppModule,
PrismaModule,
AvailabilitiesModule,
UsersModule,
TokensModule,
SchedulesModule,
],
})
)
.overrideGuard(PermissionsGuard)
@@ -82,66 +75,60 @@ describe("Schedules Endpoints", () => {
});
it("should create a default schedule", async () => {
const scheduleName = "schedule-name";
const scheduleTimeZone = "Europe/Rome";
const isDefault = true;
const body: CreateScheduleInput = {
name: scheduleName,
timeZone: scheduleTimeZone,
isDefault,
};
return request(app.getHttpServer())
.post("/api/v2/schedules")
.send(createScheduleInput)
.send(body)
.expect(201)
.then(async (response) => {
const responseBody: CreateScheduleOutput = response.body;
expect(responseBody.status).toEqual(SUCCESS_STATUS);
createdSchedule = response.body.data;
const responseData: CreateScheduleOutput = response.body;
expect(responseData.status).toEqual(SUCCESS_STATUS);
expect(responseData.data).toBeDefined();
expect(responseData.data.isDefault).toEqual(isDefault);
expect(responseData.data.timeZone).toEqual(scheduleTimeZone);
expect(responseData.data.name).toEqual(scheduleName);
const expectedSchedule = {
...createScheduleInput,
availability: defaultAvailability,
overrides: [],
};
outputScheduleMatchesExpected(createdSchedule, expectedSchedule, 1);
const schedule = responseData.data.schedule;
expect(schedule).toBeDefined();
expect(schedule.length).toEqual(1);
expect(schedule?.[0]?.days).toEqual(defaultAvailabilityDays);
expect(schedule?.[0]?.startTime).toEqual(defaultAvailabilityStartTime);
expect(schedule?.[0]?.endTime).toEqual(defaultAvailabilityEndTime);
const scheduleOwner = createdSchedule.ownerId
? await userRepositoryFixture.get(createdSchedule.ownerId)
const scheduleUser = schedule?.[0].userId
? await userRepositoryFixture.get(schedule?.[0].userId)
: null;
expect(scheduleOwner?.defaultScheduleId).toEqual(createdSchedule.id);
expect(scheduleUser?.defaultScheduleId).toEqual(responseData.data.id);
createdSchedule = responseData.data;
});
});
function outputScheduleMatchesExpected(
outputSchedule: ScheduleOutput | null,
expected: CreateScheduleInput & { availability: CreateScheduleInput["availability"] } & {
overrides: CreateScheduleInput["overrides"];
},
expectedAvailabilityLength: number
) {
expect(outputSchedule).toBeTruthy();
expect(outputSchedule?.name).toEqual(expected.name);
expect(outputSchedule?.timeZone).toEqual(expected.timeZone);
expect(outputSchedule?.isDefault).toEqual(expected.isDefault);
expect(outputSchedule?.availability.length).toEqual(expectedAvailabilityLength);
const outputScheduleAvailability = outputSchedule?.availability[0];
expect(outputScheduleAvailability).toBeDefined();
expect(outputScheduleAvailability?.days).toEqual(expected.availability?.[0].days);
expect(outputScheduleAvailability?.startTime).toEqual(expected.availability?.[0].startTime);
expect(outputScheduleAvailability?.endTime).toEqual(expected.availability?.[0].endTime);
expect(JSON.stringify(outputSchedule?.overrides)).toEqual(JSON.stringify(expected.overrides));
}
it("should get default schedule", async () => {
return request(app.getHttpServer())
.get("/api/v2/schedules/default")
.expect(200)
.then(async (response) => {
const responseBody: GetScheduleOutput = response.body;
expect(responseBody.status).toEqual(SUCCESS_STATUS);
const outputSchedule = responseBody.data;
const responseData: CreateScheduleOutput = response.body;
expect(responseData.status).toEqual(SUCCESS_STATUS);
expect(responseData.data).toBeDefined();
expect(responseData.data.id).toEqual(createdSchedule.id);
expect(responseData.data.schedule?.[0].userId).toEqual(createdSchedule.schedule[0].userId);
const expectedSchedule = {
...createScheduleInput,
availability: defaultAvailability,
overrides: [],
};
outputScheduleMatchesExpected(outputSchedule, expectedSchedule, 1);
const schedule = responseData.data.schedule;
expect(schedule).toBeDefined();
expect(schedule.length).toEqual(1);
expect(schedule?.[0]?.days).toEqual(defaultAvailabilityDays);
expect(schedule?.[0]?.startTime).toEqual(defaultAvailabilityStartTime);
expect(schedule?.[0]?.endTime).toEqual(defaultAvailabilityEndTime);
});
});
@@ -150,21 +137,23 @@ describe("Schedules Endpoints", () => {
.get(`/api/v2/schedules`)
.expect(200)
.then((response) => {
const responseBody: GetSchedulesOutput = response.body;
expect(responseBody.status).toEqual(SUCCESS_STATUS);
const outputSchedule = responseBody.data[0];
const responseData: GetSchedulesOutput = response.body;
expect(responseData.status).toEqual(SUCCESS_STATUS);
expect(responseData.data).toBeDefined();
expect(responseData.data?.[0].id).toEqual(createdSchedule.id);
expect(responseData.data?.[0].schedule?.[0].userId).toEqual(createdSchedule.schedule[0].userId);
const expectedSchedule = {
...createScheduleInput,
availability: defaultAvailability,
overrides: [],
};
outputScheduleMatchesExpected(outputSchedule, expectedSchedule, 1);
const schedule = responseData.data?.[0].schedule;
expect(schedule).toBeDefined();
expect(schedule.length).toEqual(1);
expect(schedule?.[0]?.days).toEqual(defaultAvailabilityDays);
expect(schedule?.[0]?.startTime).toEqual(defaultAvailabilityStartTime);
expect(schedule?.[0]?.endTime).toEqual(defaultAvailabilityEndTime);
});
});
it("should update schedule name", async () => {
const newScheduleName = "updated-schedule-name";
const newScheduleName = "new-schedule-name";
const body: UpdateScheduleInput = {
name: newScheduleName,
@@ -177,41 +166,19 @@ describe("Schedules Endpoints", () => {
.then((response: any) => {
const responseData: UpdateScheduleOutput = response.body;
expect(responseData.status).toEqual(SUCCESS_STATUS);
const responseSchedule = responseData.data;
expect(responseData.data).toBeDefined();
expect(responseData.data.schedule.name).toEqual(newScheduleName);
expect(responseData.data.schedule.id).toEqual(createdSchedule.id);
expect(responseData.data.schedule.userId).toEqual(createdSchedule.schedule[0].userId);
const expectedSchedule = { ...createdSchedule, name: newScheduleName };
outputScheduleMatchesExpected(responseSchedule, expectedSchedule, 1);
const availability = responseData.data.schedule.availability;
expect(availability).toBeDefined();
expect(availability?.length).toEqual(1);
expect(availability?.[0]?.days).toEqual(defaultAvailabilityDays);
expect(availability?.[0]?.startTime).toEqual(defaultAvailabilityStartTime);
expect(availability?.[0]?.endTime).toEqual(defaultAvailabilityEndTime);
createdSchedule = responseSchedule;
});
});
it("should add overrides", async () => {
const overrides = [
{
date: "2026-05-05",
startTime: "10:00",
endTime: "12:00",
},
];
const body: UpdateScheduleInput = {
overrides,
};
return request(app.getHttpServer())
.patch(`/api/v2/schedules/${createdSchedule.id}`)
.send(body)
.expect(200)
.then((response: any) => {
const responseData: UpdateScheduleOutput = response.body;
expect(responseData.status).toEqual(SUCCESS_STATUS);
const responseSchedule = responseData.data;
const expectedSchedule = { ...createdSchedule, overrides };
outputScheduleMatchesExpected(responseSchedule, expectedSchedule, 1);
createdSchedule = responseSchedule;
createdSchedule.name = newScheduleName;
});
});
@@ -1,3 +1,9 @@
import { CreateScheduleOutput } from "@/ee/schedules/outputs/create-schedule.output";
import { DeleteScheduleOutput } from "@/ee/schedules/outputs/delete-schedule.output";
import { GetDefaultScheduleOutput } from "@/ee/schedules/outputs/get-default-schedule.output";
import { GetScheduleOutput } from "@/ee/schedules/outputs/get-schedule.output";
import { GetSchedulesOutput } from "@/ee/schedules/outputs/get-schedules.output";
import { UpdateScheduleOutput } from "@/ee/schedules/outputs/update-schedule.output";
import { SchedulesService } from "@/ee/schedules/services/schedules.service";
import { GetUser } from "@/modules/auth/decorators/get-user/get-user.decorator";
import { Permissions } from "@/modules/auth/decorators/permissions/permissions.decorator";
@@ -20,16 +26,9 @@ import { ApiResponse, ApiTags as DocsTags } from "@nestjs/swagger";
import { Throttle } from "@nestjs/throttler";
import { SCHEDULE_READ, SCHEDULE_WRITE, SUCCESS_STATUS } from "@calcom/platform-constants";
import {
CreateScheduleOutput,
CreateScheduleInput,
UpdateScheduleInput,
GetScheduleOutput,
UpdateScheduleOutput,
GetDefaultScheduleOutput,
DeleteScheduleOutput,
GetSchedulesOutput,
} from "@calcom/platform-types";
import { UpdateScheduleInput } from "@calcom/platform-types";
import { CreateScheduleInput } from "../inputs/create-schedule.input";
@Controller({
path: "schedules",
@@ -47,22 +46,26 @@ export class SchedulesController {
@Body() bodySchedule: CreateScheduleInput
): Promise<CreateScheduleOutput> {
const schedule = await this.schedulesService.createUserSchedule(user.id, bodySchedule);
const scheduleFormatted = await this.schedulesService.formatScheduleForAtom(user, schedule);
return {
status: SUCCESS_STATUS,
data: schedule,
data: scheduleFormatted,
};
}
@Get("/default")
@Permissions([SCHEDULE_READ])
@ApiResponse({ status: 200, description: "Returns the default schedule", type: GetDefaultScheduleOutput })
async getDefaultSchedule(@GetUser() user: UserWithProfile): Promise<GetScheduleOutput> {
async getDefaultSchedule(@GetUser() user: UserWithProfile): Promise<GetDefaultScheduleOutput | null> {
const schedule = await this.schedulesService.getUserScheduleDefault(user.id);
const scheduleFormatted = schedule
? await this.schedulesService.formatScheduleForAtom(user, schedule)
: null;
return {
status: SUCCESS_STATUS,
data: schedule,
data: scheduleFormatted,
};
}
@@ -74,10 +77,11 @@ export class SchedulesController {
@Param("scheduleId") scheduleId: number
): Promise<GetScheduleOutput> {
const schedule = await this.schedulesService.getUserSchedule(user.id, scheduleId);
const scheduleFormatted = await this.schedulesService.formatScheduleForAtom(user, schedule);
return {
status: SUCCESS_STATUS,
data: schedule,
data: scheduleFormatted,
};
}
@@ -85,13 +89,15 @@ export class SchedulesController {
@Permissions([SCHEDULE_READ])
async getSchedules(@GetUser() user: UserWithProfile): Promise<GetSchedulesOutput> {
const schedules = await this.schedulesService.getUserSchedules(user.id);
const schedulesFormatted = await this.schedulesService.formatSchedulesForAtom(user, schedules);
return {
status: SUCCESS_STATUS,
data: schedules,
data: schedulesFormatted,
};
}
// note(Lauris): currently this endpoint is atoms only
@Patch("/:scheduleId")
@Permissions([SCHEDULE_WRITE])
async updateSchedule(
@@ -100,7 +106,7 @@ export class SchedulesController {
@Param("scheduleId") scheduleId: string
): Promise<UpdateScheduleOutput> {
const updatedSchedule = await this.schedulesService.updateUserSchedule(
user.id,
user,
Number(scheduleId),
bodySchedule
);
@@ -0,0 +1,20 @@
import { CreateAvailabilityInput } from "@/modules/availabilities/inputs/create-availability.input";
import { Type } from "class-transformer";
import { IsArray, IsBoolean, IsTimeZone, IsOptional, IsString, ValidateNested } from "class-validator";
export class CreateScheduleInput {
@IsString()
name!: string;
@IsTimeZone()
timeZone!: string;
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateAvailabilityInput)
@IsOptional()
availabilities?: CreateAvailabilityInput[];
@IsBoolean()
isDefault!: boolean;
}
@@ -0,0 +1,20 @@
import { ScheduleOutput } from "@/ee/schedules/outputs/schedule.output";
import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsEnum, IsNotEmptyObject, ValidateNested } from "class-validator";
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
export class CreateScheduleOutput {
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
@ApiProperty({
type: ScheduleOutput,
})
@IsNotEmptyObject()
@ValidateNested()
@Type(() => ScheduleOutput)
data!: ScheduleOutput;
}
@@ -0,0 +1,10 @@
import { ApiProperty } from "@nestjs/swagger";
import { IsEnum } from "class-validator";
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
export class DeleteScheduleOutput {
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
}
@@ -0,0 +1,20 @@
import { ScheduleOutput } from "@/ee/schedules/outputs/schedule.output";
import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsEnum, IsNotEmptyObject, ValidateNested } from "class-validator";
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
export class GetDefaultScheduleOutput {
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
@ApiProperty({
type: ScheduleOutput,
})
@IsNotEmptyObject()
@ValidateNested()
@Type(() => ScheduleOutput)
data!: ScheduleOutput | null;
}
@@ -0,0 +1,20 @@
import { ScheduleOutput } from "@/ee/schedules/outputs/schedule.output";
import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsEnum, IsNotEmptyObject, ValidateNested } from "class-validator";
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
export class GetScheduleOutput {
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
@ApiProperty({
type: ScheduleOutput,
})
@IsNotEmptyObject()
@ValidateNested()
@Type(() => ScheduleOutput)
data!: ScheduleOutput;
}
@@ -0,0 +1,21 @@
import { ScheduleOutput } from "@/ee/schedules/outputs/schedule.output";
import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsArray, IsEnum, IsNotEmptyObject, ValidateNested } from "class-validator";
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
export class GetSchedulesOutput {
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
@ApiProperty({
type: ScheduleOutput,
})
@IsNotEmptyObject()
@ValidateNested({ each: true })
@Type(() => ScheduleOutput)
@IsArray()
data!: ScheduleOutput[];
}
@@ -0,0 +1,95 @@
import { Type } from "class-transformer";
import { IsBoolean, IsInt, IsOptional, IsString, ValidateNested, IsArray } from "class-validator";
class EventTypeModel {
@IsInt()
id!: number;
@IsOptional()
@IsString()
eventName?: string | null;
}
class AvailabilityModel {
@IsInt()
id!: number;
@IsOptional()
@IsInt()
userId?: number | null;
@IsOptional()
@IsInt()
scheduleId?: number | null;
@IsOptional()
@IsInt()
eventTypeId?: number | null;
@IsArray()
@IsInt({ each: true })
days!: number[];
@IsOptional()
@Type(() => Date)
@IsString() // Assuming date is serialized/deserialized appropriately
startTime?: Date;
@IsOptional()
@Type(() => Date)
@IsString() // Assuming date is serialized/deserialized appropriately
endTime?: Date;
@IsOptional()
@Type(() => Date)
@IsString() // Assuming date is serialized/deserialized appropriately
date?: Date | null;
}
class ScheduleModel {
@IsInt()
id!: number;
@IsInt()
userId!: number;
@IsString()
name!: string;
@IsOptional()
@IsString()
timeZone?: string | null;
@IsOptional()
@ValidateNested({ each: true })
@Type(() => EventTypeModel)
@IsArray()
eventType?: EventTypeModel[];
@IsOptional()
@ValidateNested({ each: true })
@Type(() => AvailabilityModel)
@IsArray()
availability?: AvailabilityModel[];
}
export class UpdatedScheduleOutput {
@ValidateNested()
@Type(() => ScheduleModel)
schedule!: ScheduleModel;
@IsBoolean()
isDefault!: boolean;
@IsOptional()
@IsString()
timeZone?: string;
@IsOptional()
@IsInt()
prevDefaultId?: number | null;
@IsOptional()
@IsInt()
currentDefaultId?: number | null;
}
@@ -0,0 +1,105 @@
import { Type } from "class-transformer";
import { IsDate, IsOptional, IsArray, IsBoolean, IsInt, IsString, ValidateNested } from "class-validator";
class AvailabilityModel {
@IsInt()
id!: number;
@IsOptional()
@IsInt()
userId?: number | null;
@IsOptional()
@IsInt()
eventTypeId?: number | null;
@IsArray()
@IsInt({ each: true })
days!: number[];
@IsDate()
@Type(() => Date)
startTime!: Date;
@IsDate()
@Type(() => Date)
endTime!: Date;
@IsOptional()
@IsDate()
@Type(() => Date)
date?: Date | null;
@IsOptional()
@IsInt()
scheduleId?: number | null;
}
class WorkingHours {
@IsArray()
@IsInt({ each: true })
days!: number[];
@IsInt()
startTime!: number;
@IsInt()
endTime!: number;
@IsOptional()
@IsInt()
userId?: number | null;
}
class TimeRange {
@IsOptional()
@IsInt()
userId?: number | null;
@IsDate()
start!: Date;
@IsDate()
end!: Date;
}
export class ScheduleOutput {
@IsInt()
id!: number;
@IsString()
name!: string;
@IsBoolean()
isManaged!: boolean;
@ValidateNested({ each: true })
@Type(() => WorkingHours)
workingHours!: WorkingHours[];
@ValidateNested({ each: true })
@Type(() => AvailabilityModel)
@IsArray()
schedule!: AvailabilityModel[];
availability!: TimeRange[][];
@IsString()
timeZone!: string;
@ValidateNested({ each: true })
@IsArray()
// note(Lauris) it should be
// dateOverrides!: { ranges: TimeRange[] }[];
// but docs aren't generating correctly it results in array of strings
dateOverrides!: unknown[];
@IsBoolean()
isDefault!: boolean;
@IsBoolean()
isLastSchedule!: boolean;
@IsBoolean()
readOnly!: boolean;
}
@@ -0,0 +1,20 @@
import { UpdatedScheduleOutput } from "@/ee/schedules/outputs/schedule-updated.output";
import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsEnum, IsNotEmptyObject, ValidateNested } from "class-validator";
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
export class UpdateScheduleOutput {
@ApiProperty({ example: SUCCESS_STATUS, enum: [SUCCESS_STATUS, ERROR_STATUS] })
@IsEnum([SUCCESS_STATUS, ERROR_STATUS])
status!: typeof SUCCESS_STATUS | typeof ERROR_STATUS;
@ApiProperty({
type: UpdatedScheduleOutput,
})
@IsNotEmptyObject()
@ValidateNested()
@Type(() => UpdatedScheduleOutput)
data!: UpdatedScheduleOutput;
}
@@ -1,16 +1,15 @@
import { SchedulesController } from "@/ee/schedules/controllers/schedules.controller";
import { SchedulesRepository } from "@/ee/schedules/schedules.repository";
import { InputSchedulesService } from "@/ee/schedules/services/input-schedules.service";
import { OutputSchedulesService } from "@/ee/schedules/services/output-schedules.service";
import { SchedulesService } from "@/ee/schedules/services/schedules.service";
import { AvailabilitiesModule } from "@/modules/availabilities/availabilities.module";
import { PrismaModule } from "@/modules/prisma/prisma.module";
import { TokensModule } from "@/modules/tokens/tokens.module";
import { UsersModule } from "@/modules/users/users.module";
import { Module } from "@nestjs/common";
@Module({
imports: [PrismaModule, UsersModule, TokensModule],
providers: [SchedulesRepository, SchedulesService, InputSchedulesService, OutputSchedulesService],
imports: [PrismaModule, AvailabilitiesModule, UsersModule, TokensModule],
providers: [SchedulesRepository, SchedulesService],
controllers: [SchedulesController],
exports: [SchedulesService, SchedulesRepository],
})
@@ -1,34 +1,19 @@
import { CreateScheduleInput } from "@/ee/schedules/inputs/create-schedule.input";
import { CreateAvailabilityInput } from "@/modules/availabilities/inputs/create-availability.input";
import { PrismaReadService } from "@/modules/prisma/prisma-read.service";
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
import { Injectable } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import type { CreateScheduleInput } from "@calcom/platform-types";
type InputScheduleAvailabilityTransformed = {
days: number[];
startTime: Date;
endTime: Date;
};
type InputScheduleOverrideTransformed = {
date: Date;
startTime: Date;
endTime: Date;
};
type InputScheduleTransformed = Omit<CreateScheduleInput, "availability" | "overrides"> & {
availability: InputScheduleAvailabilityTransformed[];
overrides: InputScheduleOverrideTransformed[];
};
@Injectable()
export class SchedulesRepository {
constructor(private readonly dbRead: PrismaReadService, private readonly dbWrite: PrismaWriteService) {}
async createSchedule(userId: number, schedule: Omit<InputScheduleTransformed, "isDefault">) {
const { availability, overrides } = schedule;
async createScheduleWithAvailabilities(
userId: number,
schedule: CreateScheduleInput,
availabilities: CreateAvailabilityInput[]
) {
const createScheduleData: Prisma.ScheduleCreateInput = {
user: {
connect: {
@@ -39,34 +24,17 @@ export class SchedulesRepository {
timeZone: schedule.timeZone,
};
const availabilitiesAndOverrides: Prisma.AvailabilityCreateManyInput[] = [];
if (availability && availability.length > 0) {
availability.forEach((availability) => {
availabilitiesAndOverrides.push({
days: availability.days,
startTime: availability.startTime,
endTime: availability.endTime,
userId,
});
});
}
if (overrides && overrides.length > 0) {
overrides.forEach((override) => {
availabilitiesAndOverrides.push({
date: override.date,
startTime: override.startTime,
endTime: override.endTime,
userId,
});
});
}
if (availabilitiesAndOverrides.length > 0) {
if (availabilities.length > 0) {
createScheduleData.availability = {
createMany: {
data: availabilitiesAndOverrides,
data: availabilities.map((availability) => {
return {
days: availability.days,
startTime: availability.startTime,
endTime: availability.endTime,
userId,
};
}),
},
};
}
@@ -96,87 +64,6 @@ export class SchedulesRepository {
return schedule;
}
async updateSchedule(
userId: number,
scheduleId: number,
schedule: Partial<Omit<InputScheduleTransformed, "isDefault">>
) {
const { availability, overrides } = schedule;
const updateScheduleData: Prisma.ScheduleUpdateInput = {
name: schedule.name,
timeZone: schedule.timeZone,
};
const availabilitiesAndOverrides: Prisma.AvailabilityCreateManyInput[] = [];
const deleteConditions = [];
if (availability) {
// note(Lauris): availabilities and overrides are stored in the same "Availability" table,
// but availabilities have "date" field as null, while overrides have it as not null, so delete
// condition below results in deleting only rows from Availability table that are availabilities.
deleteConditions.push({
scheduleId: { equals: scheduleId },
date: null,
});
}
if (overrides) {
// note(Lauris): availabilities and overrides are stored in the same "Availability" table,
// but overrides have "date" field as not-null, while availabilities have it as null, so delete
// condition below results in deleting only rows from Availability table that are overrides.
deleteConditions.push({
scheduleId: { equals: scheduleId },
NOT: { date: null },
});
}
if (availability && availability.length > 0) {
availability.forEach((availability) => {
availabilitiesAndOverrides.push({
days: availability.days,
startTime: availability.startTime,
endTime: availability.endTime,
userId,
});
});
}
if (overrides && overrides.length > 0) {
overrides.forEach((override) => {
availabilitiesAndOverrides.push({
date: override.date,
startTime: override.startTime,
endTime: override.endTime,
userId,
});
});
}
if (availabilitiesAndOverrides.length > 0) {
updateScheduleData.availability = {
deleteMany: deleteConditions,
createMany: {
data: availabilitiesAndOverrides,
},
};
}
const updatedSchedule = await this.dbWrite.prisma.schedule.update({
where: {
id: scheduleId,
},
data: {
...updateScheduleData,
},
include: {
availability: true,
},
});
return updatedSchedule;
}
async getSchedulesByUserId(userId: number) {
const schedules = await this.dbRead.prisma.schedule.findMany({
where: {
@@ -1,40 +0,0 @@
import { Injectable } from "@nestjs/common";
import { transformApiScheduleOverrides, transformApiScheduleAvailability } from "@calcom/platform-libraries";
import { CreateScheduleInput, ScheduleAvailabilityInput } from "@calcom/platform-types";
import { ScheduleOverrideInput } from "@calcom/platform-types";
@Injectable()
export class InputSchedulesService {
transformInputCreateSchedule(inputSchedule: CreateScheduleInput) {
const defaultAvailability: ScheduleAvailabilityInput[] = [
{
days: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
startTime: "09:00",
endTime: "17:00",
},
];
const defaultOverrides: ScheduleOverrideInput[] = [];
const availability = this.transformInputScheduleAvailability(
inputSchedule.availability || defaultAvailability
);
const overrides = this.transformInputOverrides(inputSchedule.overrides || defaultOverrides);
const internalCreateSchedule = {
...inputSchedule,
availability,
overrides,
};
return internalCreateSchedule;
}
transformInputScheduleAvailability(inputAvailability: ScheduleAvailabilityInput[]) {
return transformApiScheduleAvailability(inputAvailability);
}
transformInputOverrides(inputOverrides: ScheduleOverrideInput[]) {
return transformApiScheduleOverrides(inputOverrides);
}
}
@@ -1,78 +0,0 @@
import { UsersRepository } from "@/modules/users/users.repository";
import { Injectable } from "@nestjs/common";
import type { Availability, Schedule } from "@prisma/client";
import { WeekDay } from "@calcom/platform-types";
@Injectable()
export class OutputSchedulesService {
constructor(private readonly usersRepository: UsersRepository) {}
async getResponseSchedule(databaseSchedule: Schedule & { availability: Availability[] }) {
if (!databaseSchedule.timeZone) {
throw new Error("Failed to create schedule because its timezone is not set.");
}
const ownerDefaultScheduleId = await this.usersRepository.getUserScheduleDefaultId(
databaseSchedule.userId
);
const createdScheduleAvailabilities = databaseSchedule.availability.filter(
(availability) => !!availability.days.length
);
const createdScheduleOverrides = databaseSchedule.availability.filter((override) => !!override.date);
return {
id: databaseSchedule.id,
ownerId: databaseSchedule.userId,
name: databaseSchedule.name,
timeZone: databaseSchedule.timeZone,
availability: createdScheduleAvailabilities.map((availability) => ({
days: availability.days.map(transformNumberToDay),
startTime: this.padHoursMinutesWithZeros(
availability.startTime.getUTCHours() + ":" + availability.startTime.getUTCMinutes()
),
endTime: this.padHoursMinutesWithZeros(
availability.endTime.getUTCHours() + ":" + availability.endTime.getUTCMinutes()
),
})),
isDefault: databaseSchedule.id === ownerDefaultScheduleId,
overrides: createdScheduleOverrides.map((override) => ({
date:
override.date?.getUTCFullYear() +
"-" +
(override.date ? override.date.getUTCMonth() + 1 : "").toString().padStart(2, "0") +
"-" +
override.date?.getUTCDate().toString().padStart(2, "0"),
startTime: this.padHoursMinutesWithZeros(
override.startTime.getUTCHours() + ":" + override.startTime.getUTCMinutes()
),
endTime: this.padHoursMinutesWithZeros(
override.endTime.getUTCHours() + ":" + override.endTime.getUTCMinutes()
),
})),
};
}
padHoursMinutesWithZeros(hhMM: string) {
const [hours, minutes] = hhMM.split(":");
const formattedHours = hours.padStart(2, "0");
const formattedMinutes = minutes.padStart(2, "0");
return `${formattedHours}:${formattedMinutes}`;
}
}
function transformNumberToDay(day: number): WeekDay {
const weekMap: { [key: number]: WeekDay } = {
0: "Sunday",
1: "Monday",
2: "Tuesday",
3: "Wednesday",
4: "Thursday",
5: "Friday",
6: "Saturday",
};
return weekMap[day];
}
@@ -1,42 +1,55 @@
import { CreateScheduleInput } from "@/ee/schedules/inputs/create-schedule.input";
import { ScheduleOutput } from "@/ee/schedules/outputs/schedule.output";
import { SchedulesRepository } from "@/ee/schedules/schedules.repository";
import { InputSchedulesService } from "@/ee/schedules/services/input-schedules.service";
import { OutputSchedulesService } from "@/ee/schedules/services/output-schedules.service";
import { UsersRepository } from "@/modules/users/users.repository";
import { AvailabilitiesService } from "@/modules/availabilities/availabilities.service";
import { UserWithProfile, UsersRepository } from "@/modules/users/users.repository";
import { BadRequestException, ForbiddenException, Injectable, NotFoundException } from "@nestjs/common";
import { Schedule } from "@prisma/client";
import { User } from "@prisma/client";
import { CreateScheduleInput, ScheduleOutput } from "@calcom/platform-types";
import type { ScheduleWithAvailabilities } from "@calcom/platform-libraries";
import { updateScheduleHandler } from "@calcom/platform-libraries";
import {
transformWorkingHoursForClient,
transformAvailabilityForClient,
transformDateOverridesForClient,
} from "@calcom/platform-libraries";
import { UpdateScheduleInput } from "@calcom/platform-types";
@Injectable()
export class SchedulesService {
constructor(
private readonly schedulesRepository: SchedulesRepository,
private readonly inputSchedulesService: InputSchedulesService,
private readonly outputSchedulesService: OutputSchedulesService,
private readonly availabilitiesService: AvailabilitiesService,
private readonly usersRepository: UsersRepository
) {}
async createUserDefaultSchedule(userId: number, timeZone: string) {
const defaultSchedule = {
const schedule = {
isDefault: true,
name: "Default schedule",
timeZone,
};
return this.createUserSchedule(userId, defaultSchedule);
return this.createUserSchedule(userId, schedule);
}
async createUserSchedule(userId: number, scheduleInput: CreateScheduleInput): Promise<ScheduleOutput> {
const schedule = this.inputSchedulesService.transformInputCreateSchedule(scheduleInput);
async createUserSchedule(userId: number, schedule: CreateScheduleInput) {
const availabilities = schedule.availabilities?.length
? schedule.availabilities
: [this.availabilitiesService.getDefaultAvailabilityInput()];
const createdSchedule = await this.schedulesRepository.createSchedule(userId, schedule);
const createdSchedule = await this.schedulesRepository.createScheduleWithAvailabilities(
userId,
schedule,
availabilities
);
if (schedule.isDefault) {
await this.usersRepository.setDefaultSchedule(userId, createdSchedule.id);
}
return this.outputSchedulesService.getResponseSchedule(createdSchedule);
return createdSchedule;
}
async getUserScheduleDefault(userId: number) {
@@ -44,10 +57,7 @@ export class SchedulesService {
if (!user?.defaultScheduleId) return null;
const defaultSchedule = await this.schedulesRepository.getScheduleById(user.defaultScheduleId);
if (!defaultSchedule) return null;
return this.outputSchedulesService.getResponseSchedule(defaultSchedule);
return this.schedulesRepository.getScheduleById(user.defaultScheduleId);
}
async getUserSchedule(userId: number, scheduleId: number) {
@@ -59,45 +69,38 @@ export class SchedulesService {
this.checkUserOwnsSchedule(userId, existingSchedule);
return this.outputSchedulesService.getResponseSchedule(existingSchedule);
return existingSchedule;
}
async getUserSchedules(userId: number) {
const schedules = await this.schedulesRepository.getSchedulesByUserId(userId);
return Promise.all(
schedules.map(async (schedule) => {
return this.outputSchedulesService.getResponseSchedule(schedule);
})
);
return this.schedulesRepository.getSchedulesByUserId(userId);
}
async updateUserSchedule(userId: number, scheduleId: number, bodySchedule: UpdateScheduleInput) {
async updateUserSchedule(user: UserWithProfile, scheduleId: number, bodySchedule: UpdateScheduleInput) {
const existingSchedule = await this.schedulesRepository.getScheduleById(scheduleId);
if (!existingSchedule) {
throw new NotFoundException(`Schedule with ID=${scheduleId} does not exist.`);
}
this.checkUserOwnsSchedule(userId, existingSchedule);
this.checkUserOwnsSchedule(user.id, existingSchedule);
const availability = bodySchedule.availability
? this.inputSchedulesService.transformInputScheduleAvailability(bodySchedule.availability)
: undefined;
const overrides = bodySchedule.overrides
? this.inputSchedulesService.transformInputOverrides(bodySchedule.overrides)
: undefined;
const schedule = await this.getUserSchedule(user.id, Number(scheduleId));
const scheduleFormatted = await this.formatScheduleForAtom(user, schedule);
if (bodySchedule.isDefault) {
await this.usersRepository.setDefaultSchedule(userId, scheduleId);
if (!bodySchedule.schedule) {
// note(Lauris): When updating an availability in cal web app, lets say only its name, also
// the schedule is sent and then passed to the update handler. Notably, availability is passed too
// and they have same shape, so to match shapes I attach "scheduleFormatted.availability" to reflect
// schedule that would be passed by the web app. If we don't, then updating schedule name will erase
// schedule.
bodySchedule.schedule = scheduleFormatted.availability;
}
const updatedSchedule = await this.schedulesRepository.updateSchedule(userId, scheduleId, {
...bodySchedule,
availability,
overrides,
return updateScheduleHandler({
input: { scheduleId: Number(scheduleId), ...bodySchedule },
ctx: { user },
});
return this.outputSchedulesService.getResponseSchedule(updatedSchedule);
}
async deleteUserSchedule(userId: number, scheduleId: number) {
@@ -112,6 +115,44 @@ export class SchedulesService {
return this.schedulesRepository.deleteScheduleById(scheduleId);
}
async formatScheduleForAtom(user: User, schedule: ScheduleWithAvailabilities): Promise<ScheduleOutput> {
const usersSchedulesCount = await this.schedulesRepository.getUserSchedulesCount(user.id);
return this.transformScheduleForAtom(schedule, usersSchedulesCount, user);
}
async formatSchedulesForAtom(
user: User,
schedules: ScheduleWithAvailabilities[]
): Promise<ScheduleOutput[]> {
const usersSchedulesCount = await this.schedulesRepository.getUserSchedulesCount(user.id);
return Promise.all(
schedules.map((schedule) => this.transformScheduleForAtom(schedule, usersSchedulesCount, user))
);
}
async transformScheduleForAtom(
schedule: ScheduleWithAvailabilities,
userSchedulesCount: number,
user: Pick<User, "id" | "defaultScheduleId" | "timeZone">
): Promise<ScheduleOutput> {
const timeZone = schedule.timeZone || user.timeZone;
const defaultSchedule = await this.getUserScheduleDefault(user.id);
return {
id: schedule.id,
name: schedule.name,
isManaged: schedule.userId !== user.id,
workingHours: transformWorkingHoursForClient(schedule),
schedule: schedule.availability,
availability: transformAvailabilityForClient(schedule),
timeZone,
dateOverrides: transformDateOverridesForClient(schedule, timeZone),
isDefault: defaultSchedule?.id === schedule.id,
isLastSchedule: userSchedulesCount <= 1,
readOnly: schedule.userId !== user.id,
};
}
checkUserOwnsSchedule(userId: number, schedule: Pick<Schedule, "id" | "userId">) {
if (userId !== schedule.userId) {
throw new ForbiddenException(`User with ID=${userId} does not own schedule with ID=${schedule.id}`);
@@ -0,0 +1,10 @@
import { AvailabilitiesService } from "@/modules/availabilities/availabilities.service";
import { PrismaModule } from "@/modules/prisma/prisma.module";
import { Module } from "@nestjs/common";
@Module({
imports: [PrismaModule],
providers: [AvailabilitiesService],
exports: [AvailabilitiesService],
})
export class AvailabilitiesModule {}
@@ -0,0 +1,16 @@
import { CreateAvailabilityInput } from "@/modules/availabilities/inputs/create-availability.input";
import { Injectable } from "@nestjs/common";
@Injectable()
export class AvailabilitiesService {
getDefaultAvailabilityInput(): CreateAvailabilityInput {
const startTime = new Date(new Date().setUTCHours(9, 0, 0, 0));
const endTime = new Date(new Date().setUTCHours(17, 0, 0, 0));
return {
days: [1, 2, 3, 4, 5],
startTime,
endTime,
};
}
}
@@ -0,0 +1,48 @@
import { BadRequestException } from "@nestjs/common";
import { ApiProperty } from "@nestjs/swagger";
import { Transform, TransformFnParams } from "class-transformer";
import { IsArray, IsDate, IsNumber } from "class-validator";
export class CreateAvailabilityInput {
@IsArray()
@IsNumber({}, { each: true })
@ApiProperty({ example: [1, 2] })
days!: number[];
@IsDate()
@Transform(({ value, key }: TransformFnParams) => transformStringToDate(value, key))
startTime!: Date;
@IsDate()
@Transform(({ value, key }: TransformFnParams) => transformStringToDate(value, key))
endTime!: Date;
}
function transformStringToDate(value: string, key: string): Date {
// note(Lauris): incoming value is ISO8061 e.g. 2025-0412T13:17:56.324Z
const dateTimeParts = value.split("T");
const timePart = dateTimeParts[1].split(".")[0]; // Removes milliseconds
const parts = timePart.split(":");
if (parts.length !== 3) {
throw new BadRequestException(
`Invalid time format. Expected format(ISO8061): 2025-0412T13:17:56.324Z. Received: ${value}`
);
}
const [hours, minutes, seconds] = parts.map(Number);
if (hours < 0 || hours > 23) {
throw new BadRequestException(`Invalid ${key} hours. Expected value between 0 and 23`);
}
if (minutes < 0 || minutes > 59) {
throw new BadRequestException(`Invalid ${key} minutes. Expected value between 0 and 59`);
}
if (seconds < 0 || seconds > 59) {
throw new BadRequestException(`Invalid ${key} seconds. Expected value between 0 and 59`);
}
return new Date(new Date().setUTCHours(hours, minutes, seconds, 0));
}
@@ -21,6 +21,7 @@ import {
HttpStatus,
Param,
Patch,
BadRequestException,
Delete,
Query,
NotFoundException,
@@ -173,14 +173,6 @@ export class UsersRepository {
},
});
}
async getUserScheduleDefaultId(userId: number) {
const user = await this.findById(userId);
if (!user?.defaultScheduleId) return null;
return user?.defaultScheduleId;
}
}
function capitalizeTimezone(timezone: string) {
+277 -151
View File
@@ -2883,26 +2883,26 @@
"data"
]
},
"ScheduleAvailabilityInput": {
"CreateAvailabilityInput": {
"type": "object",
"properties": {
"days": {
"example": [
"Monday",
"Tuesday"
1,
2
],
"type": "array",
"items": {
"type": "string"
"type": "number"
}
},
"startTime": {
"type": "string",
"example": "09:00"
"format": "date-time",
"type": "string"
},
"endTime": {
"type": "string",
"example": "10:00"
"format": "date-time",
"type": "string"
}
},
"required": [
@@ -2911,71 +2911,23 @@
"endTime"
]
},
"ScheduleOverrideInput": {
"type": "object",
"properties": {
"date": {
"type": "string",
"example": "2024-05-20"
},
"startTime": {
"type": "string",
"example": "12:00"
},
"endTime": {
"type": "string",
"example": "13:00"
}
},
"required": [
"date",
"startTime",
"endTime"
]
},
"CreateScheduleInput": {
"type": "object",
"properties": {
"name": {
"type": "string",
"example": "One-on-one coaching"
"type": "string"
},
"timeZone": {
"type": "string",
"example": "Europe/Rome"
"type": "string"
},
"availability": {
"example": [
{
"days": [
"Monday",
"Tuesday"
],
"startTime": "09:00",
"endTime": "10:00"
}
],
"availabilities": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ScheduleAvailabilityInput"
"$ref": "#/components/schemas/CreateAvailabilityInput"
}
},
"isDefault": {
"type": "boolean",
"example": true
},
"overrides": {
"example": [
{
"date": "2024-05-20",
"startTime": "12:00",
"endTime": "14:00"
}
],
"type": "array",
"items": {
"$ref": "#/components/schemas/ScheduleOverrideInput"
}
"type": "boolean"
}
},
"required": [
@@ -2984,67 +2936,163 @@
"isDefault"
]
},
"ScheduleOutput": {
"WorkingHours": {
"type": "object",
"properties": {
"days": {
"type": "array",
"items": {
"type": "number"
}
},
"startTime": {
"type": "number"
},
"endTime": {
"type": "number"
},
"userId": {
"type": "number",
"nullable": true
}
},
"required": [
"days",
"startTime",
"endTime"
]
},
"AvailabilityModel": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"userId": {
"type": "number",
"example": 254
"nullable": true
},
"ownerId": {
"eventTypeId": {
"type": "number",
"example": 478
"nullable": true
},
"name": {
"type": "string",
"example": "One-on-one coaching"
},
"timeZone": {
"type": "string",
"example": "Europe/Rome"
},
"availability": {
"example": [
{
"days": [
"Monday",
"Tuesday"
],
"startTime": "09:00",
"endTime": "10:00"
}
],
"days": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ScheduleAvailabilityInput"
"type": "number"
}
},
"isDefault": {
"type": "boolean",
"example": true
"startTime": {
"format": "date-time",
"type": "string"
},
"overrides": {
"example": [
{
"date": "2024-05-20",
"startTime": "12:00",
"endTime": "13:00"
"endTime": {
"format": "date-time",
"type": "string"
},
"date": {
"format": "date-time",
"type": "string",
"nullable": true
},
"scheduleId": {
"type": "number",
"nullable": true
}
},
"required": [
"id",
"days",
"startTime",
"endTime"
]
},
"TimeRange": {
"type": "object",
"properties": {
"userId": {
"type": "number",
"nullable": true
},
"start": {
"format": "date-time",
"type": "string"
},
"end": {
"format": "date-time",
"type": "string"
}
},
"required": [
"start",
"end"
]
},
"ScheduleOutput": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
},
"isManaged": {
"type": "boolean"
},
"workingHours": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WorkingHours"
}
},
"schedule": {
"type": "array",
"items": {
"$ref": "#/components/schemas/AvailabilityModel"
}
},
"availability": {
"type": "array",
"items": {
"required": true,
"type": "array",
"items": {
"$ref": "#/components/schemas/TimeRange"
}
],
}
},
"timeZone": {
"type": "string"
},
"dateOverrides": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ScheduleOverrideInput"
"type": "object"
}
},
"isDefault": {
"type": "boolean"
},
"isLastSchedule": {
"type": "boolean"
},
"readOnly": {
"type": "boolean"
}
},
"required": [
"id",
"ownerId",
"name",
"timeZone",
"isManaged",
"workingHours",
"schedule",
"availability",
"timeZone",
"dateOverrides",
"isDefault",
"overrides"
"isLastSchedule",
"readOnly"
]
},
"CreateScheduleOutput": {
@@ -3079,7 +3127,12 @@
]
},
"data": {
"$ref": "#/components/schemas/ScheduleOutput"
"nullable": true,
"allOf": [
{
"$ref": "#/components/schemas/ScheduleOutput"
}
]
}
},
"required": [
@@ -3099,15 +3152,7 @@
]
},
"data": {
"nullable": true,
"allOf": [
{
"$ref": "#/components/schemas/ScheduleOutput"
}
]
},
"error": {
"type": "object"
"$ref": "#/components/schemas/ScheduleOutput"
}
},
"required": [
@@ -3127,13 +3172,7 @@
]
},
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ScheduleOutput"
}
},
"error": {
"type": "object"
"$ref": "#/components/schemas/ScheduleOutput"
}
},
"required": [
@@ -3144,48 +3183,138 @@
"UpdateScheduleInput": {
"type": "object",
"properties": {
"timeZone": {
"type": "string"
},
"name": {
"type": "string"
},
"isDefault": {
"type": "boolean"
},
"schedule": {
"example": [
[],
[
{
"start": "2022-01-01T00:00:00.000Z",
"end": "2022-01-02T00:00:00.000Z"
}
],
[],
[],
[],
[],
[]
],
"items": {
"type": "array"
},
"type": "array"
},
"dateOverrides": {
"example": [
[],
[
{
"start": "2022-01-01T00:00:00.000Z",
"end": "2022-01-02T00:00:00.000Z"
}
],
[],
[],
[],
[],
[]
],
"items": {
"type": "array"
},
"type": "array"
}
},
"required": [
"timeZone",
"name",
"isDefault",
"schedule"
]
},
"EventTypeModel": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"eventName": {
"type": "string",
"example": "One-on-one coaching"
"nullable": true
}
},
"required": [
"id"
]
},
"ScheduleModel": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"userId": {
"type": "number"
},
"name": {
"type": "string"
},
"timeZone": {
"type": "string",
"example": "Europe/Rome"
"nullable": true
},
"eventType": {
"type": "array",
"items": {
"$ref": "#/components/schemas/EventTypeModel"
}
},
"availability": {
"example": [
{
"days": [
"Monday",
"Tuesday"
],
"startTime": "09:00",
"endTime": "10:00"
}
],
"type": "array",
"items": {
"$ref": "#/components/schemas/ScheduleAvailabilityInput"
}
},
"isDefault": {
"type": "boolean",
"example": true
},
"overrides": {
"example": [
{
"date": "2024-05-20",
"startTime": "12:00",
"endTime": "14:00"
}
],
"type": "array",
"items": {
"$ref": "#/components/schemas/ScheduleOverrideInput"
"$ref": "#/components/schemas/AvailabilityModel"
}
}
}
},
"required": [
"id",
"userId",
"name"
]
},
"UpdatedScheduleOutput": {
"type": "object",
"properties": {
"schedule": {
"$ref": "#/components/schemas/ScheduleModel"
},
"isDefault": {
"type": "boolean"
},
"timeZone": {
"type": "string"
},
"prevDefaultId": {
"type": "number",
"nullable": true
},
"currentDefaultId": {
"type": "number",
"nullable": true
}
},
"required": [
"schedule",
"isDefault"
]
},
"UpdateScheduleOutput": {
"type": "object",
@@ -3199,10 +3328,7 @@
]
},
"data": {
"$ref": "#/components/schemas/ScheduleOutput"
},
"error": {
"type": "object"
"$ref": "#/components/schemas/UpdatedScheduleOutput"
}
},
"required": [