fit get applications (#114)

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