summaryrefslogtreecommitdiff
path: root/store
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-09-22 00:06:25 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-09-22 00:06:25 +0200
commitddf5c9356b9d459dededb826faa7a41f34605b72 (patch)
tree92772e3c52620a0360ee78d04ef2cef1db7b2876 /store
parent143485b07b8560d7774aabfe711fabd0efe5f9f6 (diff)
Create model
Diffstat (limited to 'store')
-rw-r--r--store/models.js28
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;
+ },
};