From d3b22d7078cea73d95c388de787f3cc906bcc1ac Mon Sep 17 00:00:00 2001 From: carlosjr Date: Wed, 28 Apr 2021 11:55:04 +0200 Subject: [PATCH] controller refactor to remove repeated code --- modules/entry/front/buy/index/index.js | 29 +++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/modules/entry/front/buy/index/index.js b/modules/entry/front/buy/index/index.js index 9f0b487b90..97c89a437b 100644 --- a/modules/entry/front/buy/index/index.js +++ b/modules/entry/front/buy/index/index.js @@ -7,23 +7,24 @@ 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 => { - if (!res.data) return; - - buy = Object.assign(buy, res.data); - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + 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!')); + }); } /**