This repository was archived by the owner on May 28, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -2,17 +2,23 @@ import DeskbookersError from '../../DeskbookersError'
22import Resource from '../Resource'
33import { pickAll } from 'ramda'
44
5- // Construct and return Map
6- function constructMap ( obj ) {
5+ // Construct Map from object
6+ const constructMap = o => {
77 const map = new Map ( )
88
9- for ( const key in obj ) {
10- map . set ( key , obj [ key ] )
9+ for ( const key in o ) {
10+ map . set ( key , o [ key ] )
1111 }
1212
1313 return map
1414}
1515
16+ // Convert response array to object
17+ const parseResponse = res => res . reduce ( ( o , pref ) => {
18+ o [ pref . key ] = pref . value
19+ return o
20+ } , { } )
21+
1622export default class Preferences extends Resource {
1723 constructor ( api ) {
1824 super ( api )
@@ -25,7 +31,7 @@ export default class Preferences extends Resource {
2531 path : this . endpoint
2632 } )
2733
28- return JSON . parse ( res )
34+ return parseResponse ( res )
2935 }
3036
3137 /**
@@ -66,6 +72,6 @@ export default class Preferences extends Resource {
6672 }
6773 } )
6874
69- return constructMap ( JSON . parse ( res ) )
75+ return constructMap ( parseResponse ( res ) )
7076 }
7177}
You can’t perform that action at this time.
0 commit comments