🎉 First commit, from couchbase generator, basic changes

not tested / updated yet
This commit is contained in:
Sebastián Ramírez
2019-02-09 19:42:36 +04:00
commit 7f8bfc8faa
198 changed files with 21022 additions and 0 deletions

View File

@@ -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);
}
},
};