fit get applications (#114)
This commit is contained in:
1 parent
7c8a649047
commit
5eb453dec2
17 files changed
+113
-35
No files matched your search
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "patch",
|
||||
"comment": "fit getApplications",
|
||||
"packageName": "@acedatacloud/nexior",
|
||||
"email": "1348977728@qq.com",
|
||||
"dependentChangeType": "patch"
|
||||
}
|
||||
@@ -91,7 +91,7 @@ export default defineComponent({
|
||||
ElMessage.success(this.$t('chatdoc.message.createDocumentSuccess'));
|
||||
this.dialogVisible = false;
|
||||
this.$store.dispatch('chatdoc/getDocuments', { repositoryId: this.$route.params.repositoryId });
|
||||
this.$store.dispatch('chatdoc/getApplication');
|
||||
this.$store.dispatch('chatdoc/getApplications');
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error(this.$t('chatdoc.message.createDocumentError'));
|
||||
|
||||
@@ -101,7 +101,7 @@ export default defineComponent({
|
||||
await this.$store.dispatch('chatdoc/getService');
|
||||
},
|
||||
async onGetApplications() {
|
||||
await this.$store.dispatch('chatdoc/getApplication');
|
||||
await this.$store.dispatch('chatdoc/getApplications');
|
||||
},
|
||||
async onGetRepositories() {
|
||||
await this.$store.dispatch('chatdoc/getRepositories');
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
:application="application"
|
||||
:need-apply="needApply"
|
||||
:service="service"
|
||||
@refresh="$store.dispatch('chatdoc/getApplication')"
|
||||
@refresh="$store.dispatch('chatdoc/getApplications')"
|
||||
/>
|
||||
</div>
|
||||
<div class="dialogue">
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
:application="application"
|
||||
:need-apply="needApply"
|
||||
:service="service"
|
||||
@refresh="$store.dispatch('chatdoc/getApplication')"
|
||||
@refresh="$store.dispatch('chatdoc/getApplications')"
|
||||
/>
|
||||
</div>
|
||||
<el-row class="repositories" :gutter="15">
|
||||
@@ -93,7 +93,7 @@ export default defineComponent({
|
||||
return this.$store.state.chatdoc.repositories;
|
||||
},
|
||||
needApply() {
|
||||
return this.$store.state.chatdoc.status.getApplication === Status.Success && !this.application;
|
||||
return this.$store.state.chatdoc.status.getApplications === Status.Success && !this.application;
|
||||
},
|
||||
application() {
|
||||
return this.$store.state.chatdoc.application;
|
||||
@@ -102,7 +102,7 @@ export default defineComponent({
|
||||
return this.$store.state.chatdoc.service;
|
||||
},
|
||||
initializing() {
|
||||
return this.$store.state.chatdoc.status.getApplication === Status.Request;
|
||||
return this.$store.state.chatdoc.status.getApplications === Status.Request;
|
||||
}
|
||||
},
|
||||
async mounted() {},
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
:application="application"
|
||||
:need-apply="needApply"
|
||||
:service="service"
|
||||
@refresh="$store.dispatch('chatdoc/getApplication')"
|
||||
@refresh="$store.dispatch('chatdoc/getApplications')"
|
||||
/>
|
||||
</div>
|
||||
<div class="operations">
|
||||
@@ -99,7 +99,7 @@ export default defineComponent({
|
||||
return this.repository?.documents;
|
||||
},
|
||||
needApply() {
|
||||
return this.$store.state.chatdoc.status.getApplication === Status.Success && !this.application;
|
||||
return this.$store.state.chatdoc.status.getApplications === Status.Success && !this.application;
|
||||
},
|
||||
service() {
|
||||
return this.$store.state.chatdoc.service;
|
||||
@@ -108,7 +108,7 @@ export default defineComponent({
|
||||
return this.$store.state.chatdoc.application;
|
||||
},
|
||||
initializing() {
|
||||
return this.$store.state.chatdoc.status.getApplication === Status.Request;
|
||||
return this.$store.state.chatdoc.status.getApplications === Status.Request;
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
|
||||
@@ -53,7 +53,7 @@ export default defineComponent({
|
||||
},
|
||||
computed: {
|
||||
loading() {
|
||||
return this.$store.state.luma?.status?.getApplication === Status.Request;
|
||||
return this.$store.state.luma?.status?.getApplications === Status.Request;
|
||||
},
|
||||
service() {
|
||||
return this.$store.state.luma.service;
|
||||
@@ -65,10 +65,10 @@ export default defineComponent({
|
||||
return this.$store.state.luma.config;
|
||||
},
|
||||
initializing() {
|
||||
return this.$store.state.luma.status.getApplication === Status.Request;
|
||||
return this.$store.state.luma.status.getApplications === Status.Request;
|
||||
},
|
||||
needApply() {
|
||||
return this.$store.state.luma.status.getApplication === Status.Success && !this.application;
|
||||
return this.$store.state.luma.status.getApplications === Status.Success && !this.application;
|
||||
},
|
||||
application() {
|
||||
return this.$store.state.luma.application;
|
||||
@@ -96,7 +96,7 @@ export default defineComponent({
|
||||
},
|
||||
async onGetApplication() {
|
||||
console.debug('start onGetApplication');
|
||||
await this.$store.dispatch('luma/getApplication');
|
||||
await this.$store.dispatch('luma/getApplications');
|
||||
console.debug('end onGetApplication');
|
||||
await this.onGetTasks();
|
||||
},
|
||||
|
||||
@@ -55,7 +55,7 @@ export default defineComponent({
|
||||
},
|
||||
computed: {
|
||||
loading() {
|
||||
return this.$store.state.qrart?.status?.getApplication === Status.Request;
|
||||
return this.$store.state.qrart?.status?.getApplications === Status.Request;
|
||||
},
|
||||
service() {
|
||||
return this.$store.state.qrart.service;
|
||||
|
||||
@@ -60,7 +60,7 @@ export default defineComponent({
|
||||
},
|
||||
computed: {
|
||||
loading() {
|
||||
return this.$store.state.suno?.status?.getApplication === Status.Request;
|
||||
return this.$store.state.suno?.status?.getApplications === Status.Request;
|
||||
},
|
||||
service() {
|
||||
return this.$store.state.suno.service;
|
||||
|
||||
@@ -87,9 +87,19 @@ export const getApplications = async ({
|
||||
if (application && application?.remaining_amount) {
|
||||
console.debug('set application with Period', application);
|
||||
commit('setApplication', application);
|
||||
const credential = application?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Period', application);
|
||||
commit('setCredential', credential);
|
||||
} else if (application2) {
|
||||
console.debug('set application with Usage', application2);
|
||||
commit('setApplication', application2);
|
||||
const credential = application2?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Usage', application);
|
||||
commit('setCredential', credential);
|
||||
}
|
||||
resolve(response.data.items);
|
||||
console.debug('save applications success', response.data.items);
|
||||
|
||||
@@ -9,7 +9,8 @@ import {
|
||||
IChatdocRepository,
|
||||
ICredential,
|
||||
IService,
|
||||
Status
|
||||
Status,
|
||||
IApplicationType
|
||||
} from '@/models';
|
||||
import { chatdocOperator, applicationOperator, serviceOperator } from '@/operators';
|
||||
import { CHATDOC_SERVICE_ID } from '@/constants';
|
||||
@@ -32,29 +33,49 @@ export const setRepository = async ({ commit }: any, payload: { repository: ICha
|
||||
commit('setRepository', payload);
|
||||
};
|
||||
|
||||
export const getApplication = async ({
|
||||
export const getApplications = async ({
|
||||
commit,
|
||||
rootState,
|
||||
state
|
||||
}: ActionContext<IChatdocState, IRootState>): Promise<IApplication> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
state.status.getApplication = Status.Request;
|
||||
state,
|
||||
rootState
|
||||
}: ActionContext<IChatdocState, IRootState>): Promise<IApplication[]> => {
|
||||
console.debug('start to get applications for chatdoc');
|
||||
return new Promise((resolve, reject) => {
|
||||
state.status.getApplications = Status.Request;
|
||||
applicationOperator
|
||||
.getAll({
|
||||
user_id: rootState?.user?.id,
|
||||
service_id: CHATDOC_SERVICE_ID
|
||||
})
|
||||
.then((response) => {
|
||||
state.status.getApplication = Status.Success;
|
||||
commit('setApplication', response.data.items[0]);
|
||||
const credential = response.data.items?.[0]?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
commit('setCredential', credential);
|
||||
resolve(response.data.items[0]);
|
||||
console.debug('get applications success', response?.data);
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', response.data.items);
|
||||
// check if there is any application with 'Period' type
|
||||
const application = response.data.items?.find((application) => application?.type === IApplicationType.PERIOD);
|
||||
const application2 = response.data.items?.find((application) => application?.type === IApplicationType.USAGE);
|
||||
if (application && application?.remaining_amount) {
|
||||
console.debug('set application with Period', application);
|
||||
commit('setApplication', application);
|
||||
const credential = application?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Period', application);
|
||||
commit('setCredential', credential);
|
||||
} else if (application2) {
|
||||
console.debug('set application with Usage', application2);
|
||||
commit('setApplication', application2);
|
||||
const credential = application2?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Usage', application);
|
||||
commit('setCredential', credential);
|
||||
}
|
||||
resolve(response.data.items);
|
||||
console.debug('save applications success', response.data.items);
|
||||
})
|
||||
.catch((error) => {
|
||||
state.status.getApplication = Status.Error;
|
||||
console.error('get applications error', error);
|
||||
state.status.getApplications = Status.Error;
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -301,7 +322,7 @@ export default {
|
||||
getService,
|
||||
createRepository,
|
||||
setApplication,
|
||||
getApplication,
|
||||
getApplications,
|
||||
getRepositories,
|
||||
setCredential,
|
||||
deleteRepository,
|
||||
|
||||
@@ -7,7 +7,7 @@ export interface IChatdocState {
|
||||
credential: ICredential | undefined;
|
||||
status: {
|
||||
getService: Status;
|
||||
getApplication: Status;
|
||||
getApplications: Status;
|
||||
getRepositories: Status;
|
||||
};
|
||||
}
|
||||
@@ -9,7 +9,7 @@ export default (): IChatdocState => {
|
||||
credential: undefined,
|
||||
status: {
|
||||
getService: Status.None,
|
||||
getApplication: Status.None,
|
||||
getApplications: Status.None,
|
||||
getRepositories: Status.None
|
||||
}
|
||||
};
|
||||
|
||||
@@ -51,9 +51,19 @@ export const getApplications = async ({
|
||||
if (application && application?.remaining_amount) {
|
||||
console.debug('set application with Period', application);
|
||||
commit('setApplication', application);
|
||||
const credential = application?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Period', application);
|
||||
commit('setCredential', credential);
|
||||
} else if (application2) {
|
||||
console.debug('set application with Usage', application2);
|
||||
commit('setApplication', application2);
|
||||
const credential = application2?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Usage', application);
|
||||
commit('setCredential', credential);
|
||||
}
|
||||
resolve(response.data.items);
|
||||
console.debug('save applications success', response.data.items);
|
||||
@@ -101,7 +111,7 @@ export const getService = async ({ commit, state }: ActionContext<ILumaState, IR
|
||||
};
|
||||
|
||||
export const getTasks = async (
|
||||
{ commit, state }: ActionContext<ILumaState, IRootState>,
|
||||
{ commit, state, rootState }: ActionContext<ILumaState, IRootState>,
|
||||
{ offset, limit }: { offset?: number; limit?: number }
|
||||
): Promise<ILumaTask[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -114,7 +124,7 @@ export const getTasks = async (
|
||||
lumaOperator
|
||||
.tasks(
|
||||
{
|
||||
applicationId: state.application?.id
|
||||
userId: rootState?.user?.id
|
||||
},
|
||||
{
|
||||
token
|
||||
|
||||
@@ -63,9 +63,19 @@ export const getApplications = async ({
|
||||
if (application && application?.remaining_amount) {
|
||||
console.debug('set application with Period', application);
|
||||
commit('setApplication', application);
|
||||
const credential = application?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Period', application);
|
||||
commit('setCredential', credential);
|
||||
} else if (application2) {
|
||||
console.debug('set application with Usage', application2);
|
||||
commit('setApplication', application2);
|
||||
const credential = application2?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Usage', application);
|
||||
commit('setCredential', credential);
|
||||
}
|
||||
resolve(response.data.items);
|
||||
console.debug('save application success', response.data.items[0]);
|
||||
|
||||
@@ -51,9 +51,19 @@ export const getApplications = async ({
|
||||
if (application && application?.remaining_amount) {
|
||||
console.debug('set application with Period', application);
|
||||
commit('setApplication', application);
|
||||
const credential = application?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Period', application);
|
||||
commit('setCredential', credential);
|
||||
} else if (application2) {
|
||||
console.debug('set application with Usage', application2);
|
||||
commit('setApplication', application2);
|
||||
const credential = application2?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Usage', application);
|
||||
commit('setCredential', credential);
|
||||
}
|
||||
resolve(response.data.items);
|
||||
console.debug('save applications success', response.data.items);
|
||||
|
||||
@@ -50,9 +50,19 @@ export const getApplications = async ({
|
||||
if (application && application?.remaining_amount) {
|
||||
console.debug('set application with Period', application);
|
||||
commit('setApplication', application);
|
||||
const credential = application?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Period', application);
|
||||
commit('setCredential', credential);
|
||||
} else if (application2) {
|
||||
console.debug('set application with Usage', application2);
|
||||
commit('setApplication', application2);
|
||||
const credential = application2?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('set credential with Usage', application);
|
||||
commit('setCredential', credential);
|
||||
}
|
||||
resolve(response.data.items);
|
||||
console.debug('save applications success', response.data.items);
|
||||
|
||||
Reference in new issue
Block a user