Pita/berlin-vac-appointment-checker

Minor Optimisation

Closed this issue · 3 comments

switch (stat.id) {
case "arena":
isOk = true;
open(
"https://www.doctolib.de/institut/berlin/ciz-berlin-berlin?pid=practice-158431"
);
break;
case "tempelhof":
isOk = true;
open(
"https://www.doctolib.de/institut/berlin/ciz-berlin-berlin?pid=practice-158433"
);
break;
case "messe":
isOk = true;
open(
"https://www.doctolib.de/institut/berlin/ciz-berlin-berlin?pid=practice-158434"
);
break;
case "velodrom":
isOk = true;
open(
"https://www.doctolib.de/institut/berlin/ciz-berlin-berlin?pid=practice-158435"
);
break;
case "tegel":
isOk = true;
open(
"https://www.doctolib.de/institut/berlin/ciz-berlin-berlin?pid=practice-158436"
);
break;
case "erika":
isOk = true;
open(
"https://www.doctolib.de/institut/berlin/ciz-berlin-berlin?pid=practice-158437"
);
break;
default:
return;
}
if (!isOk) {
return;
}

What about moving the lookup table to a ES6 Map and just check if stat.id exists and is in that list, then open that link and set isOk true. Would make the lookup table much easier to maintain :)

Something like:

const lookupTable = new Map([ ['arena', 'https://www.doctolib.de/institut/berlin/ciz-berlin-berlin?pid=practice-158431'] ])
followed by

if(stat && stat.id && lookupTable.has(stat.id)){ isOk = true; open(lookupTable.get(stat.id)); }

Pita commented

Yes that's true. At the beginning I wanted to filter for certain vaccination centers. That's why there is this isOk flag. It's not necessary anymore, or could be solved with a lookup map, yes

Do you want me to create a PR?

You can check the code here: Arcticon@02ac828

Pita commented

I merged it, thank you!