From 64b52b7a63b4729c0f964a69e20f6807d7e4d777 Mon Sep 17 00:00:00 2001
From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com>
Date: Tue, 28 Jul 2020 11:48:22 +0200
Subject: [PATCH] feat: add send mail for test purpose

---
 manifest.webapp                        |  2 +-
 src/targets/services/monthlySummary.js | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/manifest.webapp b/manifest.webapp
index cfeb858b1..319d3ed43 100644
--- a/manifest.webapp
+++ b/manifest.webapp
@@ -21,7 +21,7 @@
       "public": false
     }
   },
-  "service": {
+  "services": {
     "monthlySummary": {
       "type": "node",
       "file": "monthlySummary.js",
diff --git a/src/targets/services/monthlySummary.js b/src/targets/services/monthlySummary.js
index a4d8dd6e5..10000734b 100644
--- a/src/targets/services/monthlySummary.js
+++ b/src/targets/services/monthlySummary.js
@@ -50,6 +50,25 @@ const monthlySummaryStats = async () => {
   const consumptions = await fetchConsumptionsForPeriod(period)
   const meanConsumptions = getMeanOnPeriod(consumptions, period)
 
+  const FEEDBACK_EMAIL = 'ecolyo@grandlyon.com'
+
+  const mailContent = 'TEST'
+
+  const mailData = {
+    mode: 'from',
+    to: [{ name: 'Support', email: FEEDBACK_EMAIL }],
+    subject: '[Ecolyo] - Votre bilan mensuel',
+    parts: [{ type: 'text/plain', body: mailContent }],
+  }
+  try {
+    const jobCollection = client.collection('io.cozy.jobs')
+    await jobCollection.create('sendmail', mailData)
+  } catch (e) {
+    // eslint-disable-next-line no-console
+    console.error(e)
+    setError(t('feedback.error_sending'))
+  }
+
   log(
     'info',
     `${consumptions.length} consumptions between ${period.start} and ${period.end}`
-- 
GitLab