From 179c470ff9c91f8206b9e0d53d5b6563656e28b1 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 25 Sep 2022 16:16:31 +0200 Subject: Edit user --- store/users.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'store') diff --git a/store/users.js b/store/users.js index cb9b4b4..e1f6767 100644 --- a/store/users.js +++ b/store/users.js @@ -59,6 +59,32 @@ export const actions = { commit("loadingStatus", false, { root: true }); + return res; + }, + // Edit an user + async editUser({ commit, rootGetters }, payload) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/users/${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