controller refactor to remove repeated code
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2021-04-28 11:55:04 +02:00
parent e53298f35c
commit d3b22d7078
1 changed files with 15 additions and 14 deletions

View File

@ -7,24 +7,25 @@ export default class Controller extends Section {
const missingData = !buy.itemFk || !buy.quantity || !buy.packageFk;
if (missingData) return;
let options;
if (buy.id) {
const query = `Buys/${buy.id}`;
this.$http.patch(query, buy).then(res => {
if (!res.data) return;
buy = Object.assign(buy, res.data);
this.vnApp.showSuccess(this.$t('Data saved!'));
});
options = {
query: `Buys/${buy.id}`,
method: 'patch'
};
} else {
const query = `Entries/${this.entry.id}/addBuy`;
this.$http.post(query, buy).then(res => {
options = {
query: `Entries/${this.entry.id}/addBuy`,
method: 'post'
};
}
this.$http[options.method](options.query, buy).then(res => {
if (!res.data) return;
buy = Object.assign(buy, res.data);
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
}
/**
* Returns checked instances