diff options
Diffstat (limited to 'store/models.js')
-rw-r--r-- | store/models.js | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/store/models.js b/store/models.js index 23c612e..47f14b1 100644 --- a/store/models.js +++ b/store/models.js @@ -50,7 +50,7 @@ export const actions = { return res; }, // Find a model by its id - async findModal({ commit }, id) { + async findModel({ commit }, id) { commit("loadingStatus", true, { root: true }); let res = { status: 0, data: null }; let api = this.$config.api; @@ -72,4 +72,30 @@ export const actions = { return res; }, + // Create a new model + async createModel({ commit, rootGetters }, payload) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/models`, { + method: "POST", + 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; + }, }; |