UNPKG

640 BJavaScriptView Raw
1'use strict'
2
3const config = require('./rc')().get()
4
5const api = require('./api.js')(config.medx.username, config.medx.password)
6const store = require('./store.js')
7
8module.exports = (key, answer, delteAllProfiles, handleResponse) => {
9 const handleData = (err, data) => {
10 if (err) return handleResponse(err)
11 store.setState(key, data, (err) => {
12 if (err) return handleResponse(err)
13 handleResponse(null, data)
14 })
15 }
16
17 if (!api.isLoggedIn()) return api.login(delteAllProfiles, handleData)
18
19 store.getState(key, (err, state) => {
20 if (err) throw err
21 api.ask(answer, state, key === 'cli', handleData)
22 })
23}