Skip to content
Snippets Groups Projects
Commit 53602327 authored by i-vall's avatar i-vall
Browse files

feat(format): normalized data storing

parent 4f97b02a
Branches
No related tags found
No related merge requests found
{
"name": "cozy-konnector-template",
"name": "egl-api-connector",
"version": "1.0.0",
"description": "",
"repository": {
"type": "git",
"url": "git+https://github.com/konnectors/template.git"
"url": "git+https://gitlab.alpha.grandlyon.com/cozy/egl-api-connector.git"
},
"keywords": [],
"author": "Cozy Cloud",
......@@ -33,12 +33,13 @@
"clean": "rm -rf ./data",
"build": "webpack",
"lint": "eslint --fix .",
"deploy": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build} --repo=${DEPLOY_REPOSITORY:-git@github.com:konnectors/template.git}",
"deploy": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build} --repo=${DEPLOY_REPOSITORY:-https://gitlab.alpha.grandlyon.com/cozy/egl-api-connector.git}",
"cozyPublish": "cozy-app-publish --token $REGISTRY_TOKEN --build-commit $(git rev-parse ${DEPLOY_BRANCH:-build})",
"travisDeployKey": "./bin/generate_travis_deploy_key"
},
"dependencies": {
"cozy-konnector-libs": "4.15.7"
"cozy-konnector-libs": "4.15.7",
"moment": "^2.24.0"
},
"devDependencies": {
"copy-webpack-plugin": "5.0.3",
......
......@@ -7,6 +7,7 @@ const {
cozyClient
} = require('cozy-konnector-libs')
const rp = require('request-promise')
const moment = require('moment')
//const moment = require('moment')
//require('request-debug')(rp)
......@@ -79,15 +80,34 @@ async function getData(response) {
}
try {
const response = await rp(dataRequest)
return response
switch (response.codeRetour) {
case 100:
return format(response)
case -2:
throw new Error(errors.LOGIN_FAILED)
case -1:
throw new Error(errors.VENDOR_DOWN)
default:
throw new Error(errors.UNKNOWN_ERROR)
}
} catch (error) {
throw new Error(errors.VENDOR_DOWN)
}
}
function format(response) {
const data = response.resultatRetour.map(value => {
return {
time: moment(value.DateReleve, moment.ISO_8601).format('YYYY-MM-DD'),
load: value.ValeurIndex,
type: value.TypeAgregat
}
})
return data
}
function storeLoadProfile(loadProfile) {
return hydrateAndFilter(loadProfile, 'egl.loadprofile', {
keys: ['DateReleve']
keys: ['time']
}).then(filteredDocuments => {
addData(filteredDocuments, 'egl.loadprofile')
})
......
......@@ -3570,6 +3570,11 @@ mkdirp@0.5.1, mkdirp@0.x.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@
dependencies:
minimist "0.0.8"
moment@^2.24.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==
move-concurrently@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment