From b1748b580d25b32ee2fab22515693ff1c7f79c8c Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 13 Oct 2022 22:26:59 +0200 Subject: Add actions --- store/users.js | 24 ++++++++++++++++++++++++ store/warnings.js | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) (limited to 'store') diff --git a/store/users.js b/store/users.js index 90e4dad..df2b596 100644 --- a/store/users.js +++ b/store/users.js @@ -143,4 +143,28 @@ export const actions = { return res; }, + // Get users + async getUsers({ commit, rootGetters }, data) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + const page = data.page ? data.page : 0; + + await fetch(`${api}/v1/users?page=${page}`, { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${rootGetters["auth/accessToken"]}`, + }, + }) + .then(async (response) => { + res.status = response.status; + res.data = await response.json(); + commit("saveUsers", res.data.results); + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + }, }; diff --git a/store/warnings.js b/store/warnings.js index 4c94459..2d3aa99 100644 --- a/store/warnings.js +++ b/store/warnings.js @@ -6,15 +6,44 @@ export const getters = { warnings: (state) => { return state.warnings; }, + count: (state) => { + return state.count; + }, }; export const mutations = { saveWarnings: (state, value) => { - state.warnings = value; + state.warnings = value.results; + state.count = value.count; }, }; export const actions = { + // Get warnings + async getWarnings({ commit, rootGetters }, page) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + await fetch(`${api}/v1/warnings?page=${page}`, { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${rootGetters["auth/accessToken"]}`, + }, + }) + .then(async (response) => { + res.status = response.status; + const data = await response.json(); + if (res.status == 200) { + commit("saveWarnings", data); + } + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + }, // Filter warnings async filterWarnings({ commit, rootGetters }, payload) { commit("loadingStatus", true, { root: true }); @@ -33,7 +62,7 @@ export const actions = { res.status = response.status; const data = await response.json(); if (res.status == 200) { - commit("saveWarnings", data.results); + commit("saveWarnings", { results: data.results }); } }) .catch((e) => { -- cgit v1.2.3-18-g5258