controller refactor to remove repeated code
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e53298f35c
commit
d3b22d7078
|
@ -7,24 +7,25 @@ export default class Controller extends Section {
|
||||||
const missingData = !buy.itemFk || !buy.quantity || !buy.packageFk;
|
const missingData = !buy.itemFk || !buy.quantity || !buy.packageFk;
|
||||||
if (missingData) return;
|
if (missingData) return;
|
||||||
|
|
||||||
|
let options;
|
||||||
if (buy.id) {
|
if (buy.id) {
|
||||||
const query = `Buys/${buy.id}`;
|
options = {
|
||||||
this.$http.patch(query, buy).then(res => {
|
query: `Buys/${buy.id}`,
|
||||||
if (!res.data) return;
|
method: 'patch'
|
||||||
|
};
|
||||||
buy = Object.assign(buy, res.data);
|
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
const query = `Entries/${this.entry.id}/addBuy`;
|
options = {
|
||||||
this.$http.post(query, buy).then(res => {
|
query: `Entries/${this.entry.id}/addBuy`,
|
||||||
|
method: 'post'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.$http[options.method](options.query, buy).then(res => {
|
||||||
if (!res.data) return;
|
if (!res.data) return;
|
||||||
|
|
||||||
buy = Object.assign(buy, res.data);
|
buy = Object.assign(buy, res.data);
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns checked instances
|
* Returns checked instances
|
||||||
|
|
Loading…
Reference in New Issue