Skip to content
Snippets Groups Projects
Commit e95d2633 authored by Yoan VALLET's avatar Yoan VALLET
Browse files

feat: set data into report mail

parent f3bdfc62
No related branches found
No related tags found
3 merge requests!103Support,!102Dev,!83Features/113 bilan mensuel
{"oauthOptions":{"clientID":"e6c1051a9a73b2153511c725f600585b","clientName":"cli-client-9","clientKind":"","clientSecret":"F373BJTE5Uezr6lskyXjpzvreceBIfId","clientURI":"","registrationAccessToken":"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyZWdpc3RyYXRpb24iLCJpYXQiOjE1OTg4NjAwNTYsImlzcyI6ImNvenkudG9vbHM6ODA4MCIsInN1YiI6ImU2YzEwNTFhOWE3M2IyMTUzNTExYzcyNWY2MDA1ODViIn0.eBaaP3IyTu2-R6iJJzoR5uAlgMGNVTXG-hrvRW1xlfSMRCFrOBYi6VhzYYPE2Gew93qe8j97pRxIfuAj-AX5iw","redirectURI":"http://localhost:3333/do_access","softwareID":"dev-connector","softwareVersion":"","logoURI":"","policyURI":"","notificationPlatform":"","notificationDeviceToken":""},"token":{"tokenType":"bearer","accessToken":"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhY2Nlc3MiLCJpYXQiOjE1OTg4NjAwNjAsImlzcyI6ImNvenkudG9vbHM6ODA4MCIsInN1YiI6ImU2YzEwNTFhOWE3M2IyMTUzNTExYzcyNWY2MDA1ODViIiwic2NvcGUiOiJpby5jb3p5LmFwcHMgaW8uY296eS5zZXR0aW5ncyBpby5jb3p5LmFjY291bnRzIGlvLmNvenkua29ubmVjdG9ycyBpby5jb3p5LnRyaWdnZXJzIGlvLmNvenkuam9icyBjb20uZ3JhbmRseW9uLmVuZWRpcy4qIGNvbS5ncmFuZGx5b24uZ3JkZi4qIGNvbS5ncmFuZGx5b24uZWdsLiogY29tLmdyYW5kbHlvbi5lY29seW8uKiJ9.fYEG_VXhI3Yl_GKs248AF2oMU4d0uEnIavZgQoGGIEycovIbQHylC2D9j0O9oU6rsBm9Ewu8v23ZI5YwcTZxSA","refreshToken":"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyZWZyZXNoIiwiaWF0IjoxNTk4ODYwMDYwLCJpc3MiOiJjb3p5LnRvb2xzOjgwODAiLCJzdWIiOiJlNmMxMDUxYTlhNzNiMjE1MzUxMWM3MjVmNjAwNTg1YiIsInNjb3BlIjoiaW8uY296eS5hcHBzIGlvLmNvenkuc2V0dGluZ3MgaW8uY296eS5hY2NvdW50cyBpby5jb3p5Lmtvbm5lY3RvcnMgaW8uY296eS50cmlnZ2VycyBpby5jb3p5LmpvYnMgY29tLmdyYW5kbHlvbi5lbmVkaXMuKiBjb20uZ3JhbmRseW9uLmdyZGYuKiBjb20uZ3JhbmRseW9uLmVnbC4qIGNvbS5ncmFuZGx5b24uZWNvbHlvLioifQ.3DvqlWeJz-urjyb-rUATiUaz_ITo4GaOt2Hrp6loZ7yyW17qnh9XtkQwIm68cqe4ZrrWbb219-3q1ANy9SOhrg","scope":"io.cozy.apps io.cozy.settings io.cozy.accounts io.cozy.konnectors io.cozy.triggers io.cozy.jobs com.grandlyon.enedis.* com.grandlyon.grdf.* com.grandlyon.egl.* com.grandlyon.ecolyo.*"}}
\ No newline at end of file
{
"COZY_URL": "http://cozy.tools:8080",
"fields": {}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
import logger from 'cozy-logger'
import { runService } from './service'
import { Client } from 'cozy-client'
import get from 'lodash/get'
import { DateTime } from 'luxon'
import { runService } from './service'
import { createEmail } from './createEmail'
import { TimePeriod } from 'services/dataConsumptionContracts'
import UserProfileManager from 'services/userProfileDataManagerService'
import ConsumptionDataManager from 'services/consumptionDataManagerService'
import PerformanceIndicatorAggregateCalculator from 'services/performanceIndicatorAggregateCalculatorService'
const log = logger.namespace('report')
......@@ -20,14 +24,73 @@ const monthlyReport = async ({ client }: MonthlyReportProps) => {
return
}
const username = ''
const url = ''
const period = ''
let username = ''
let url = ''
let periodLabel = ''
const monthlyPerformance = '--%'
log('info', 'Fetching data for mail...')
// Retrieve public name from the stack
const settings = await client
.getStackClient()
.fetchJSON('GET', '/settings/instance')
const publicName = get(settings, 'data.attributes.public_name')
if (publicName) {
username = publicName
}
// Retrieve link to ecolyo app from the stack
const apps = await client.getStackClient().fetchJSON('GET', '/apps/ecolyo')
const appLink = get(apps, 'data.links.related')
if (appLink) {
url = appLink
}
// Define period for the mail
const startingDate = DateTime.local()
.minus({
months: 1,
})
.startOf('month')
const endingDate = DateTime.local()
.minus({
months: 1,
})
.endOf('month')
periodLabel = `${startingDate
.setLocale('fr')
.toFormat(
'LLL yyyy'
)} (${startingDate.toISODate()} au ${endingDate.toISODate()})`
const period = new TimePeriod(startingDate, endingDate)
// Retrieve performance for the concerned period
const cdm = new ConsumptionDataManager(client)
const fetchedPerformanceIndicators = await cdm.getPerformanceIndicators(
period,
20,
[0, 1, 2]
)
if (fetchedPerformanceIndicators) {
log('info', fetchedPerformanceIndicators[0].value)
log('info', fetchedPerformanceIndicators[1].value)
log('info', fetchedPerformanceIndicators[2].value)
const performanceIndicators = PerformanceIndicatorAggregateCalculator.aggregatePerformanceIndicators(
fetchedPerformanceIndicators
)
log('info', performanceIndicators.value)
log('info', performanceIndicators.percentageVariation)
} else {
log('info', 'performanceIndicators not fetched')
}
log('info', 'Creation of mail...')
const mailContent = createEmail(username, url, period, monthlyPerformance)
const mailContent = createEmail(
username,
url,
periodLabel,
monthlyPerformance
)
const mailData = {
mode: 'noreply',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment