✨ Update all for Postgres and new techniques
This commit is contained in:
@@ -5,6 +5,5 @@ import { AdminState } from '../state';
|
||||
|
||||
const {commit} = getStoreAccessors<AdminState, State>('');
|
||||
|
||||
export const commitSetRoles = commit(mutations.setRoles);
|
||||
export const commitSetUser = commit(mutations.setUser);
|
||||
export const commitSetUsers = commit(mutations.setUsers);
|
||||
|
@@ -6,6 +6,5 @@ import { actions } from '../actions';
|
||||
const {dispatch} = getStoreAccessors<AdminState, State>('');
|
||||
|
||||
export const dispatchCreateUser = dispatch(actions.actionCreateUser);
|
||||
export const dispatchGetRoles = dispatch(actions.actionGetRoles);
|
||||
export const dispatchGetUsers = dispatch(actions.actionGetUsers);
|
||||
export const dispatchUpdateUser = dispatch(actions.actionUpdateUser);
|
||||
|
@@ -6,5 +6,4 @@ import { getters } from '../getters';
|
||||
const { read } = getStoreAccessors<AdminState, State>('');
|
||||
|
||||
export const readAdminOneUser = read(getters.adminOneUser);
|
||||
export const readAdminRoles = read(getters.adminRoles);
|
||||
export const readAdminUsers = read(getters.adminUsers);
|
||||
|
@@ -3,7 +3,6 @@ import { ActionContext } from 'vuex';
|
||||
import {
|
||||
commitSetUsers,
|
||||
commitSetUser,
|
||||
commitSetRoles,
|
||||
} from './accessors/commit';
|
||||
import { IUserProfileCreate, IUserProfileUpdate } from '@/interfaces';
|
||||
import { State } from '../state';
|
||||
@@ -23,12 +22,12 @@ export const actions = {
|
||||
await dispatchCheckApiError(context, error);
|
||||
}
|
||||
},
|
||||
async actionUpdateUser(context: MainContext, payload: { name: string, user: IUserProfileUpdate }) {
|
||||
async actionUpdateUser(context: MainContext, payload: { id: number, user: IUserProfileUpdate }) {
|
||||
try {
|
||||
const loadingNotification = { content: 'saving', showProgress: true };
|
||||
commitAddNotification(context, loadingNotification);
|
||||
const response = (await Promise.all([
|
||||
api.updateUser(context.rootState.main.token, payload.name, payload.user),
|
||||
api.updateUser(context.rootState.main.token, payload.id, payload.user),
|
||||
await new Promise((resolve, reject) => setTimeout(() => resolve(), 500)),
|
||||
]))[0];
|
||||
commitSetUser(context, response.data);
|
||||
@@ -53,12 +52,4 @@ export const actions = {
|
||||
await dispatchCheckApiError(context, error);
|
||||
}
|
||||
},
|
||||
async actionGetRoles(context: MainContext) {
|
||||
try {
|
||||
const response = await api.getRoles(context.rootState.main.token);
|
||||
commitSetRoles(context, response.data.roles);
|
||||
} catch (error) {
|
||||
await dispatchCheckApiError(context, error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@@ -2,9 +2,8 @@ import { AdminState } from './state';
|
||||
|
||||
export const getters = {
|
||||
adminUsers: (state: AdminState) => state.users,
|
||||
adminRoles: (state: AdminState) => state.roles,
|
||||
adminOneUser: (state: AdminState) => (name: string) => {
|
||||
const filteredUsers = state.users.filter((user) => user.name === name);
|
||||
adminOneUser: (state: AdminState) => (userId: number) => {
|
||||
const filteredUsers = state.users.filter((user) => user.id === userId);
|
||||
if (filteredUsers.length > 0) {
|
||||
return { ...filteredUsers[0] };
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import { AdminState } from './state';
|
||||
|
||||
const defaultState: AdminState = {
|
||||
users: [],
|
||||
roles: [],
|
||||
};
|
||||
|
||||
export const adminModule = {
|
||||
|
@@ -6,11 +6,8 @@ export const mutations = {
|
||||
state.users = payload;
|
||||
},
|
||||
setUser(state: AdminState, payload: IUserProfile) {
|
||||
const users = state.users.filter((user: IUserProfile) => user.name !== payload.name);
|
||||
const users = state.users.filter((user: IUserProfile) => user.id !== payload.id);
|
||||
users.push(payload);
|
||||
state.users = users;
|
||||
},
|
||||
setRoles(state: AdminState, payload: string[]) {
|
||||
state.roles = payload;
|
||||
},
|
||||
};
|
||||
|
@@ -2,5 +2,4 @@ import { IUserProfile } from '@/interfaces';
|
||||
|
||||
export interface AdminState {
|
||||
users: IUserProfile[];
|
||||
roles: string[];
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@ import {
|
||||
commitAddNotification,
|
||||
} from './accessors';
|
||||
import { AxiosError } from 'axios';
|
||||
import { IUserProfileCreate, IUserProfileUpdate } from '@/interfaces';
|
||||
import { State } from '../state';
|
||||
import { MainState, AppNotification } from './state';
|
||||
|
||||
|
@@ -4,7 +4,7 @@ export const getters = {
|
||||
hasAdminAccess: (state: MainState) => {
|
||||
return (
|
||||
state.userProfile &&
|
||||
state.userProfile.admin_roles.includes('superuser'));
|
||||
state.userProfile.is_superuser && state.userProfile.is_active);
|
||||
},
|
||||
loginError: (state: MainState) => state.logInError,
|
||||
dashboardShowDrawer: (state: MainState) => state.dashboardShowDrawer,
|
||||
|
Reference in New Issue
Block a user