mirror of
https://github.com/fastapi/full-stack-fastapi-template.git
synced 2026-11-03 20:36:27 +00:00
🎉 First commit, from couchbase generator, basic changes
not tested / updated yet
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { getStoreAccessors } from 'typesafe-vuex';
|
||||
import { State } from '@/store/state';
|
||||
import { mutations } from '../mutations';
|
||||
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);
|
||||
@@ -0,0 +1,11 @@
|
||||
import { getStoreAccessors } from 'typesafe-vuex';
|
||||
import { AdminState } from '../state';
|
||||
import { State } from '@/store/state';
|
||||
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);
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './commit';
|
||||
export * from './dispatch';
|
||||
export * from './read';
|
||||
@@ -0,0 +1,10 @@
|
||||
import { getStoreAccessors } from 'typesafe-vuex';
|
||||
import { AdminState } from '../state';
|
||||
import { State } from '@/store/state';
|
||||
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);
|
||||
@@ -0,0 +1,64 @@
|
||||
import { api } from '@/api';
|
||||
import { ActionContext } from 'vuex';
|
||||
import {
|
||||
commitSetUsers,
|
||||
commitSetUser,
|
||||
commitSetRoles,
|
||||
} from './accessors/commit';
|
||||
import { IUserProfileCreate, IUserProfileUpdate } from '@/interfaces';
|
||||
import { State } from '../state';
|
||||
import { AdminState } from './state';
|
||||
import { dispatchCheckApiError, commitAddNotification, commitRemoveNotification } from '../main/accessors';
|
||||
|
||||
type MainContext = ActionContext<AdminState, State>;
|
||||
|
||||
export const actions = {
|
||||
async actionGetUsers(context: MainContext) {
|
||||
try {
|
||||
const response = await api.getUsers(context.rootState.main.token);
|
||||
if (response) {
|
||||
commitSetUsers(context, response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
await dispatchCheckApiError(context, error);
|
||||
}
|
||||
},
|
||||
async actionUpdateUser(context: MainContext, payload: { name: string, 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),
|
||||
await new Promise((resolve, reject) => setTimeout(() => resolve(), 500)),
|
||||
]))[0];
|
||||
commitSetUser(context, response.data);
|
||||
commitRemoveNotification(context, loadingNotification);
|
||||
commitAddNotification(context, {content: 'User successfully updated', color: 'success'});
|
||||
} catch (error) {
|
||||
await dispatchCheckApiError(context, error);
|
||||
}
|
||||
},
|
||||
async actionCreateUser(context: MainContext, payload: IUserProfileCreate) {
|
||||
try {
|
||||
const loadingNotification = { content: 'saving', showProgress: true };
|
||||
commitAddNotification(context, loadingNotification);
|
||||
const response = (await Promise.all([
|
||||
api.createUser(context.rootState.main.token, payload),
|
||||
await new Promise((resolve, reject) => setTimeout(() => resolve(), 500)),
|
||||
]))[0];
|
||||
commitSetUser(context, response.data);
|
||||
commitRemoveNotification(context, loadingNotification);
|
||||
commitAddNotification(context, { content: 'User successfully created', color: 'success' });
|
||||
} catch (error) {
|
||||
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);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
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);
|
||||
if (filteredUsers.length > 0) {
|
||||
return { ...filteredUsers[0] };
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import { mutations } from './mutations';
|
||||
import { getters } from './getters';
|
||||
import { actions } from './actions';
|
||||
import { AdminState } from './state';
|
||||
|
||||
const defaultState: AdminState = {
|
||||
users: [],
|
||||
roles: [],
|
||||
};
|
||||
|
||||
export const adminModule = {
|
||||
state: defaultState,
|
||||
mutations,
|
||||
actions,
|
||||
getters,
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IUserProfile } from '@/interfaces';
|
||||
import { AdminState } from './state';
|
||||
|
||||
export const mutations = {
|
||||
setUsers(state: AdminState, payload: IUserProfile[]) {
|
||||
state.users = payload;
|
||||
},
|
||||
setUser(state: AdminState, payload: IUserProfile) {
|
||||
const users = state.users.filter((user: IUserProfile) => user.name !== payload.name);
|
||||
users.push(payload);
|
||||
state.users = users;
|
||||
},
|
||||
setRoles(state: AdminState, payload: string[]) {
|
||||
state.roles = payload;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import { IUserProfile } from '@/interfaces';
|
||||
|
||||
export interface AdminState {
|
||||
users: IUserProfile[];
|
||||
roles: string[];
|
||||
}
|
||||
Reference in New Issue
Block a user