refactor: extract slots from libraries barrel file (#19895)

* refactor: extract slots fn from libraries barrel file

* bump platform libs

---------

Co-authored-by: Morgan Vernay <morgan@cal.com>
This commit is contained in:
Rajiv SahalandMorgan Vernay authored and GitHub committed 2025-03-10 10:33:29 +00:00
1 parent 1848cd55b1
commit 277ce1c244
11 files changed
+45 -15

No files matched your search

+1 -1
View File
@@ -32,7 +32,7 @@
"@axiomhq/winston": "^1.2.0",
"@calcom/platform-constants": "*",
"@calcom/platform-enums": "*",
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.127",
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.140",
"@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2",
"@calcom/platform-types": "*",
"@calcom/platform-utils": "*",
@@ -1,4 +1,5 @@
import { SlotsOutputService_2024_04_15 } from "@/modules/slots/slots-2024-04-15/services/slots-output.service";
import type { RangeSlots, TimeSlots } from "@/modules/slots/slots-2024-04-15/services/slots-output.service";
import { SlotsService_2024_04_15 } from "@/modules/slots/slots-2024-04-15/services/slots.service";
import { Query, Body, Controller, Get, Delete, Post, Req, Res } from "@nestjs/common";
import { ApiExcludeController as DocsExcludeController } from "@nestjs/swagger";
@@ -12,8 +13,7 @@ import {
VERSION_2024_06_11,
VERSION_2024_08_13,
} from "@calcom/platform-constants";
import { getAvailableSlots } from "@calcom/platform-libraries";
import type { AvailableSlotsType } from "@calcom/platform-libraries";
import { getAvailableSlots } from "@calcom/platform-libraries/slots";
import { RemoveSelectedSlotInput_2024_04_15, ReserveSlotInput_2024_04_15 } from "@calcom/platform-types";
import { ApiResponse, GetAvailableSlotsInput_2024_04_15 } from "@calcom/platform-types";
@@ -156,7 +156,7 @@ export class SlotsController_2024_04_15 {
async getAvailableSlots(
@Query() query: GetAvailableSlotsInput_2024_04_15,
@Req() req: ExpressRequest
): Promise<ApiResponse<AvailableSlotsType>> {
): Promise<ApiResponse<{ slots: TimeSlots["slots"] | RangeSlots["slots"] }>> {
const isTeamEvent = await this.slotsService.checkIfIsTeamEvent(query.eventTypeId);
const availableSlots = await getAvailableSlots({
input: {
@@ -7,7 +7,7 @@ import { SlotFormat } from "@calcom/platform-enums";
export type TimeSlots = {
slots: Record<string, { time: string; attendees?: number; bookingUid?: string }[]>;
};
type RangeSlots = {
export type RangeSlots = {
slots: Record<string, { startTime: string; endTime: string; attendees?: number; bookingUid?: string }[]>;
};
@@ -2,7 +2,7 @@ import { EventTypesRepository_2024_06_14 } from "@/ee/event-types/event-types_20
import { OrganizationsRepository } from "@/modules/organizations/index/organizations.repository";
import { OrganizationsUsersRepository } from "@/modules/organizations/users/index/organizations-users.repository";
import { UsersRepository } from "@/modules/users/users.repository";
import { Injectable, NotFoundException } from "@nestjs/common";
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
import { DateTime } from "luxon";
import { dynamicEvent } from "@calcom/platform-libraries";
@@ -88,6 +88,11 @@ export class SlotsInputService_2024_09_04 {
dateTime = dateTime.set({ hour: 23, minute: 59, second: 59 });
}
return dateTime.toISO();
const ISOEndTime = dateTime.toISO();
if (ISOEndTime === null) {
throw new BadRequestException("Invalid end date");
}
return ISOEndTime;
}
}
@@ -17,7 +17,7 @@ import {
import { DateTime } from "luxon";
import { z } from "zod";
import { getAvailableSlots } from "@calcom/platform-libraries";
import { getAvailableSlots } from "@calcom/platform-libraries/slots";
import { GetSlotsInput_2024_09_04, ReserveSlotInput_2024_09_04 } from "@calcom/platform-types";
import { EventType } from "@calcom/prisma/client";
+2 -1
View File
@@ -18,7 +18,8 @@
"@calcom/platform-constants": ["../../../packages/platform/constants/index.ts"],
"@calcom/platform-types": ["../../../packages/platform/types/index.ts"],
"@calcom/platform-utils": ["../../../packages/platform/utils/index.ts"],
"@calcom/platform-enums": ["../../../packages/platform/enums/index.ts"]
"@calcom/platform-enums": ["../../../packages/platform/enums/index.ts"],
"@calcom/platform-libraries/slots": ["../../../packages/platform/libraries/slots.ts"]
},
"incremental": true,
"skipLibCheck": true,
+1 -1
View File
@@ -1,6 +1,6 @@
import { Prisma } from "@prisma/client";
import "server-only";
//import "server-only";
import { getLocationGroupedOptions } from "@calcom/app-store/server";
import { getEventTypeAppData } from "@calcom/app-store/utils";
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
+2 -4
View File
@@ -55,7 +55,6 @@ import { paymentDataSelect } from "@calcom/prisma/selects/payment";
import type { TeamQuery } from "@calcom/trpc/server/routers/loggedInViewer/integrations.handler";
import { updateHandler as updateScheduleHandler } from "@calcom/trpc/server/routers/viewer/availability/schedule/update.handler";
import addDelegationCredential from "@calcom/trpc/server/routers/viewer/delegationCredential/add.handler";
import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
import {
createNewUsersConnectToOrgIfExists,
sendSignupToOrganizationEmail,
@@ -116,8 +115,6 @@ export { handleInstantMeeting };
export { handleMarkNoShow };
export { handleCreatePhoneCall };
export { getAvailableSlots };
export type AvailableSlotsType = Awaited<ReturnType<typeof getAvailableSlots>>;
export { handleNewRecurringBooking } from "@calcom/features/bookings/lib/handleNewRecurringBooking";
export { getConnectedDestinationCalendarsAndEnsureDefaultsInDb } from "@calcom/lib/getConnectedDestinationCalendars";
@@ -207,7 +204,8 @@ export type {
InternalLocation,
} from "@calcom/lib/event-types/transformers";
export { parseBookingLimit, parseEventTypeColor } from "@calcom/lib";
export { parseEventTypeColor } from "@calcom/lib";
export { parseBookingLimit } from "@calcom/lib/intervalLimits/isBookingLimits";
export { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
export { dynamicEvent } from "@calcom/lib/defaultEvents";
+19
View File
@@ -27,5 +27,24 @@
"vite": "^5.0.12",
"vite-plugin-dts": "^3.7.2",
"vite-plugin-environment": "^1.1.3"
},
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"./slots": {
"import": "./dist/slots.js",
"require": "./dist/slots.cjs",
"types": "./dist/slots.d.ts"
}
},
"typesVersions": {
"*": {
"slots": [
"dist/slots.d.ts"
]
}
}
}
+4
View File
@@ -0,0 +1,4 @@
import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
export { getAvailableSlots };
export type AvailableSlotsType = Awaited<ReturnType<typeof getAvailableSlots>>;
+4 -1
View File
@@ -16,7 +16,10 @@ export default defineConfig({
platform: "node",
ssr: true,
lib: {
entry: resolve(__dirname, "./index.ts"),
entry: {
index: resolve(__dirname, "./index.ts"),
slots: resolve(__dirname, "./slots.ts"),
},
name: "calcom-lib",
fileName: "calcom-lib",
},