From ddf5c9356b9d459dededb826faa7a41f34605b72 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 22 Sep 2022 00:06:25 +0200 Subject: Create model --- store/models.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'store') 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; @@ -70,6 +70,32 @@ export const actions = { commit("loadingStatus", false, { root: true }); + 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; }, }; -- cgit v1.2.3-18-g5258