UNPKG

@kadconsulting/dry

Version:
227 lines 9.64 kB
const isoUtc = (isoString) => { let datePart, timePart; // Check if the string contains the 'T' character, typical for ISO strings if (isoString.includes('T')) { [datePart, timePart] = isoString.split('T'); } else { // Handle cases where the input might not be in standard ISO format datePart = isoString.substring(0, 10); // Assuming 'YYYY-MM-DD' format timePart = isoString.substring(11, 19); // Assuming 'hh:mm:ss' format } // Remove any extraneous parts from time (like milliseconds or timezone info) timePart = timePart.split('.')[0].split('Z')[0]; // Extract year, month, and day from the date part const [year, month, day] = datePart.split('-').map(Number); // Extract hours and minutes from the time part const [hours, minutes] = timePart.split(':').map(Number); // Create a new Date object using local time values const formattedTime = new Date(year, month - 1, day, hours, minutes); return formattedTime; }; const transformResourceBookingsToCalendarEvents = (bookings, resourceId, selectedFilters) => { return bookings.reduce((calendarEvents, booking) => { const bookingAttr = booking; const events = selectedFilters?.events; const locations = selectedFilters?.locations; const coaches = selectedFilters?.coaches; const services = selectedFilters?.services; const classGroups = selectedFilters?.classGroups; const membershipClasses = selectedFilters?.membershipClasses; const categories = selectedFilters?.categories; const simulatorBays = selectedFilters?.simulatorBays; const bookingLocation = booking?.location?.id; const bookingCoaches = booking?.coaches; const bookingEvent = booking?.event?.id; const bookingService = booking?.service?.id; const bookingClassGroup = // @ts-ignore booking?.class?.classGroup?.id; const bookingMembershipClass = booking?.class?.id; const bookingSimulatorBay = booking?.simulator_bays; let isVisible = true; const hasACoach = () => { let flag = false; bookingCoaches?.forEach((coach) => { if (coaches?.includes(coach.id)) { flag = true; } }); return flag; }; const hasASimulatorBay = () => { let flag = false; bookingSimulatorBay?.forEach((simulatorBay) => { if (simulatorBays?.includes(simulatorBay.id)) { flag = true; } }); return flag; }; console.log({ booking, hasASimulatorBay: hasASimulatorBay(), hasACoach: hasACoach(), }); if (selectedFilters) { isVisible = (!events || events?.length === 0 || events?.includes(bookingEvent)) && (!locations || locations?.length === 0 || locations?.includes(bookingLocation)) && (!coaches || coaches?.length === 0 || hasACoach()) && (!services || services?.length === 0 || services?.includes(bookingService)) && (!classGroups || classGroups?.length === 0 || classGroups?.includes(bookingClassGroup)) && (!membershipClasses || membershipClasses?.length === 0 || membershipClasses?.includes(bookingMembershipClass)) && (!categories || categories?.length === 0 || categories?.includes(bookingCategory)) && (!simulatorBays || simulatorBays?.length === 0 || hasASimulatorBay()); } let color = 'purple'; if (booking?.service) { color = booking?.service?.calendarColor; } if (booking?.class) { color = booking?.class?.calendarColor; } if (booking?.event) { color = booking?.event?.calendarColor; } if (isVisible && bookingAttr?.startDateTime && bookingAttr?.endDateTime) { const calendarEvent = { id: String(booking?.id), title: bookingAttr?.title || 'No Title', resourceId, start: isoUtc(bookingAttr?.startDateTime), end: isoUtc(bookingAttr?.endDateTime), allDay: false, color, extraData: { bookingId: booking?.id, title: bookingAttr?.title, date: isoUtc(bookingAttr?.startDateTime), type: 'membershipClass', }, }; return [...calendarEvents, calendarEvent]; } return calendarEvents; }, []); }; const transformResourceCalendarToCalendarEvents = (calendar, resourceId, blockedTimeColor) => { const test = calendar[0]?.blocked_times?.reduce((calendarEvents, data) => { const id = data?.id; const { startTime, endTime, reason, type, booking } = data; if (startTime && endTime && !booking) { const calendarEvent = { id: String(id), title: `${reason} - ${type}`, resourceId, start: isoUtc(startTime), end: isoUtc(endTime), allDay: false, color: blockedTimeColor, extraData: { blockedTimeId: id, title: `${reason} - ${type}`, date: isoUtc(startTime), }, }; return [...calendarEvents, calendarEvent]; } return calendarEvents; }, []); return test; }; const transformAllBookingsToCalendarEvents = (bookings, selectedFilters) => { return bookings.reduce((calendarEvents, booking) => { const bookingAttr = booking; const events = selectedFilters?.events; const locations = selectedFilters?.locations; const coaches = selectedFilters?.coaches; const services = selectedFilters?.services; const classGroups = selectedFilters?.classGroups; const membershipClasses = selectedFilters?.membershipClasses; const simulatorBays = selectedFilters?.simulatorBays; const bookingLocation = booking?.location?.id; const bookingCoaches = booking?.coaches; const bookingEvent = booking?.event?.id; const bookingService = booking?.service?.id; const bookingClassGroup = booking?.class?.classGroup?.id; const bookingMembershipClass = booking?.class?.id; const bookingSimulatorBay = booking?.simulator_bays; const hasACoach = () => { let flag = false; bookingCoaches?.forEach((coach) => { if (coaches?.includes(coach.id)) { flag = true; } }); return flag; }; const hasASimulatorBay = () => { let flag = false; bookingSimulatorBay?.forEach((simulatorBay) => { if (simulatorBays?.includes(simulatorBay.id)) { flag = true; } }); return flag; }; const isVisible = !selectedFilters || ((!events || events?.length === 0 || events?.includes(bookingEvent)) && (!locations || locations?.length === 0 || locations?.includes(bookingLocation)) && (!coaches || coaches?.length === 0 || hasACoach()) && (!services || services?.length === 0 || services?.includes(bookingService)) && (!classGroups || classGroups?.length === 0 || classGroups?.includes(bookingClassGroup)) && (!membershipClasses || membershipClasses?.length === 0 || membershipClasses?.includes(bookingMembershipClass)) && (!simulatorBays || simulatorBays?.length === 0 || hasASimulatorBay())); let color = 'purple'; if (booking?.service) { color = booking?.service?.calendarColor; } if (booking?.class) { color = booking?.class?.calendarColor; } if (booking?.event) { color = booking?.event?.calendarColor; } if (isVisible && bookingAttr?.startDateTime && bookingAttr?.endDateTime) { const calendarEvent = { id: String(booking.id), title: bookingAttr?.title || 'No Title', start: isoUtc(bookingAttr?.startDateTime), end: isoUtc(bookingAttr?.endDateTime), allDay: false, color, extraData: { bookingId: booking.id, title: bookingAttr?.title, date: isoUtc(bookingAttr?.startDateTime), type: 'membershipClass', }, }; return [...calendarEvents, calendarEvent]; } return calendarEvents; }, []); }; export { transformResourceBookingsToCalendarEvents, transformAllBookingsToCalendarEvents, transformResourceCalendarToCalendarEvents, }; //# sourceMappingURL=transformFunctions2.js.map