Newer
Older
import axios from 'axios'
import { Account, Trigger } from 'models'
import config from './config'
const headers = {
Accept: 'application/json',
Authorization: config.authorization,
Cookie: config.cookie,
'content-type': 'application/json',
}
const COZY_PREFIX = 'cozy35ba44d2d1749e6f21646edce51e7190'
const ENEDIS_ACCOUNT_ID = '70e68b8450cee09fe2f077610901094d'
const ENEDIS_ACCOUNT: Partial<Account> = {
account_type: 'enedissgegrandlyon',
auth: {
address: '6 Rue Vaillant Couturier',
city: 'Vénissieux',
firstname: 'Jane',
lastname: 'Doe',
pointId: '19170766804121',
postalCode: '69200',
data: {
consentId: 43,
expirationDate: '2023-09-26',
identifier: 'address',
state: null,
}
const dataEnedisAccount = JSON.stringify(ENEDIS_ACCOUNT)
const GRDF_ACCOUNT_ID = '89e68b8450cee09fe2f077610901094d'
const GRDF_ACCOUNT: Partial<Account> = {
pce: '12345678901234',
email: 'jane@grandlyon.com',
lastname: 'Doe',
firstname: 'Jane',
postalCode: '69003',
identifier: 'email',
}
const dataGrdfAccount = JSON.stringify(GRDF_ACCOUNT)
const EGL_ACCOUNT_ID = '90e68b8450cee09fe2f077610901094d'
const EGL_ACCOUNT: Partial<Account> = {
contractId: '1234567',
meteringId: '123456789ABC',
identifier: 'contractId',
}
const dataEglAccount = JSON.stringify(EGL_ACCOUNT)
const ENEDIS_TRIGGER: Trigger = {
_id: '3ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: COZY_PREFIX,
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: ENEDIS_ACCOUNT_ID,
konnector: 'enedissgegrandlyon',
},
cozyMetadata: {
doctypeVersion: '1',
metadataVersion: 1,
createdAt: '2020-10-09T08:00:00.6092798Z',
createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z',
},
}
const dataEnedisTrigger = JSON.stringify({
data: {
const GRDF_TRIGGER: Trigger = {
_id: '4ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: COZY_PREFIX,
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: GRDF_ACCOUNT_ID,
konnector: 'grdfgrandlyon',
},
cozyMetadata: {
doctypeVersion: '1',
metadataVersion: 1,
createdAt: '2020-10-09T08:00:00.6092798Z',
createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z',
},
}
const dataGrdfTrigger = JSON.stringify({
data: {
const EGL_TRIGGER: Trigger = {
_id: '5ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: COZY_PREFIX,
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: EGL_ACCOUNT_ID,
konnector: 'eglgrandlyon',
},
cozyMetadata: {
doctypeVersion: '1',
metadataVersion: 1,
createdAt: '2020-10-09T08:00:00.6092798Z',
createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z',
},
}
const dataEglTrigger = JSON.stringify({
data: {
},
})
async function launch() {
// Enedis
await axios({
method: 'put',
url: `http://cozy.tools:8080/data/io.cozy.accounts/${ENEDIS_ACCOUNT_ID}`,
headers: headers,
data: dataEnedisAccount,
})
.then(function (response) {
console.log(JSON.stringify(response.data))
})
.catch(function (error) {
console.log(error)
})
await axios({
method: 'post',
url: 'http://cozy.tools:8080/jobs/triggers',
headers: headers,
data: dataEnedisTrigger,
})
.then(function (response) {
console.log(JSON.stringify(response.data))
})
.catch(function (error) {
console.log(error)
})
// GRDF
await axios({
method: 'put',
url: `http://cozy.tools:8080/data/io.cozy.accounts/${GRDF_ACCOUNT_ID}`,
headers: headers,
data: dataGrdfAccount,
})
.then(function (response) {
console.log(JSON.stringify(response.data))
})
.catch(function (error) {
console.log(error)
})
await axios({
method: 'post',
url: 'http://cozy.tools:8080/jobs/triggers',
headers: headers,
data: dataGrdfTrigger,
})
.then(function (response) {
console.log(JSON.stringify(response.data))
})
.catch(function (error) {
console.log(error)
})
// EGL
await axios({
method: 'put',
url: `http://cozy.tools:8080/data/io.cozy.accounts/${EGL_ACCOUNT_ID}`,
headers: headers,
data: dataEglAccount,
})
.then(function (response) {
console.log(JSON.stringify(response.data))
})
.catch(function (error) {
console.log(error)
})
await axios({
method: 'post',
url: 'http://cozy.tools:8080/jobs/triggers',
headers: headers,
data: dataEglTrigger,
})
.then(function (response) {
console.log(JSON.stringify(response.data))
})
.catch(function (error) {
console.log(error)
})
}
launch()