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

Merged
merged 49 commits into from
Feb 13, 2025
Merged

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 13, 2025 2:10pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Feb 13, 2025 2:10pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Feb 13, 2025 2:10pm

Copy link

socket-security bot commented Feb 11, 2025

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

import { NO_AUTH_PROVIDED_MESSAGE } from "@/modules/auth/strategies/api-auth/api-auth.strategy";

export class OptionalApiAuthGuard extends ApiAuthGuard {
handleRequest(error: Error, user: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is the user typed as any here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

defining UserWithProfile gave TS error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i could try putting unknown

Comment on lines +48 to +77
for (const date in availableSlots.slots) {
slots[date] = availableSlots.slots[date].map((slot) => {
if (!timeZone) {
if (!eventType?.seatsPerTimeSlot) {
return this.getAvailableTimeSlot(slot.time);
}
return this.getAvailableTimeSlotSeated(
slot.time,
slot.attendees || 0,
eventType.seatsPerTimeSlot || 0,
slot.bookingUid
);
}
const slotTimezoneAdjusted = DateTime.fromISO(slot.time, { zone: "utc" }).setZone(timeZone).toISO();
if (!slotTimezoneAdjusted) {
throw new BadRequestException(
`Could not adjust timezone for slot ${slot.time} with timezone ${timeZone}`
);
}
if (!eventType?.seatsPerTimeSlot) {
return this.getAvailableTimeSlot(slotTimezoneAdjusted);
}
return this.getAvailableTimeSlotSeated(
slotTimezoneAdjusted,
slot.attendees || 0,
eventType.seatsPerTimeSlot || 0,
slot.bookingUid
);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be refactored for clarity, something like that

const adjustTimeForTimeZone = (time, timeZone) =>{
  if (!timeZone) return time;

  const adjustedTime = DateTime.fromISO(time, { zone: "utc" }).setZone(timeZone).toISO();
  if (!adjustedTime) {
    throw new BadRequestException(
      `Could not adjust timezone for slot ${time} with timezone ${timeZone}`
    );
  }
  return adjustedTime;
}

const getAvailableSlot = (time, slot, eventType) => {
  if (!eventType?.seatsPerTimeSlot) {
    return this.getAvailableTimeSlot(time);
  }
  return this.getAvailableTimeSlotSeated(
    time,
    slot.attendees || 0,
    eventType.seatsPerTimeSlot || 0,
    slot.bookingUid
  );
}


for (const date in availableSlots.slots) {
  slots[date] = availableSlots.slots[date].map((slot) => {
    const adjustedTime = adjustTimeForTimeZone(slot.time, timeZone);
    return getAvailableSlot(adjustedTime, slot, eventType);
  });
}

Comment on lines +113 to +167
const slots = Object.entries(availableSlots.slots).reduce<
Record<string, (RangeSlot_2024_09_04 | SeatedRangeSlot_2024_09_04)[]>
>((acc, [date, slots]) => {
acc[date] = slots.map((slot) => {
if (timeZone) {
const start = DateTime.fromISO(slot.time, { zone: "utc" }).setZone(timeZone).toISO();
if (!start) {
throw new BadRequestException(
`Could not adjust timezone for slot ${slot.time} with timezone ${timeZone}`
);
}

const end = DateTime.fromISO(slot.time, { zone: "utc" })
.plus({ minutes: slotDuration })
.setZone(timeZone)
.toISO();

if (!end) {
throw new BadRequestException(
`Could not adjust timezone for slot end time ${slot.time} with timezone ${timeZone}`
);
}

if (!eventType?.seatsPerTimeSlot) {
return this.getAvailableRangeSlot(start, end);
}
return this.getAvailableRangeSlotSeated(
start,
end,
slot.attendees || 0,
eventType.seatsPerTimeSlot ?? undefined,
slot.bookingUid
);
} else {
const start = DateTime.fromISO(slot.time, { zone: "utc" }).toISO();
const end = DateTime.fromISO(slot.time, { zone: "utc" }).plus({ minutes: slotDuration }).toISO();

if (!start || !end) {
throw new BadRequestException(`Could not create UTC time for slot ${slot.time}`);
}

if (!eventType?.seatsPerTimeSlot) {
return this.getAvailableRangeSlot(start, end);
}
return this.getAvailableRangeSlotSeated(
start,
end,
slot.attendees || 0,
eventType.seatsPerTimeSlot ?? undefined,
slot.bookingUid
);
}
});
return acc;
}, {});
Copy link
Contributor

@ThyMinimalDev ThyMinimalDev Feb 13, 2025

Choose a reason for hiding this comment

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

same thing, can be refactored for clarity , something like this

const slots = Object.entries(availableSlots.slots).reduce<
  Record<string, (RangeSlot_2024_09_04 | SeatedRangeSlot_2024_09_04)[]>
>((acc, [date, slots]) => {
  acc[date] = slots.map((slot) => {
    const { start, end } = getSlotTimes(slot.time, timeZone, slotDuration);
    return getAvailableSlot(start, end, slot, eventType);
  });
  return acc;
}, {});


const getSlotTimes = (time, timeZone, slotDuration) => {
  const start = DateTime.fromISO(time, { zone: "utc" });
 // not sure here if putting fromISO again is useful or not
  const end = start.plus({ minutes: slotDuration });

  if (timeZone) {
    const startAdjusted = start.setZone(timeZone).toISO();
    const endAdjusted = end.setZone(timeZone).toISO();

    if (!startAdjusted || !endAdjusted) {
      throw new BadRequestException(
        `Could not adjust timezone for slot ${time} with timezone ${timeZone}`
      );
    }

    return { start: startAdjusted, end: endAdjusted };
  }

  const startISO = start.toISO();
  const endISO = end.toISO();

  if (!startISO || !endISO) {
    throw new BadRequestException(`Could not create UTC time for slot ${time}`);
  }

  return { start: startISO, end: endISO };
}


const getAvailableSlot = (start, end, slot, eventType) =>{
  if (!eventType?.seatsPerTimeSlot) {
    return this.getAvailableRangeSlot(start, end);
  }
  return this.getAvailableRangeSlotSeated(
    start,
    end,
    slot.attendees || 0,
    eventType.seatsPerTimeSlot ?? undefined,
    slot.bookingUid
  );
}

Copy link

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@bcoe/[email protected] None 0 277 kB bcoe
npm/@istanbuljs/[email protected] None 0 17.2 kB coreyfarrell
npm/@nodelib/[email protected] filesystem 0 22.2 kB mrmlnc
npm/@nodelib/[email protected] filesystem 0 11.8 kB mrmlnc
npm/@pkgjs/[email protected] None 0 74.2 kB oss-bot
npm/@types/[email protected] None 0 8.23 kB types
npm/@types/[email protected] None 0 7.42 kB types
npm/[email protected] None 0 24.4 kB rreverser
npm/[email protected] None 0 6.69 kB sindresorhus
npm/[email protected] eval 0 929 kB esp
npm/[email protected] None +1 135 kB sindresorhus
npm/[email protected] None 0 3.17 kB sindresorhus
npm/[email protected] None 0 3.4 kB kevva
npm/[email protected] None 0 27.4 kB alexindigo
npm/[email protected] None 0 6.94 kB juliangruber
npm/[email protected] 🔁 npm/[email protected] None 0 9.62 kB feross
npm/[email protected] None 0 49.2 kB doowb
npm/[email protected] None 0 14.7 kB ljharb
npm/[email protected] None 0 6.33 kB sindresorhus
npm/[email protected] filesystem 0 5.75 kB isaacs
npm/[email protected] None 0 5.51 kB sindresorhus
npm/[email protected] None 0 4.37 kB sindresorhus
npm/[email protected] None 0 11.1 kB pvorb
npm/[email protected] None 0 6.69 kB dfcreative
npm/[email protected] None 0 11.5 kB alexindigo
npm/[email protected] None 0 4.86 kB substack
npm/[email protected] None 0 6.49 kB mathias
npm/[email protected] None 0 30.1 kB tehshrike
npm/[email protected] None 0 3.77 kB tmpvar
npm/[email protected] None 0 8.02 kB apechimp
npm/[email protected] None 0 106 kB eslint
npm/[email protected] None 0 13.6 kB komagata
npm/[email protected] environment 0 197 kB jonschlinkert
npm/[email protected] None 0 10.2 kB sindresorhus
npm/[email protected] None 0 12.3 kB achingbrain
npm/[email protected] None 0 9.04 kB qix
npm/[email protected] None +1 60.5 kB ljharb
npm/[email protected] filesystem 0 11.4 kB lukeed
npm/[email protected] None 0 3.79 kB sindresorhus
npm/[email protected] None +1 383 kB mysticatea
npm/[email protected] None 0 314 kB ariya
npm/[email protected] None 0 13.5 kB michaelficarra
npm/[email protected] None 0 50.6 kB michaelficarra
npm/[email protected] None 0 82.8 kB goto-bus-stop
npm/[email protected] None 0 37.3 kB sssayegh
npm/[email protected] None 0 17 kB esp
npm/[email protected] None 0 9.44 kB hiddentao
npm/[email protected] filesystem 0 25.6 kB royriojas
npm/[email protected] None 0 16.4 kB jonschlinkert
npm/[email protected] filesystem 0 30 kB royriojas
npm/[email protected] environment, filesystem 0 13.4 kB isaacs
npm/[email protected] 🔁 npm/[email protected] None 0 156 kB pipobscure
npm/[email protected] None 0 25.2 kB ljharb
npm/[email protected] filesystem 0 6.01 kB coreyfarrell
npm/[email protected] None 0 12.2 kB sindresorhus
npm/[email protected] None 0 10.3 kB ljharb
npm/[email protected] None 0 4.42 kB sindresorhus
npm/[email protected] None 0 10.9 kB ljharb
npm/[email protected] None 0 2.77 kB ljharb
npm/[email protected] None 0 25.8 kB nlf
npm/[email protected] None 0 13.1 kB webreflection
npm/[email protected] None 0 35.9 kB kornel
npm/[email protected] network 0 26.2 kB tootallnate
npm/[email protected] None 0 44.3 kB ehmicky
npm/[email protected] None 0 336 kB ashtuchkin
npm/[email protected] None 0 6.8 kB feross
npm/[email protected] None 0 11.9 kB jensyt
npm/[email protected] None 0 4.4 kB sindresorhus
npm/[email protected] None 0 3.76 kB isaacs
npm/[email protected] None 0 3.96 kB isaacs
npm/[email protected] None 0 15.5 kB ljharb
npm/[email protected] None 0 13.6 kB indutny
npm/[email protected] None 0 4.05 kB qix
npm/[email protected] None 0 6.22 kB jonschlinkert
npm/[email protected] None 0 4.99 kB sindresorhus
npm/[email protected] None 0 4.62 kB sindresorhus
npm/[email protected] None 0 2.94 kB watson
npm/[email protected] None 0 9.62 kB jonschlinkert
npm/[email protected] None 0 4.12 kB sindresorhus
npm/[email protected] None 0 30.1 kB ljharb
npm/[email protected] None 0 19.1 kB ljharb
npm/[email protected] None 0 22 kB ljharb
npm/[email protected] None 0 3.54 kB sindresorhus
npm/[email protected] environment, filesystem 0 11 kB isaacs
npm/[email protected] filesystem 0 37.5 kB coreyfarrell
npm/[email protected] environment 0 253 kB isaacs
npm/[email protected] None 0 15.1 kB lydell
npm/[email protected] None 0 405 kB vitaly
npm/[email protected] None 0 6.7 kB zkat
npm/[email protected] None 0 10.4 kB isaacs
npm/[email protected] None 0 14.2 kB samn
npm/[email protected] None 0 24.9 kB gkz
npm/[email protected] None 0 54.1 kB jdalton
npm/[email protected] None 0 1.41 MB bnjmnt4n
npm/[email protected] None 0 4.58 kB sindresorhus
npm/[email protected] None 0 4.31 kB stevemao
npm/[email protected] None 0 2.97 kB thejameskyle
npm/[email protected] None 0 7 kB isaacs
npm/[email protected] None 0 124 kB isaacs
npm/[email protected] None 0 48.1 kB isaacs
npm/[email protected] None 0 6.84 kB styfle
npm/[email protected] None 0 5.65 kB megawac
npm/[email protected] None 0 27.4 kB dougwilson
npm/[email protected] None 0 9.22 kB jonschlinkert
npm/[email protected] environment 0 8.13 kB sindresorhus
npm/[email protected] None 0 26.5 kB ljharb
npm/[email protected] None 0 4.05 kB isaacs
npm/[email protected] None 0 50.2 kB gkz
npm/[email protected] None 0 23.2 kB sindresorhus
npm/[email protected] None 0 7.75 kB sindresorhus
npm/[email protected] None 0 4.37 kB sindresorhus
npm/[email protected] None 0 3.92 kB sindresorhus
npm/[email protected] None 0 5.41 kB sindresorhus
npm/[email protected] None 0 3.62 kB sindresorhus
npm/[email protected] None 0 4.55 kB sindresorhus
npm/[email protected] None 0 4.51 kB jbgutierrez
npm/[email protected] filesystem 0 529 kB isaacs
npm/[email protected] filesystem 0 5.41 kB sindresorhus
npm/[email protected] None 0 36.7 kB gkz
npm/[email protected] None 0 3.17 kB cwmma
npm/[email protected] None 0 15.6 kB achingbrain
npm/[email protected] None 0 433 kB lupomontero
npm/[email protected] None 0 32.4 kB mathias
npm/[email protected] None 0 8.37 kB feross
npm/[email protected] environment 0 122 kB matteo.collina
npm/[email protected] None 0 3.6 kB sindresorhus
npm/[email protected] filesystem 0 12.1 kB troygoode
npm/[email protected] unsafe 0 3.42 kB floatdrop
npm/[email protected] None 0 3.93 kB bcoe
npm/[email protected] filesystem, unsafe 0 4.64 kB sindresorhus
npm/[email protected] None 0 32.2 kB tim-kos
npm/[email protected] None 0 9.44 kB matteo.collina
npm/[email protected] None 0 6.56 kB feross
npm/[email protected] None 0 42.3 kB chalker
npm/[email protected] None 0 61.6 kB isaacs
npm/[email protected] None 0 4.22 kB bcoe
npm/[email protected] None 0 2.56 kB kevva
npm/[email protected] None 0 2.83 kB sindresorhus
npm/[email protected] None 0 14.6 kB ljharb
npm/[email protected] None 0 6.79 kB terkelg
npm/[email protected] None 0 3.51 kB sindresorhus
npm/[email protected] None 0 138 kB joshglazebrook
npm/[email protected] network 0 152 kB joshglazebrook
npm/[email protected] None 0 22.4 kB kemitchell
npm/[email protected] None 0 2.66 kB kemitchell
npm/[email protected] None 0 11.8 kB kemitchell
npm/[email protected] None 0 34.8 kB alexei
npm/[email protected] None 0 14.4 kB matteo.collina
npm/[email protected] None 0 0 B
npm/[email protected] None 0 3 kB sindresorhus
npm/[email protected] None 0 3.05 kB sindresorhus
npm/[email protected] None 0 3.31 kB sindresorhus
npm/[email protected] None 0 11 kB substack
npm/[email protected] None 0 22.9 kB jonschlinkert
npm/[email protected] None 0 111 kB sindresorhus
npm/[email protected] None 0 5.48 kB tootallnate
npm/[email protected] None 0 16.6 kB kemitchell
npm/[email protected] None 0 14.2 kB timoxley
npm/[email protected] None 0 15 kB ljharb
npm/[email protected] None 0 10.6 kB jonschlinkert
npm/[email protected] None 0 0 B
npm/[email protected] None 0 2.96 kB zkat
npm/[email protected] None 0 6.46 kB raynos
npm/[email protected] filesystem 0 23.4 kB oss-bot
npm/[email protected] environment 0 448 kB eemeli

🚮 Removed packages: npm/[email protected], npm/[email protected]

View full report↗︎

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