Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v2 slots new version #18758

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

supalarry
Copy link
Contributor

Linear CAL-5052

Copy link

linear bot commented Jan 20, 2025

@keithwillcode keithwillcode added core area: core, team members only platform Anything related to our platform plan labels Jan 20, 2025
@supalarry supalarry mentioned this pull request Jan 20, 2025
Copy link

vercel bot commented Jan 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cal-com-ui-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 7, 2025 4:09pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Feb 7, 2025 4:09pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Feb 7, 2025 4:09pm

@liferays
Copy link

Hello,

I’d like to emphasize an important point. Alongside the default "reserve slot" behavior, which reserves a slot for 5 minutes, we need the flexibility to define how far into the future a slot can be reserved. For instance, instead of the default 5-minute duration, we should be able to reserve a slot for an extended period—up to 1000 years, if needed—effectively keeping the slot reserved indefinitely until we trigger a "Delete a selected slot" API or complete a booking.

This functionality would be particularly useful when building on top of Cal.com using its platform API, such as when creating predefined classes.

@liferays
Copy link

If possible, it would be great to include the ability to return reserved slots along with their slot ID and datetime. This would be especially beneficial for managing predefined timed classes or events across various platforms.

@supalarry
Copy link
Contributor Author

Hello,

I’d like to emphasize an important point. Alongside the default "reserve slot" behavior, which reserves a slot for 5 minutes, we need the flexibility to define how far into the future a slot can be reserved. For instance, instead of the default 5-minute duration, we should be able to reserve a slot for an extended period—up to 1000 years, if needed—effectively keeping the slot reserved indefinitely until we trigger a "Delete a selected slot" API or complete a booking.

This functionality would be particularly useful when building on top of Cal.com using its platform API, such as when creating predefined classes.

Thanks for the input and it's a great idea! Luckily, this is implemented in this PR. Here is an example POST request made to /v2/slots/reservations with the reservationDuration set to 60 minutes with following request body:

{
    eventTypeId: 10,
    slotStart: "2050-09-05T10:00:00.000Z",
    reservationDuration: 60,
}

@supalarry
Copy link
Contributor Author

If possible, it would be great to include the ability to return reserved slots along with their slot ID and datetime. This would be especially beneficial for managing predefined timed classes or events across various platforms.

The response of reserving a slot can be viewed here: reserve-slot.output.ts

Slots don't have IDs per se, but reservations do, so response contains UID of the reservation and the slotStart telling when slot starts and more.


1. By event type id. Event type id can be of user and team event types. Example '/v2/slots?eventTypeId=10&start=2050-09-05&end=2050-09-06&timeZone=Europe/Rome'

2. By event type slug + username. Example '/v2/slots?eventTypeSlug=intro&username=bob&start=2050-09-05&end=2050-09-06'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should enable providing orgSlug or orgId, there can be conflicts between username + eventslug of org users being the same than username + eventslug of non org ursers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see in the inputs that we allow orgSlug, we can just specify here that for org users they should also pass the org slug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - in commit fix: handle same username in org and non org I make sure that we can scope by organizationSlug query parameter and added tests in slots.controller.e2e-spec.ts - i set up org user with profile username X and event type Y and then normal user with username X and event type Y and then fetch org user availability using profile username + event type slug using organizationSlug param and then normal user without organizationParam. The tests are on line 1859.

Comment on lines 25 to 32
@IsInt()
@IsOptional()
@ApiPropertyOptional({
example: 5,
description:
"For how many minutes the slot should be reserved - for this long time noone else can book this event type at `start` time.",
})
reservationDuration = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a cool feature but we should only enable it when authenticated with apikey / next auth / access token

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too easy to abuse it to block the schedule of someone

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not authenticated force 5

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! But instead of forcing back to 5, return an auth validation error, as sensitive and high-dependency cases can be critical for the (Platform).
If no duration is set, it should function normally without any type of auth, with 5 min as default duration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! In commit fix: allow reservationDuration only for authed requests I implemented that

  1. if no authentification is passed then reservationDuration can't be set
  2. if invalid authentification is passed then 400 bad request error is thrown.

This can be seen in e2e tests slots.controller.e2e-spec.ts

@@ -37,22 +37,6 @@ export class OrganizationsUsersRepository {
});
}

async getOrganizationUserByUsername(orgId: number, username: string) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joeauyeung had added this code but I replaced it with 'getOrganizationUserByUsername' below which does not check 'User.username' like this function did but 'Profile.username'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core area: core, team members only ✨ feature New feature or request platform Anything related to our platform plan ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants