diff options
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 } |
