From 6164e98a11c2437fd6258672ad7fd636d2b66574 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 23 Sep 2022 21:04:03 +0200 Subject: Edit model using a component for the same form --- store/models.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'store') diff --git a/store/models.js b/store/models.js index 4f2297d..44dbb56 100644 --- a/store/models.js +++ b/store/models.js @@ -121,6 +121,32 @@ export const actions = { commit("loadingStatus", false, { root: true }); + return res; + }, + // Edit a model + async editModel({ commit, rootGetters }, payload) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/models/${payload.id}`, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${rootGetters["auth/accessToken"]}`, + }, + body: JSON.stringify(payload), + }) + .then(async (response) => { + res.data = await response.json(); + res.status = response.status; + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + return res; }, }; -- cgit v1.2.3-18-g5258