Fix auth and experience issue (#87)
Co-authored-by: Germey <germey@acedata.cloud>
This commit is contained in:
1 parent
c7c755fcd6
commit
558eadb63c
24 files changed
+235
-427
No files matched your search
+15
-14
@@ -1,7 +1,6 @@
|
||||
import { applicationOperator, chatOperator, serviceOperator } from '@/operators';
|
||||
import { IRootState } from '../common/models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IChatState } from './models';
|
||||
import { IApplication, IChatConversation, IChatModel, ICredential, IService, Status } from '@/models';
|
||||
import { CHAT_SERVICE_ID } from '@/constants';
|
||||
@@ -15,27 +14,27 @@ export const setModel = async ({ commit }: any, payload: IChatModel): Promise<vo
|
||||
};
|
||||
|
||||
export const setApplication = async ({ commit }: any, payload: IApplication): Promise<void> => {
|
||||
log(setApplication, 'set application', payload);
|
||||
console.debug('set application', payload);
|
||||
commit('setApplication', payload);
|
||||
};
|
||||
|
||||
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
|
||||
log(setService, 'set service', payload);
|
||||
console.debug('set service', payload);
|
||||
commit('setService', payload);
|
||||
};
|
||||
|
||||
export const setConversations = async ({ commit }: any, payload: IChatConversation[]): Promise<void> => {
|
||||
log(setConversations, 'set conversations', payload);
|
||||
console.debug('set conversations', payload);
|
||||
commit('setConversations', payload);
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
log(setCredential, 'set credential', payload);
|
||||
console.debug('set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
export const setConversation = async ({ commit, state }: any, payload: IChatConversation): Promise<void> => {
|
||||
log(setConversation, 'set conversation', payload);
|
||||
console.debug('set conversation', payload);
|
||||
const conversations = state.conversations || [];
|
||||
const index = conversations?.findIndex((conversation: IChatConversation) => conversation.id === payload.id);
|
||||
if (index > -1) {
|
||||
@@ -44,12 +43,12 @@ export const setConversation = async ({ commit, state }: any, payload: IChatConv
|
||||
conversations?.unshift(payload);
|
||||
}
|
||||
commit('setConversations', conversations);
|
||||
log(setConversation, 'set conversation success', conversations);
|
||||
console.debug('set conversation success', conversations);
|
||||
};
|
||||
|
||||
export const getService = async ({ commit, state }: ActionContext<IChatState, IRootState>): Promise<IService> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getService, 'start to get service for chat');
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get service for chat');
|
||||
state.status.getService = Status.Request;
|
||||
serviceOperator
|
||||
.get(CHAT_SERVICE_ID)
|
||||
@@ -70,8 +69,8 @@ export const getApplication = async ({
|
||||
state,
|
||||
rootState
|
||||
}: ActionContext<IChatState, IRootState>): Promise<IApplication> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getApplication, 'start to get application for chat');
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get application for chat');
|
||||
state.status.getApplication = Status.Request;
|
||||
applicationOperator
|
||||
.getAll({
|
||||
@@ -79,6 +78,7 @@ export const getApplication = async ({
|
||||
service_id: CHAT_SERVICE_ID
|
||||
})
|
||||
.then((response) => {
|
||||
console.debug('get application success', response?.data);
|
||||
state.status.getApplication = Status.Success;
|
||||
commit('setApplication', response.data.items[0]);
|
||||
const credential = response.data.items?.[0]?.credentials?.find(
|
||||
@@ -86,6 +86,7 @@ export const getApplication = async ({
|
||||
);
|
||||
commit('setCredential', credential);
|
||||
resolve(response.data.items[0]);
|
||||
console.debug('save application success', response.data.items[0]);
|
||||
})
|
||||
.catch((error) => {
|
||||
state.status.getApplication = Status.Error;
|
||||
@@ -98,10 +99,10 @@ export const getConversations = async ({
|
||||
commit,
|
||||
state
|
||||
}: ActionContext<IChatState, IRootState>): Promise<IChatConversation[]> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
state.status.getConversations = Status.Request;
|
||||
const credential = state.credential;
|
||||
log(getConversations, 'credential', credential);
|
||||
console.debug('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
state.status.getConversations = Status.Error;
|
||||
@@ -117,7 +118,7 @@ export const getConversations = async ({
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
log(getConversations, 'get conversations success', response.data?.items?.length);
|
||||
console.debug('get conversations success', response.data?.items?.length);
|
||||
commit('setConversations', response.data.items);
|
||||
const conversations = response.data.items;
|
||||
resolve(conversations);
|
||||
|
||||
Reference in new issue
Block a user