diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-06-21 00:50:15 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-06-21 00:50:15 +0200 |
| commit | 0b854ecccfe7832ba9a837605822a103fd9d8bc0 (patch) | |
| tree | d4a11b5677ff96618d29b114e43d25a334f66412 /client/db.js | |
| parent | fbbb3a348018081bb2a89439eb3275153105d2e0 (diff) | |
clearing out old code
Diffstat (limited to 'client/db.js')
| -rw-r--r-- | client/db.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/client/db.js b/client/db.js new file mode 100644 index 0000000..8c3a6b5 --- /dev/null +++ b/client/db.js @@ -0,0 +1,33 @@ +function fetchDB(cb) { + let raw_db; + fetch('/db.json', { + method: 'GET' + }).then(res => { + if (res.status !== 200) { + return null + } + return res.json() + }).then(json => { + if (json) { + raw_db = parse(json) + } + cb(raw_db) + }).catch((err) => { + console.warn(err) + }) +} + +function parse(db) { + Object.keys(db).forEach(key => { + db[key] = db[key] + .filter((el) => ! el.disabled) + .sort((a,b) => a.__index<b.__index?-1:a.__index===b.__index?0:1) + }) + return db +} + +const backupDB = { + painting: [], +} + +export default { fetch: fetchDB, backupDB } |
