store/index.js   A
last analyzed

Complexity

Total Complexity 23
Complexity/F 1.05

Size

Lines of Code 86
Function Count 22

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 23
eloc 57
mnd 1
bc 1
fnc 22
dl 0
loc 86
rs 10
bpm 0.0454
cpm 1.0454
noi 2
c 0
b 0
f 0
1
  import Vuex from "vuex";
2
  import Vue from 'vue';
3
4
import moment from 'moment'
5
6
Vue.filter('formatDate', function(value) {
7
  if (value) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if value is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
8
    return moment(String(value)).format('MM/DD/YYYY hh:mm')
9
  }
10
});
11
12
export const state = () => ({
13
  person: {},
14
  people: {},
15
  chatMessages: '',
16
  role: {},
17
  permission: [],
18
});
19
20
export const getters = {
21
  getPerson: (state) => state.person,
22
  getPeople: (state) => state.people,
23
  isAuthenticated(state) {
24
    return state.auth.loggedIn
25
  },
26
27
  loggedInUser(state) {
28
    return state.auth.user
29
  },
30
  getRole: (state) => state.role,
31
  getPermission: (state) => state.permission,
32
};
33
34
export const mutations = {
35
  SET_PERSON(state, person) {
36
    state.person = person;
37
  },
38
  SET_PEOPLE(state, people) {
39
    state.people = people;
40
  },
41
  SET_ROLE(state , role) {
42
    state.role = role
43
  },
44
  SET_PERMISSION(state , permission) {
45
    state.permission = permission
46
  },
47
  SET_UNREAD_COUNT(state, count){
48
    state.auth.user.unreadMsgCount = count;
49
  }
50
};
51
52
export const actions = {
53
  loadPerson({ commit, state }, id) {
54
    const person = state.people.find(person => person.id == id)
55
    commit("SET_PERSON", person);
56
  },
57
58
  loadAccount({ commit, state }, id) {
59
    const account = state.accounts.find(account => account.id == id)
60
    commit("SET_ACCOUNT", account);
61
  },
62
  async loadPeople({ commit }) {
63
    const people = await this.$axios.$get("/api/person?start=0&length=10");
64
    commit("SET_PEOPLE", people);
65
  },
66
  async deletePeople({ commit, dispatch }, id) {
67
    this.$axios
68
      .$delete("/api/person/" + id)
69
      .then(response => ( this.$router.push('/people') )) 
0 ignored issues
show
Unused Code introduced by
The parameter response is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
70
  },
71
  async loadRole({ commit }) {
72
    const role = await this.$axios.$get("/api/roles");
73
    commit("SET_ROLE", role);
74
  },
75
  async loadPermission({ commit }) {
76
    const permission = await this.$axios.$get("/api/permissions");
77
    commit("SET_PERMISSION", permission);
78
  },
79
};
80
81
export default {
82
  state,
83
  getters,
84
  mutations,
85
  actions,
86
};
87