IMP-218: Navigate to party routing rules by default (#350)

This commit is contained in:
Rinat Arsaev 2024-04-16 15:11:51 +09:00 committed by GitHub
parent f426c74080
commit e590bb8ca5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 12 deletions

View File

@ -38,12 +38,12 @@ export class PartyComponent {
},
{
label: 'Payment Routing Rules',
url: 'routing-rules/payment',
url: 'routing-rules/payment/main',
services: RULESET_ROUTING_CONFIG.services,
},
{
label: 'Withdrawal Routing Rules',
url: 'routing-rules/withdrawal',
url: 'routing-rules/withdrawal/main',
services: RULESET_ROUTING_CONFIG.services,
},
].filter((item) => this.appAuthGuardService.userHasSomeServiceMethods(item.services));

View File

@ -7,7 +7,7 @@ import { first, map } from 'rxjs/operators';
import { DomainStoreService } from '@cc/app/api/domain-config';
import { RoutingRulesType } from '@cc/app/sections/routing-rules/types/routing-rules-type';
import { handleError } from '../../../../utils/operators/handle-error';
import { handleError } from '../../../../utils';
import { RoutingRulesTypeService } from '../routing-rules-type.service';
import { RoutingRulesService } from '../services/routing-rules';

View File

@ -9,6 +9,7 @@ import { DomainStoreService } from '@cc/app/api/domain-config';
import { SidenavInfoService } from '../../../shared/components/sidenav-info';
import { DomainObjectCardComponent } from '../../../shared/components/thrift-api-crud';
import { PartyDelegateRulesetsService } from '../party-delegate-rulesets';
import { RoutingRulesTypeService } from '../routing-rules-type.service';
import { AddPartyRoutingRuleDialogComponent } from './add-party-routing-rule-dialog';
@ -19,7 +20,7 @@ import { PartyRoutingRulesetService } from './party-routing-ruleset.service';
selector: 'cc-party-routing-ruleset',
templateUrl: 'party-routing-ruleset.component.html',
styleUrls: ['party-routing-ruleset.component.scss'],
providers: [PartyRoutingRulesetService, RoutingRulesTypeService],
providers: [PartyRoutingRulesetService, RoutingRulesTypeService, PartyDelegateRulesetsService],
})
export class PartyRoutingRulesetComponent {
partyRuleset$ = this.partyRoutingRulesetService.partyRuleset$;

View File

@ -1,30 +1,47 @@
import { Injectable, DestroyRef } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ActivatedRoute } from '@angular/router';
import { combineLatest, defer, Observable } from 'rxjs';
import { map, pluck, shareReplay, switchMap } from 'rxjs/operators';
import { NotifyLogService } from '@vality/ng-core';
import isNil from 'lodash-es/isNil';
import { combineLatest, defer, Observable, of } from 'rxjs';
import { map, shareReplay, switchMap, take, tap } from 'rxjs/operators';
import { createDsl, FistfulStatisticsService } from '@cc/app/api/fistful-stat';
import { PartyManagementService } from '@cc/app/api/payment-processing';
import { PartyDelegateRulesetsService } from '../party-delegate-rulesets';
import { RoutingRulesService } from '../services/routing-rules';
export const MAIN_REF = 'main';
@Injectable()
export class PartyRoutingRulesetService {
partyID$ = this.route.params.pipe(
pluck('partyID'),
map((r) => r.partyID),
takeUntilDestroyed(this.destroyRef),
shareReplay(1),
) as Observable<string>;
refID$ = this.route.params.pipe(
pluck('partyRefID'),
map((r) => +r),
map((r) => r.partyRefID),
switchMap((r) =>
r === MAIN_REF
? this.partyDelegateRulesetsService.getDelegatesWithPaymentInstitution().pipe(
take(1),
map((r) => (r.length === 1 ? r[0].partyDelegate.ruleset.id : null)),
)
: of(Number(r)),
),
tap((id) => {
if (isNaN(id) || isNil(id)) {
this.log.error('Unknown delegate');
}
}),
takeUntilDestroyed(this.destroyRef),
shareReplay(1),
);
shops$ = defer(() => this.party$).pipe(
pluck('shops'),
map((p) => p.shops),
map((shops) => Array.from(shops.values())),
);
wallets$ = defer(() => this.partyID$).pipe(
@ -33,7 +50,7 @@ export class PartyRoutingRulesetService {
dsl: createDsl({ wallets: { party_id: partyID } }),
}),
),
pluck('data', 'wallets'),
map((v) => v?.data?.wallets),
takeUntilDestroyed(this.destroyRef),
shareReplay(1),
);
@ -56,6 +73,8 @@ export class PartyRoutingRulesetService {
private routingRulesService: RoutingRulesService,
private fistfulStatistics: FistfulStatisticsService,
private destroyRef: DestroyRef,
private partyDelegateRulesetsService: PartyDelegateRulesetsService,
private log: NotifyLogService,
) {}
reload() {

View File

@ -41,7 +41,6 @@ export class RoutingRulesetComponent {
partyID$ = this.routingRulesetService.partyID$;
partyRulesetRefID$ = this.routingRulesetService.partyRulesetRefID$;
routingRulesType$ = this.route.params.pipe(map((p) => p.type)) as Observable<RoutingRulesType>;
shop$ = this.routingRulesetService.shop$;
candidates$ = this.routingRulesetService.shopRuleset$.pipe(
map((r) => r.data.decisions.candidates),
);