transformValue to payload, body and method

This commit is contained in:
Mathieu Jaumotte 2021-05-21 18:24:32 +02:00
parent 132f11298e
commit 21cc0007fb
2 changed files with 29 additions and 6 deletions

View File

@ -55,13 +55,36 @@ export default {
})).catch(error => this.$store.commit('catchError', error));
},
updateSocialIssues(value) {
console.log('@@@ CHANGE value', value);
console.log('@@@ CHANGED value');
this.$store.dispatch('updateSocialIssues', this.transformValue(value));
},
transformValue(value) {
let payload = value;
let body = {}; //{ type: "social_issue", id: 5 };
let method = ''; //'POST' : 'DELETE';
transformValue(updated) {
let stored = this.value;
//console.log('updated', updated, updated.length);
//console.log('stored', stored, stored.length);
let added = updated.filter(x => stored.indexOf(x) === -1).shift();
//console.log('added', added);
let removed = stored.filter(x => updated.indexOf(x) === -1).shift();
//console.log('removed', removed);
let method = (typeof removed === 'undefined') ? 'POST' : 'DELETE';
console.log('method', method);
//let concat = (...arrays) => [].concat(...arrays.filter(Array.isArray));
//let changed = concat(added, removed);
//let changed = [...new Set([...added, ...removed ])];
let changed = (typeof removed === 'undefined') ? added : removed;
//console.log('changed', changed);
let body = { type: "social_issue", id: changed.id };
console.log('body', body);
console.log(changed.text);
let payload = updated;
return { payload, body, method };
}
}

View File

@ -179,7 +179,7 @@ let initPromise = getAccompanyingCourse(id)
})).catch((error) => { commit('catchError', error) });
},
updateSocialIssues({ commit }, { payload, body, method }) {
console.log('## action: payload', { payload, body, method });
//console.log('## action: payload', { payload, body, method });
//postSocialIssue(id, body, method)
//.then(response => new Promise((resolve, reject) => {