Skip to content

Commit

Permalink
get checkIn/noShow/cancel based on most recent timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Apr 12, 2024
1 parent 2bda77d commit 7d05278
Showing 1 changed file with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,38 @@ export default function getBookingStatus(
const bookingStatusMatch = bookingStatuses.filter(
(row) => row.calendarEventId === booking.calendarEventId
)[0];

if (bookingStatusMatch === undefined) return BookingStatusLabel.UNKNOWN;
if (bookingStatusMatch.checkedInAt !== '') {
return BookingStatusLabel.CHECKED_IN;
} else if (bookingStatusMatch.noShowedAt !== '') {
return BookingStatusLabel.NO_SHOW;
} else if (bookingStatusMatch.canceledAt !== '') {
return BookingStatusLabel.CANCELED;
} else if (bookingStatusMatch.rejectedAt !== '') {

const timeStringtoDate = (time: string) =>
time.length > 0 ? new Date(time) : new Date(0);

const checkedInTimestamp = timeStringtoDate(bookingStatusMatch.checkedInAt);
const noShowTimestamp = timeStringtoDate(bookingStatusMatch.noShowedAt);
const canceledTimestamp = timeStringtoDate(bookingStatusMatch.canceledAt);

// if any of checkedInAt, noShowedAt, canceledAt have a date, return the most recent
if (
checkedInTimestamp.getTime() !== 0 ||
noShowTimestamp.getTime() !== 0 ||
canceledTimestamp.getTime() !== 0
) {
let mostRecentTimestamp: Date = checkedInTimestamp;
let label = BookingStatusLabel.CHECKED_IN;

if (noShowTimestamp > mostRecentTimestamp) {
mostRecentTimestamp = noShowTimestamp;
label = BookingStatusLabel.NO_SHOW;
}

if (canceledTimestamp > mostRecentTimestamp) {
mostRecentTimestamp = canceledTimestamp;
label = BookingStatusLabel.CANCELED;
}
return label;
}

if (bookingStatusMatch.rejectedAt !== '') {
return BookingStatusLabel.REJECTED;
} else if (bookingStatusMatch.secondApprovedAt !== '') {
return BookingStatusLabel.APPROVED;
Expand Down

0 comments on commit 7d05278

Please sign in to comment.