From 0b18ca73c2f92a8f35d8b4e1cea2812897f72af0 Mon Sep 17 00:00:00 2001 From: konrad Date: Wed, 5 Jun 2019 22:15:30 +0200 Subject: [PATCH] Fixed task update not working (again) --- src/services/abstractService.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/services/abstractService.js b/src/services/abstractService.js index f6f6454e..97ca4234 100644 --- a/src/services/abstractService.js +++ b/src/services/abstractService.js @@ -35,6 +35,23 @@ export default class AbstractService { }, }) + // Set the interceptors to process every request + let self = this + this.http.interceptors.request.use( (config) => { + switch (config.method) { + case 'post': + config.data = JSON.stringify(self.beforeUpdate(config.data)) + break + case 'put': + config.data = JSON.stringify(self.beforeCreate(config.data)) + break + case 'delete': + config.data = JSON.stringify(self.beforeDelete(config.data)) + break + } + return config + }) + // Set the default auth header if we have a token if ( localStorage.getItem('token') !== '' && @@ -291,7 +308,6 @@ export default class AbstractService { } const cancel = this.setLoading() - model = this.beforeCreate(model) return this.http.put(this.getReplacedRoute(this.paths.create, model), model) .catch(error => { return this.errorHandler(error) @@ -315,9 +331,6 @@ export default class AbstractService { } const cancel = this.setLoading() - if(typeof this.beforeUpdate === 'function') { - model = this.beforeUpdate(model) - } return this.http.post(this.getReplacedRoute(this.paths.update, model), model) .catch(error => { return this.errorHandler(error) @@ -341,7 +354,6 @@ export default class AbstractService { } const cancel = this.setLoading() - model = this.beforeDelete(model) return this.http.delete(this.getReplacedRoute(this.paths.delete, model), model) .catch(error => { return this.errorHandler(error)