Skip to content

feat: v2 slots new version#18758

Merged
supalarry merged 49 commits intomainfrom
lauris/cal-5052-platform-refactor-v2-slots
Feb 13, 2025
Merged

feat: v2 slots new version#18758
supalarry merged 49 commits intomainfrom
lauris/cal-5052-platform-refactor-v2-slots

Conversation

@supalarry
Copy link
Copy Markdown
Contributor

Linear CAL-5052

@linear
Copy link
Copy Markdown

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
@vercel
Copy link
Copy Markdown

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

@socket-security
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
  );
}

@socket-security
Copy link
Copy Markdown

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

Package New capabilities Transitives Size Publisher
npm/@bcoe/v8-coverage@0.2.3 None 0 277 kB bcoe
npm/@istanbuljs/schema@0.1.3 None 0 17.2 kB coreyfarrell
npm/@nodelib/fs.scandir@2.1.5 filesystem 0 22.2 kB mrmlnc
npm/@nodelib/fs.stat@2.0.5 filesystem 0 11.8 kB mrmlnc
npm/@pkgjs/parseargs@0.11.0 None 0 74.2 kB oss-bot
npm/@types/istanbul-lib-report@3.0.0 None 0 8.23 kB types
npm/@types/istanbul-reports@3.0.1 None 0 7.42 kB types
npm/acorn-jsx@5.3.2 None 0 24.4 kB rreverser
npm/aggregate-error@3.1.0 None 0 6.69 kB sindresorhus
npm/ajv@6.12.6 eval 0 929 kB esp
npm/ansi-escapes@4.3.2 None +1 135 kB sindresorhus
npm/array-union@2.1.0 None 0 3.17 kB sindresorhus
npm/astral-regex@2.0.0 None 0 3.4 kB kevva
npm/asynckit@0.4.0 None 0 27.4 kB alexindigo
npm/balanced-match@1.0.2 None 0 6.94 kB juliangruber
npm/base64-js@1.5.1 🔁 npm/base64-js@0.0.8 None 0 9.62 kB feross
npm/braces@3.0.2 None 0 49.2 kB doowb
npm/call-bind@1.0.2 None 0 14.7 kB ljharb
npm/callsites@3.1.0 None 0 6.33 kB sindresorhus
npm/chownr@2.0.0 filesystem 0 5.75 kB isaacs
npm/clean-stack@2.2.0 None 0 5.51 kB sindresorhus
npm/cli-cursor@3.1.0 None 0 4.37 kB sindresorhus
npm/clone@1.0.4 None 0 11.1 kB pvorb
npm/color-name@1.1.4 None 0 6.69 kB dfcreative
npm/combined-stream@1.0.8 None 0 11.5 kB alexindigo
npm/concat-map@0.0.1 None 0 4.86 kB substack
npm/css.escape@1.5.1 None 0 6.49 kB mathias
npm/deepmerge@4.2.2 None 0 30.1 kB tehshrike
npm/defaults@1.0.3 None 0 3.77 kB tmpvar
npm/delayed-stream@1.0.0 None 0 8.02 kB apechimp
npm/doctrine@3.0.0 None 0 106 kB eslint
npm/eastasianwidth@0.2.0 None 0 13.6 kB komagata
npm/enquirer@2.3.6 environment 0 197 kB jonschlinkert
npm/env-paths@2.2.1 None 0 10.2 kB sindresorhus
npm/err-code@2.0.3 None 0 12.3 kB achingbrain
npm/error-ex@1.3.2 None 0 9.04 kB qix
npm/es-to-primitive@1.2.1 None +1 60.5 kB ljharb
npm/escalade@3.1.1 filesystem 0 11.4 kB lukeed
npm/escape-string-regexp@4.0.0 None 0 3.79 kB sindresorhus
npm/eslint-utils@3.0.0 None +1 383 kB mysticatea
npm/esprima@4.0.1 None 0 314 kB ariya
npm/esrecurse@4.3.0 None 0 13.5 kB michaelficarra
npm/esutils@2.0.3 None 0 50.6 kB michaelficarra
npm/events@3.3.0 None 0 82.8 kB goto-bus-stop
npm/exponential-backoff@3.1.1 None 0 37.3 kB sssayegh
npm/fast-json-stable-stringify@2.1.0 None 0 17 kB esp
npm/fast-levenshtein@2.0.6 None 0 9.44 kB hiddentao
npm/file-entry-cache@6.0.1 filesystem 0 25.6 kB royriojas
npm/fill-range@7.0.1 None 0 16.4 kB jonschlinkert
npm/flat-cache@3.0.4 filesystem 0 30 kB royriojas
npm/fs.realpath@1.0.0 environment, filesystem 0 13.4 kB isaacs
npm/fsevents@2.3.2 🔁 npm/fsevents@2.3.3 None 0 156 kB pipobscure
npm/function-bind@1.1.1 None 0 25.2 kB ljharb
npm/get-package-type@0.1.0 filesystem 0 6.01 kB coreyfarrell
npm/get-stream@6.0.1 None 0 12.2 kB sindresorhus
npm/get-symbol-description@1.0.0 None 0 10.3 kB ljharb
npm/has-flag@4.0.0 None 0 4.42 kB sindresorhus
npm/has-tostringtag@1.0.0 None 0 10.9 kB ljharb
npm/has@1.0.3 None 0 2.77 kB ljharb
npm/hosted-git-info@2.8.9 None 0 25.8 kB nlf
npm/html-escaper@2.0.2 None 0 13.1 kB webreflection
npm/http-cache-semantics@4.1.1 None 0 35.9 kB kornel
npm/https-proxy-agent@5.0.0 network 0 26.2 kB tootallnate
npm/human-signals@2.1.0 None 0 44.3 kB ehmicky
npm/iconv-lite@0.4.24 None 0 336 kB ashtuchkin
npm/ieee754@1.2.1 None 0 6.8 kB feross
npm/imurmurhash@0.1.4 None 0 11.9 kB jensyt
npm/indent-string@4.0.0 None 0 4.4 kB sindresorhus
npm/inflight@1.0.6 None 0 3.76 kB isaacs
npm/inherits@2.0.4 None 0 3.96 kB isaacs
npm/internal-slot@1.0.3 None 0 15.5 kB ljharb
npm/ip@2.0.0 None 0 13.6 kB indutny
npm/is-arrayish@0.2.1 None 0 4.05 kB qix
npm/is-extglob@2.1.1 None 0 6.22 kB jonschlinkert
npm/is-fullwidth-code-point@3.0.0 None 0 4.99 kB sindresorhus
npm/is-interactive@1.0.0 None 0 4.62 kB sindresorhus
npm/is-lambda@1.0.1 None 0 2.94 kB watson
npm/is-number@7.0.0 None 0 9.62 kB jonschlinkert
npm/is-path-inside@3.0.3 None 0 4.12 kB sindresorhus
npm/is-regex@1.1.4 None 0 30.1 kB ljharb
npm/is-string@1.0.7 None 0 19.1 kB ljharb
npm/is-symbol@1.0.4 None 0 22 kB ljharb
npm/is-unicode-supported@0.1.0 None 0 3.54 kB sindresorhus
npm/isexe@2.0.0 environment, filesystem 0 11 kB isaacs
npm/istanbul-lib-report@3.0.0 filesystem 0 37.5 kB coreyfarrell
npm/jackspeak@2.3.6 environment 0 253 kB isaacs
npm/js-tokens@4.0.0 None 0 15.1 kB lydell
npm/js-yaml@4.1.0 None 0 405 kB vitaly
npm/json-parse-better-errors@1.0.2 None 0 6.7 kB zkat
npm/json-parse-even-better-errors@2.3.1 None 0 10.4 kB isaacs
npm/json-stable-stringify-without-jsonify@1.0.1 None 0 14.2 kB samn
npm/levn@0.4.1 None 0 24.9 kB gkz
npm/lodash.merge@4.6.2 None 0 54.1 kB jdalton
npm/lodash@4.17.21 None 0 1.41 MB bnjmnt4n
npm/log-symbols@4.1.0 None 0 4.58 kB sindresorhus
npm/merge-stream@2.0.0 None 0 4.31 kB stevemao
npm/min-indent@1.0.1 None 0 2.97 kB thejameskyle
npm/minipass-pipeline@1.2.4 None 0 7 kB isaacs
npm/minipass-sized@1.0.3 None 0 124 kB isaacs
npm/minipass@3.3.6 None 0 48.1 kB isaacs
npm/ms@2.1.2 None 0 6.84 kB styfle
npm/natural-compare@1.4.0 None 0 5.65 kB megawac
npm/negotiator@0.6.3 None 0 27.4 kB dougwilson
npm/normalize-path@3.0.0 None 0 9.22 kB jonschlinkert
npm/npm-run-path@4.0.1 environment 0 8.13 kB sindresorhus
npm/object-keys@1.1.1 None 0 26.5 kB ljharb
npm/once@1.4.0 None 0 4.05 kB isaacs
npm/optionator@0.9.1 None 0 50.2 kB gkz
npm/ora@5.4.1 None 0 23.2 kB sindresorhus
npm/p-limit@3.1.0 None 0 7.75 kB sindresorhus
npm/p-try@2.2.0 None 0 4.37 kB sindresorhus
npm/parent-module@1.0.1 None 0 3.92 kB sindresorhus
npm/parse-json@5.2.0 None 0 5.41 kB sindresorhus
npm/path-is-absolute@1.0.1 None 0 3.62 kB sindresorhus
npm/path-key@3.1.1 None 0 4.55 kB sindresorhus
npm/path-parse@1.0.7 None 0 4.51 kB jbgutierrez
npm/path-scurry@1.10.1 filesystem 0 529 kB isaacs
npm/path-type@4.0.0 filesystem 0 5.41 kB sindresorhus
npm/prelude-ls@1.2.1 None 0 36.7 kB gkz
npm/process-nextick-args@2.0.1 None 0 3.17 kB cwmma
npm/promise-retry@2.0.1 None 0 15.6 kB achingbrain
npm/psl@1.8.0 None 0 433 kB lupomontero
npm/punycode@2.1.1 None 0 32.4 kB mathias
npm/queue-microtask@1.2.3 None 0 8.37 kB feross
npm/readable-stream@3.6.0 environment 0 122 kB matteo.collina
npm/redent@3.0.0 None 0 3.6 kB sindresorhus
npm/require-directory@2.1.1 filesystem 0 12.1 kB troygoode
npm/require-from-string@2.0.2 unsafe 0 3.42 kB floatdrop
npm/require-main-filename@2.0.0 None 0 3.93 kB bcoe
npm/resolve-from@4.0.0 filesystem, unsafe 0 4.64 kB sindresorhus
npm/retry@0.12.0 None 0 32.2 kB tim-kos
npm/reusify@1.0.4 None 0 9.44 kB matteo.collina
npm/run-parallel@1.2.0 None 0 6.56 kB feross
npm/safer-buffer@2.1.2 None 0 42.3 kB chalker
npm/semver@5.7.1 None 0 61.6 kB isaacs
npm/set-blocking@2.0.0 None 0 4.22 kB bcoe
npm/shebang-command@2.0.0 None 0 2.56 kB kevva
npm/shebang-regex@3.0.0 None 0 2.83 kB sindresorhus
npm/side-channel@1.0.4 None 0 14.6 kB ljharb
npm/sisteransi@1.0.5 None 0 6.79 kB terkelg
npm/slash@3.0.0 None 0 3.51 kB sindresorhus
npm/smart-buffer@4.2.0 None 0 138 kB joshglazebrook
npm/socks@2.7.1 network 0 152 kB joshglazebrook
npm/spdx-correct@3.1.1 None 0 22.4 kB kemitchell
npm/spdx-exceptions@2.3.0 None 0 2.66 kB kemitchell
npm/spdx-expression-parse@3.0.1 None 0 11.8 kB kemitchell
npm/sprintf-js@1.0.3 None 0 34.8 kB alexei
npm/string_decoder@1.3.0 None 0 14.4 kB matteo.collina
npm/strip-ansi-cjs@6.0.1 None 0 0 B
npm/strip-bom@3.0.0 None 0 3 kB sindresorhus
npm/strip-final-newline@2.0.0 None 0 3.05 kB sindresorhus
npm/strip-indent@3.0.0 None 0 3.31 kB sindresorhus
npm/text-table@0.2.0 None 0 11 kB substack
npm/to-regex-range@5.0.1 None 0 22.9 kB jonschlinkert
npm/type-fest@0.20.2 None 0 111 kB sindresorhus
npm/util-deprecate@1.0.2 None 0 5.48 kB tootallnate
npm/validate-npm-package-license@3.0.4 None 0 16.6 kB kemitchell
npm/wcwidth@1.0.1 None 0 14.2 kB timoxley
npm/which-boxed-primitive@1.0.2 None 0 15 kB ljharb
npm/word-wrap@1.2.3 None 0 10.6 kB jonschlinkert
npm/wrap-ansi-cjs@7.0.0 None 0 0 B
npm/wrappy@1.0.2 None 0 2.96 kB zkat
npm/xtend@4.0.2 None 0 6.46 kB raynos
npm/y18n@5.0.8 filesystem 0 23.4 kB oss-bot
npm/yaml@1.10.2 environment 0 448 kB eemeli

🚮 Removed packages: npm/bcryptjs@2.4.3, npm/ical.js@1.5.0

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