2016-09-22 17:00:12 +08:00
|
|
|
import Backbone from './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 => {
|
2016-09-22 17:00:12 +08:00
|
|
|
callback(new Backbone.Mapper(payload))
|
2016-04-14 13:54:19 +08:00
|
|
|
})
|
|
|
|
}
|
2016-09-22 15:21:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Mapper
|