Move everything to models and services #17

Merged
konrad merged 82 commits from refactor/models into master 2019-03-02 10:25:10 +00:00
2 changed files with 15 additions and 4 deletions
Showing only changes of commit 70b382c18a - Show all commits

View File

@ -1 +1 @@
export const URL_PREFIX = '/api/v1/'
export const URL_PREFIX = '/api/v1' // _without_ slash at the end

View File

@ -1,5 +1,8 @@
import {Model} from 'vue-mc'
import {URL_PREFIX} from './config'
let config = require('../../public/config.json')
import {reduce, replace} from 'lodash'
export class List extends Model {
// Default attributes that define the "empty" state.
@ -23,15 +26,23 @@ export class List extends Model {
methods: {
update: 'POST',
create: 'PUT',
},
// How to add headers to requests?
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token')
}
}
}
getRouteResolver() {
let self = this
return function (value, options) {
// eslint-disable-next-line
console.log(value, options)
return URL_PREFIX + value
let replacements = self.getRouteReplacements(value, options); // Replace all route parameters with their replacement values.
let replaced = reduce(replacements, function (result, value, parameter) {
return replace(result, parameter, value);
}, value)
return config.VIKUNJA_API_BASE_URL + URL_PREFIX + replaced
}
}