Merged
Conversation
Closed
|
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. |
ThyMinimalDev
approved these changes
Feb 13, 2025
| import { NO_AUTH_PROVIDED_MESSAGE } from "@/modules/auth/strategies/api-auth/api-auth.strategy"; | ||
|
|
||
| export class OptionalApiAuthGuard extends ApiAuthGuard { | ||
| handleRequest(error: Error, user: any) { |
Contributor
There was a problem hiding this comment.
why is the user typed as any here ?
Contributor
Author
There was a problem hiding this comment.
defining UserWithProfile gave TS error
Contributor
Author
There was a problem hiding this comment.
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 | ||
| ); | ||
| }); | ||
| } |
Contributor
There was a problem hiding this comment.
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; | ||
| }, {}); |
Contributor
There was a problem hiding this comment.
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
);
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear CAL-5052