From 453ba9bb586fcbdd5042f037fc194b28955b15a2 Mon Sep 17 00:00:00 2001 From: Sam Redman Date: Wed, 3 Feb 2021 12:37:20 +0000 Subject: [PATCH 1/5] trying to support 6.x --- eventing-function.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eventing-function.js b/eventing-function.js index 8dd6596..2275d15 100644 --- a/eventing-function.js +++ b/eventing-function.js @@ -67,7 +67,7 @@ function findPossibleTraces(doc) { var possible_infected_visitors = SELECT meta().id, phone, checkin, checkout - FROM `track-and-tracers`._default._default + FROM `track-and-tracers` WHERE ((checkin >= $doc_checkin AND checkin <= $doc_checkout) OR (checkout >= $doc_checkin AND checkout <= $doc_checkout)) AND location = $doc_location @@ -88,7 +88,7 @@ function findPossibleTraces(doc) { function notify_via_sms(doc) { log("Person might be infected, notifying", doc) - UPDATE `track-and-tracers`._default._default USE KEYS [$doc.id] SET notified = true; + UPDATE `track-and-tracers` USE KEYS [$doc.id] SET notified = true; } function OnDelete(meta, options) { From 7144f5a73c41271272d3b976a7b9e6bbea146787 Mon Sep 17 00:00:00 2001 From: tallbigsam Date: Wed, 3 Feb 2021 12:41:01 +0000 Subject: [PATCH 2/5] Create README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..dfbaf89 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# eventing-tracking + +Need to have the following setup: + +track-and-tracers bucket +metadata bucket + From f3918c9b4a7caa1c3f8d16e9922274988e9aa16c Mon Sep 17 00:00:00 2001 From: tallbigsam Date: Wed, 3 Feb 2021 12:41:52 +0000 Subject: [PATCH 3/5] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index dfbaf89..1f2afbf 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,4 @@ Need to have the following setup: track-and-tracers bucket metadata bucket +Follow configuration in the screenshot for the eventing function. From 6b0ba2e52d3fe94726b17c3362d8bba732db5b79 Mon Sep 17 00:00:00 2001 From: Sam Redman Date: Tue, 9 Feb 2021 09:37:31 +0000 Subject: [PATCH 4/5] check for checkout --- eventing-function.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eventing-function.js b/eventing-function.js index 2275d15..93fd193 100644 --- a/eventing-function.js +++ b/eventing-function.js @@ -2,7 +2,9 @@ function OnUpdate(doc, meta) { if(doc._type === "locationRegistration"){ if(doc["location"]) { if(doc["checkin"]){ - increment_venue_guest(doc); + if(!doc["checkout"]) { + increment_venue_guest(doc); + } } if(doc["checkout"]){ decrement_venue_guest(doc); From 1b06d1e01659eaced14c9592ea094b4481a0f574 Mon Sep 17 00:00:00 2001 From: mariombj <77190447+mariombj@users.noreply.github.com> Date: Tue, 9 Feb 2021 11:35:16 +0100 Subject: [PATCH 5/5] Update eventing-function.js Issue with Object on guests is fixed, another one is decrementing when run the function of infected --- eventing-function.js | 99 ++++++-------------------------------------- 1 file changed, 12 insertions(+), 87 deletions(-) diff --git a/eventing-function.js b/eventing-function.js index 93fd193..773656f 100644 --- a/eventing-function.js +++ b/eventing-function.js @@ -1,98 +1,23 @@ function OnUpdate(doc, meta) { - if(doc._type === "locationRegistration"){ - if(doc["location"]) { - if(doc["checkin"]){ - if(!doc["checkout"]) { - increment_venue_guest(doc); - } - } - if(doc["checkout"]){ - decrement_venue_guest(doc); - if(doc.infected){ - findPossibleTraces(doc); - } - } - } - } - -} -function venue_full_call_police(location) { - //rest call to the police - log("location is full: ", location); -} - -function increment_venue_guest(doc) { - - - //log("incrementing guests at: ", doc.location) - var location_doc = tnt[doc.location]; - - log("Current venue guests:", location_doc.guests) - if(location_doc.guests < location_doc.maxGuests) { - //log("guests incremented") - location_doc.guests = location_doc + 1; - } - else { - // venue is full, call the police - venue_full_call_police(doc.location); - } - - //log("Local guests:", location_doc.guests); + if(doc.type != "covidSuspectedUser") return; + if(doc.infected == false) return; - tnt[doc.location] = location_doc; - //log("updated the location doc"); + var documentIdToBeUpdated = "covidcase::" + doc.state + "::" + doc.createDate; - //log("location guests in cb: ", tnt[doc.location].guests); + var documentToBeUpdated = SELECT track_and_trace.* FROM track_and_trace USE KEYS [$documentIdToBeUpdated]; - //log("location doc local:", location_doc); - //log("location doc couchbase:", tnt[doc.location]); -} - -function decrement_venue_guest(doc) { - log("DECREMENTING") - var location_doc = tnt[doc["location"]]; - log("decrementing from: ", location_doc.guests); - location_doc["guests"] = location_doc["guests"]--; - log("decrementation complete: ", location_doc.guests) - tnt[doc["location"]] = location_doc; - log("location guests in cb: ", tnt[doc.location].guests); - -} + for(var i of documentToBeUpdated){ -function findPossibleTraces(doc) { - - var doc_checkin = doc.checkin; - var doc_checkout = doc.checkout; - var doc_phone = doc.phone; - var doc_location = doc.location; + var incPositive = parseInt(i.positive) + 1; + var incPositiveIncrease = parseInt(i.positiveIncrease) + 1; + + i.positive = incPositive + ""; + i.positiveIncrease = incPositiveIncrease + ""; - var possible_infected_visitors = - SELECT meta().id, phone, checkin, checkout - FROM `track-and-tracers` - WHERE ((checkin >= $doc_checkin AND checkin <= $doc_checkout) - OR (checkout >= $doc_checkin AND checkout <= $doc_checkout)) - AND location = $doc_location - AND phone != $doc_phone; - - for(var person of possible_infected_visitors) { - notify_via_sms(person); + targetBucket[documentIdToBeUpdated] = i; } - - log("Updating the infections doc"); - var location_doc = tnt[doc.location]; - log("Infections doc:", location_doc); - location_doc.infections = location_doc.infections + 1; - log("new infections", location_doc.infections); - tnt[doc.location] = location_doc; - -} - -function notify_via_sms(doc) { - log("Person might be infected, notifying", doc) - UPDATE `track-and-tracers` USE KEYS [$doc.id] SET notified = true; } function OnDelete(meta, options) { - log("Doc deleted/expired", meta.id); -} \ No newline at end of file +}