-
-
Save jeanpaulsio/e534814f568a0c9a2b743fce0f493077 to your computer and use it in GitHub Desktop.
/* | |
0 - Sunday | |
1 - Monday | |
2 - Tuesday | |
3 - Wednesday | |
4 - Thursday | |
5 - Friday | |
6 - Saturday | |
*/ | |
data = | |
[ | |
{ | |
id: 2 | |
date_as_string: "Next Tuesday" | |
times: [ | |
{ | |
id: 1 | |
time_string: "8:00am" | |
}, | |
{ | |
id: 2 | |
time_string: "8:30am" | |
}, | |
] | |
}, | |
{ | |
id: 3 | |
date_as_string: "Next Wednesday" | |
times: [ | |
{ | |
id: 1 | |
time_string: "8:00am" | |
}, | |
{ | |
id: 2 | |
time_string: "8:30am" | |
}, | |
] | |
}, | |
] | |
Man, working through displaying schedule is actually really tough
- Line 16 is the day of the week as an integer - I just need an easy way to be able to display the days of the week in order
- I think this goes back to number 1. With Whiz there wasnt a concept of an id for the top level day. So in pseudo code, displaying the days with their respective times looks like this
newData = reduce data to be sorted into an object with key value pairs where key is day of week
newData.monday.each
=> sort times
=> display times
newData.tuesday.each
=> sort times
=> display times
newData.wednesday.each
=> etc.
Hopefully that makes sense
- I think that works. As I work through this, it's really looking like I actually need a unique ID and a week_day id. In order for me to display a time as being "selected" i need to be able to reference it's unique id
so in an ideal world, the data will come out looking like this:
data =
[
{
unique_id: 123,
week_day: 2,
date_as_string: "Next Tuesday",
times: [
{ unique_id: 123, id: 1, time_string: "8:00am" },
{ unique_id: 456, id: 2, time_string: "8:30am" },
{ unique_id: 789, id: 3, time_string: "9:00am" },
{ unique_id: 111, id: 4, time_string: "9:30am" },
{ unique_id: 222, id: 5, time_string: "10:00am" },
{ unique_id: 333, id: 6, time_string: "10:30am" },
]
},
{
unique_id: 456,
week_day: 3,
date_as_string: "Next Wednesday",
times: [
{ unique_id: 444, id: 1, time_string: "8:00am" },
{ unique_id: 555, id: 2, time_string: "8:30am" },
]
},
]
thoughts??
times: [
{ unique_id: 444, id: 1, time_string: "8:00am" },
{ unique_id: 555, id: 2, time_string: "8:30am" },
]
to be clear, the "id" is to indicate order. so "9:00am" would have an id of 3 for example
These things don't necessarily have to be called "id" - and normally i'm not big on assigning numbered values to things that correspond to strings - but this is strictly for displaying things in order
To put things in a little more perspective - i don't expect the data to come in already ordered:
times: [
{ unique_id: 123, id: 1, time_string: "8:00am" },
{ unique_id: 456, id: 2, time_string: "8:30am" },
{ unique_id: 789, id: 3, time_string: "9:00am" },
{ unique_id: 111, id: 4, time_string: "9:30am" },
{ unique_id: 222, id: 5, time_string: "10:00am" },
{ unique_id: 333, id: 6, time_string: "10:30am" },
]
I imagine it's probably more like this:
times: [
{ unique_id: 333, id: 6, time_string: "10:30am" },
{ unique_id: 456, id: 2, time_string: "8:30am" },
{ unique_id: 111, id: 4, time_string: "9:30am" },
{ unique_id: 789, id: 3, time_string: "9:00am" },
{ unique_id: 222, id: 5, time_string: "10:00am" }
{ unique_id: 123, id: 1, time_string: "8:00am" },
]
I still need a unique id for each of these values but I'm ok with ditching the "id" concept if we can guarantee that these times are spit out of the API in order
Well, I matched yours exactly AND made one that I think is better...
https://github.com/Johnsalzarulo/uvohealth#available-times-endpoint
In line 16 is this ID the day of the week as an integer?
There isn't an ID on the top level day. Actually there isn't an ID for any specific available time either. Since these times come from multiple "providers" we just deal with a "Scheduled Time" against visits, none of this "ID's for available times" BS.
I'd like to change the ID on each id on each of these to be "week_day" as an integer - How does this work for you?