2016-09-22 15:21:59 +08:00
|
|
|
/* global Metamaps */
|
2016-04-14 13:54:19 +08:00
|
|
|
|
|
|
|
/*
|
2016-09-22 15:21:59 +08:00
|
|
|
* Dependencies:
|
|
|
|
* - Metamaps.Backbone
|
2016-04-14 13:54:19 +08:00
|
|
|
*/
|
2016-09-22 15:21:59 +08:00
|
|
|
const Mapper = {
|
2016-04-14 13:54:19 +08:00
|
|
|
// this function is to retrieve a mapper JSON object from the database
|
|
|
|
// @param id = the id of the mapper to retrieve
|
|
|
|
get: function (id, callback) {
|
2016-09-22 15:21:59 +08:00
|
|
|
return fetch(`/users/${id}.json`, {
|
|
|
|
}).then(response => {
|
|
|
|
if (!response.ok) throw response
|
|
|
|
return response.json()
|
|
|
|
}).then(payload => {
|
|
|
|
callback(new Metamaps.Backbone.Mapper(payload))
|
2016-04-14 13:54:19 +08:00
|
|
|
})
|
|
|
|
}
|
2016-09-22 15:21:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Mapper
|