From c866549ffe8fcfaa76d41ff630235bba3cbeaaad Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Wed, 5 Oct 2022 10:57:49 +0200
Subject: [PATCH] feat: add safetyOnBoarding path

---
 src/core/types/types.js        | 1 +
 src/core/verifyUserIdentity.js | 6 ++++++
 src/index.js                   | 3 ++-
 src/requests/bo.js             | 5 ++++-
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/core/types/types.js b/src/core/types/types.js
index 04831aa..df5323e 100644
--- a/src/core/types/types.js
+++ b/src/core/types/types.js
@@ -53,6 +53,7 @@
  * @property {string} address
  * @property {string} inseeCode
  * @property {string} city
+ * @property {boolean} hasBeenThroughtSafetyOnBoarding
  */
 
 /**
diff --git a/src/core/verifyUserIdentity.js b/src/core/verifyUserIdentity.js
index 61700e1..dcdfcd2 100644
--- a/src/core/verifyUserIdentity.js
+++ b/src/core/verifyUserIdentity.js
@@ -31,6 +31,9 @@ async function verifyUserIdentity(
     inseeCode = await getInseeCode(fields.postalCode, fields.city)
   }
 
+  // Store if user is going through safety sge onboarding
+  let userSafetyOnBoarding = false
+
   // First try with user adresse
   let pdl = await findUserPdl(
     `${baseUrl}/enedis_SDE_recherche-point/1.0`,
@@ -44,6 +47,8 @@ async function verifyUserIdentity(
 
   if (!pdl) {
     log('warn', 'Second chance for sge onboarding')
+    // Set safety onboarding in order to save it inside BO
+    userSafetyOnBoarding = true
     // Backup verification
     const userAddress = await findUserAddress(
       baseUrl,
@@ -100,6 +105,7 @@ async function verifyUserIdentity(
     inseeCode,
     postalCode: fields.postalCode,
     address: fields.address,
+    hasBeenThroughtSafetyOnBoarding: userSafetyOnBoarding,
     city: fields.city,
   }
 }
diff --git a/src/index.js b/src/index.js
index 484bebd..ae1faa8 100644
--- a/src/index.js
+++ b/src/index.js
@@ -120,7 +120,8 @@ async function start(fields, cozyParameters) {
       user.address,
       user.postalCode,
       user.inseeCode,
-      user.city
+      user.city,
+      user.hasBeenThroughtSafetyOnBoarding
     )
 
     // handle user contract start date in order to preperly request data
diff --git a/src/requests/bo.js b/src/requests/bo.js
index 236b2c8..6b2c839 100644
--- a/src/requests/bo.js
+++ b/src/requests/bo.js
@@ -10,6 +10,7 @@ const { default: axios } = require('axios')
  * @param {string} postalCode
  * @param {string} inseeCode
  * @param {string} city
+ * @param {boolean} hasBeenThroughtSafetyOnBoarding
  * @returns {Promise<Consent>}
  */
 async function createBoConsent(
@@ -21,7 +22,8 @@ async function createBoConsent(
   address,
   postalCode,
   inseeCode,
-  city
+  city,
+  hasBeenThroughtSafetyOnBoarding
 ) {
   log('info', `Query createBoConsent`)
   const headers = {
@@ -41,6 +43,7 @@ async function createBoConsent(
         postalCode,
         inseeCode,
         city,
+        hasBeenThroughtSafetyOnBoarding,
       },
       headers
     )
-- 
GitLab