From eaf66a06b28aa3f4bb50216c25d0d65bf5738677 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Wed, 16 Dec 2020 21:35:44 -0800 Subject: [PATCH] Resolved blocked day scheduling issue in smart scheduling IO-478 --- server/graphql-client/queries.js | 1 + server/scheduling/scheduling-job.js | 41 +++++++++++++---------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js index abc392ec9..b109c3b45 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -198,6 +198,7 @@ query QUERY_UPCOMING_APPOINTMENTS($now: timestamptz!, $jobId: uuid!) { start isintake id + block job { joblines_aggregate { aggregate { diff --git a/server/scheduling/scheduling-job.js b/server/scheduling/scheduling-job.js index 9c6a697d7..475ce1007 100644 --- a/server/scheduling/scheduling-job.js +++ b/server/scheduling/scheduling-job.js @@ -68,20 +68,26 @@ exports.job = async (req, res) => { //Populate the jobs scheduled to come in. appointments.forEach((appointment) => { - const jobHrs = - appointment.job.joblines_aggregate.aggregate.sum.mod_lb_hrs; - //Is the job in the same bucket? - const appointmentBucket = ssbuckets.filter( - (bucket) => - bucket.gte <= jobHrs && (!!bucket.lt ? bucket.lt > jobHrs : true) - )[0]; - if (appointmentBucket.id === JobBucket.id) { - //Theyre the same classification. Add it to the matrix. + if (!appointment.block) { + const jobHrs = + appointment.job.joblines_aggregate.aggregate.sum.mod_lb_hrs; + //Is the job in the same bucket? + const appointmentBucket = ssbuckets.filter( + (bucket) => + bucket.gte <= jobHrs && (!!bucket.lt ? bucket.lt > jobHrs : true) + )[0]; + if (appointmentBucket.id === JobBucket.id) { + //Theyre the same classification. Add it to the matrix. + const appDate = moment(appointment.start).format("yyyy-MM-DD"); + bucketMatrix[appDate] = { + ...bucketMatrix[appDate], + in: bucketMatrix[appDate].in + 1, + }; + } + } else { + //remove the date from the possible list. const appDate = moment(appointment.start).format("yyyy-MM-DD"); - bucketMatrix[appDate] = { - ...bucketMatrix[appDate], - in: bucketMatrix[appDate].in + 1, - }; + delete bucketMatrix[appDate]; } }); @@ -123,15 +129,6 @@ exports.job = async (req, res) => { possibleDates.push(new Date(bmkey).toISOString().substr(0, 10)); }); - //Temp - // possibleDates.push(new Date()); - // possibleDates.push(new Date()); - // possibleDates.push(new Date()); - // possibleDates.push(new Date()); - // possibleDates.push(new Date()); - //Get a list of upcoming appointments - //Get the config for each day - res.json(possibleDates); } catch (error) { console.log("error", error);