-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
feat: v2 slots new version #18758
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
👍 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. |
import { NO_AUTH_PROVIDED_MESSAGE } from "@/modules/auth/strategies/api-auth/api-auth.strategy"; | ||
|
||
export class OptionalApiAuthGuard extends ApiAuthGuard { | ||
handleRequest(error: Error, user: any) { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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 | ||
); | ||
}); | ||
} |
There was a problem hiding this comment.
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);
});
}
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; | ||
}, {}); |
There was a problem hiding this comment.
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
);
}
Linear CAL-5052