From 6bcb5f2af5569d9f0830f70815af3dbbb0027f74 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Thu, 21 Oct 2021 11:42:05 -0700 Subject: [PATCH] IO-1446 Smart Schedule Blocked Day Fixes --- server/scheduling/scheduling-job.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/server/scheduling/scheduling-job.js b/server/scheduling/scheduling-job.js index 05f210485..cb74a524b 100644 --- a/server/scheduling/scheduling-job.js +++ b/server/scheduling/scheduling-job.js @@ -87,7 +87,10 @@ exports.job = async (req, res) => { } else { //remove the date from the possible list. const appDate = moment(appointment.start).format("yyyy-MM-DD"); - delete bucketMatrix[appDate]; + bucketMatrix[appDate] = { + ...bucketMatrix[appDate], + blocked: true, + }; } }); @@ -125,7 +128,9 @@ exports.job = async (req, res) => { const possibleDates = []; const bucketMatrixKeys = Object.keys(bucketMatrix); bucketMatrixKeys.forEach((bmkey) => { - const isShopOpen = workingdays[dayOfWeekMapper(moment(bmkey).day())]; + const isShopOpen = + workingdays[dayOfWeekMapper(moment(bmkey).day())] && + !bucketMatrix[bmkey].blocked; if ( JobBucket.target > bucketMatrix[bmkey].in - bucketMatrix[bmkey].out && @@ -134,7 +139,11 @@ exports.job = async (req, res) => { possibleDates.push(new Date(bmkey).toISOString().substr(0, 10)); }); - res.json(possibleDates); + if (possibleDates.length < 6) { + res.json(possibleDates); + } else { + res.json(possibleDates.slice(0, 5)); + } } catch (error) { logger.log("smart-scheduling-error", "ERROR", req.user.email, jobId, { error,