Created
January 11, 2023 22:02
-
-
Save abel-masila/65e26944771f48dda8ce139145a74d32 to your computer and use it in GitHub Desktop.
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
const handleDBReponse = (response) => { | |
const appointments = response; | |
const today = moment().startOf("day"); //start of today 12 am | |
const initialSchedule = {}; | |
initialSchedule[today.format("YYYY-DD-MM")] = true; | |
const schedule = !appointments.length | |
? initialSchedule | |
: appointments.reduce((currentSchedule, appointment) => { | |
const { slot_date, slot_time } = appointment; | |
const dateString = moment(slot_date, "YYYY-DD-MM").format("YYYY-DD-MM"); | |
!currentSchedule[slot_date] | |
? (currentSchedule[dateString] = Array(8).fill(false)) | |
: null; | |
Array.isArray(currentSchedule[dateString]) | |
? (currentSchedule[dateString][slot_time] = true) | |
: null; | |
return currentSchedule; | |
}, initialSchedule); | |
for (let day in schedule) { | |
let slots = schedule[day]; | |
slots.length | |
? slots.every((slot) => slot === true) | |
? (schedule[day] = true) | |
: null | |
: null; | |
} | |
setSchedule(schedule); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment