summaryrefslogtreecommitdiff
path: root/store
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-09-23 21:04:03 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-09-23 21:04:03 +0200
commit6164e98a11c2437fd6258672ad7fd636d2b66574 (patch)
treeca19d834b0afcf2a9ad787ad5e0310abebf3ecb9 /store
parent503fb2b362da8cf5541ac9a7fc879593e64de7f4 (diff)
Edit model using a component for the same form
Diffstat (limited to 'store')
-rw-r--r--store/models.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/store/models.js b/store/models.js
index 4f2297d..44dbb56 100644
--- a/store/models.js
+++ b/store/models.js
@@ -123,4 +123,30 @@ export const actions = {
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;
+ },
};