const app = require('../app') const _ = require('lodash') app.run(function(api) { api.statistics = () => api.get('/api/statistics') let locations = null api.locations = () => locations || (locations = api.get('/api/locations')) let locationsDictionary = null api.locationsDictionary = () => locationsDictionary || (locationsDictionary = api.locations().then(locations => _.fromPairs(locations.map(loc => [loc.key, loc])) )) api.location = (key) => api.locations().then(async locations => (await api.locationsDictionary())[key] ) let staffMembers = null api.staffMembers = () => staffMembers || (staffMembers = api.get('/api/staff-members')) let staffMemberDictionary = null api.staffMemberDictionary = () => staffMemberDictionary || (staffMemberDictionary = api.staffMembers().then(staffMembers => _.fromPairs(staffMembers.map(sm => [sm.id, sm])) )) })