Skip to content
This repository was archived by the owner on May 28, 2024. It is now read-only.

Commit a7f3112

Browse files
committed
refactor: align with updated API response
1 parent fd5c6fa commit a7f3112

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/resources/account/Preferences.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ import DeskbookersError from '../../DeskbookersError'
22
import Resource from '../Resource'
33
import { 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+
1622
export 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
}

0 commit comments

Comments
 (0)