feat(core): invoice service (#8124)

This commit is contained in:
EYHN
2024-09-05 23:56:58 +08:00
committed by GitHub
parent 9cbe416c2c
commit 74cd175d37
12 changed files with 229 additions and 394 deletions

View File

@@ -5,12 +5,13 @@ import {
catchErrorInto,
effect,
Entity,
exhaustMapSwitchUntilChanged,
fromPromise,
LiveData,
onComplete,
onStart,
} from '@toeverything/infra';
import { distinctUntilChanged, EMPTY, map, mergeMap, switchMap } from 'rxjs';
import { EMPTY, map, mergeMap } from 'rxjs';
import { isBackendError, isNetworkError } from '../../cloud';
import type { WorkspaceMembersStore } from '../stores/members';
@@ -37,36 +38,38 @@ export class WorkspaceMembers extends Entity {
readonly revalidate = effect(
map(() => this.pageNum$.value),
distinctUntilChanged<number>(),
switchMap(pageNum => {
return fromPromise(async signal => {
return this.store.fetchMembers(
this.workspaceService.workspace.id,
pageNum * this.PAGE_SIZE,
this.PAGE_SIZE,
signal
exhaustMapSwitchUntilChanged(
(a, b) => a === b,
pageNum => {
return fromPromise(async signal => {
return this.store.fetchMembers(
this.workspaceService.workspace.id,
pageNum * this.PAGE_SIZE,
this.PAGE_SIZE,
signal
);
}).pipe(
mergeMap(data => {
this.memberCount$.setValue(data.memberCount);
this.pageMembers$.setValue(data.members);
return EMPTY;
}),
backoffRetry({
when: isNetworkError,
count: Infinity,
}),
backoffRetry({
when: isBackendError,
}),
catchErrorInto(this.error$),
onStart(() => {
this.pageMembers$.setValue(undefined);
this.isLoading$.setValue(true);
}),
onComplete(() => this.isLoading$.setValue(false))
);
}).pipe(
mergeMap(data => {
this.memberCount$.setValue(data.memberCount);
this.pageMembers$.setValue(data.members);
return EMPTY;
}),
backoffRetry({
when: isNetworkError,
count: Infinity,
}),
backoffRetry({
when: isBackendError,
}),
catchErrorInto(this.error$),
onStart(() => {
this.pageMembers$.setValue(undefined);
this.isLoading$.setValue(true);
}),
onComplete(() => this.isLoading$.setValue(false))
);
})
}
)
);
setPageNum(pageNum: number) {