Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@vality/domain-proto": "^2.0.1-7a97267.0",
"@vality/fistful-proto": "^2.0.1-7c61ac5.0",
"@vality/machinegun-proto": "^1.0.1-cc2c27c.0",
"@vality/magista-proto": "^2.0.2-f3b4b14.0",
"@vality/magista-proto": "^2.0.2-2de1ebf.0",
"@vality/ng-monaco-editor": "^20.0.0",
"@vality/repairer-proto": "^2.0.2-1a48729.0",
"@vality/scrooge-proto": "^0.1.1-42aba67.0",
Expand Down
3 changes: 2 additions & 1 deletion src/api/fistful-stat/query-dsl/types/withdrawal-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export interface WithdrawalParams extends PagedBaseParameters {
party_id?: string;
wallet_id?: string;
withdrawal_id?: string;
withdrawal_ids?: string;
withdrawal_ids?: string[];
identity_id?: string;
destination_id?: string;
status?: Capitalize<keyof WithdrawalStatus>;
external_id?: string;
external_ids?: string[];
amount_from?: number;
amount_to?: number;
currency_code?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,33 +429,43 @@ export class CandidatesComponent {
});
}

edit(idx: number) {
edit(candidateIdx: number) {
this.routingRulesetService.refID$
.pipe(
switchCombineWith((refId) => [
this.routingRulesService.getCandidate(refId, idx),
this.routingRulesService.getCandidate(refId, candidateIdx),
this.candidates$,
]),
first(),
switchCombineWith(([_, candidate, candidates]) => [
this.dialog
.open(EditCandidateDialogComponent, {
candidate,
othersWeight: candidates.reduce(
(acc, c, cIdx) =>
acc +
(c.priority === candidate.priority && idx !== cIdx
? c.weight || 0
: 0),
0,
),
})
.afterClosed(),
]),
switchMap(([[refId], res]) =>
switchCombineWith(([_, candidate, candidates]) => {
const others = candidates.filter(
(c) => c !== candidate && c.priority === candidate.priority && c.allowed,
);
const ids = others.map((c) => candidates.findIndex((cd) => cd === c));
return [
this.dialog
.open(EditCandidateDialogComponent, {
candidate,
others,
})
.afterClosed(),
ids,
others,
];
}),
switchMap(([[refId], res, ids]) =>
res.status === DialogResponseStatus.Success
? this.routingRulesService.updateRules([
{ refId, candidateIdx: idx, newCandidate: res.data },
{
refId,
candidateIdx: candidateIdx,
newCandidate: res.data.candidate,
},
...res.data.others.map((newCandidate, idx) => ({
refId,
candidateIdx: ids[idx],
newCandidate,
})),
])
: of(null),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
<v-input-field formControlName="description" label="Description"></v-input-field>
<div class="flex gap-2">
<v-input-field
[hintText]="'' + (weight$ | async)"
class="flex-1"
formControlName="weight"
label="Weight"
type="number"
></v-input-field>
<v-input-field
[formControl]="weightPercentControl"
class="flex-1"
formControlName="weightPercent"
label="Percent"
type="number"
></v-input-field>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { round } from 'lodash-es';
import { distinctUntilChanged, map, shareReplay } from 'rxjs';

import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
Expand Down Expand Up @@ -38,67 +35,69 @@ import {
export class EditCandidateDialogComponent
extends DialogSuperclass<
EditCandidateDialogComponent,
{ candidate: RoutingCandidate; othersWeight: number },
RoutingCandidate
{ candidate: RoutingCandidate; others: RoutingCandidate[] },
{ candidate: RoutingCandidate; others: RoutingCandidate[] }
>
implements OnInit
{
private fb = inject(FormBuilder);
private dr = inject(DestroyRef);
private othersWeight = this.dialogData.others.reduce((acc, c) => acc + (c.weight || 0), 0);

form = this.fb.nonNullable.group({
terminal: this.dialogData.candidate.terminal.id,
description: this.dialogData.candidate.description,
weight: this.dialogData.candidate.weight,
weightPercent: this.calcPercent(this.dialogData.candidate.weight),
allowed: this.dialogData.candidate.allowed,
});
percent$ = getValueChanges(this.form.controls.weight).pipe(
distinctUntilChanged(),
map((weight) => this.calcPercent(Number(weight || 0))),
shareReplay({ bufferSize: 1, refCount: true }),
);
weight$ = getValueChanges(this.form.controls.weightPercent).pipe(
distinctUntilChanged(),
map((weightPercent) => this.calcWeight(Number(weightPercent || 0))),
shareReplay({ bufferSize: 1, refCount: true }),
);
weightPercentControl = this.fb.nonNullable.control<number | null>(null);

ngOnInit() {
this.weight$.pipe(takeUntilDestroyed(this.dr)).subscribe((weight) => {
this.form.controls.weight.setValue(Math.round(weight), {
emitEvent: false,
getValueChanges(this.weightPercentControl)
.pipe(takeUntilDestroyed(this.dr))
.subscribe(() => {
this.form.controls.weight.setValue(null, {
emitEvent: false,
});
});
});
this.percent$.pipe(takeUntilDestroyed(this.dr)).subscribe((weightPercent) => {
this.form.controls.weightPercent.setValue(weightPercent, {
emitEvent: false,
getValueChanges(this.form.controls.weight)
.pipe(takeUntilDestroyed(this.dr))
.subscribe(() => {
this.weightPercentControl.setValue(null, {
emitEvent: false,
});
});
});
}

confirm() {
const { terminal, ...value } = getValue(this.form);
const { terminal, weight, ...value } = getValue(this.form);
const percent = getValue(this.weightPercentControl);
const isPercent = !!percent;
const weightNum = isPercent ? Number(percent) : Number(weight || 0);

this.closeWithSuccess({
...this.dialogData.candidate,
terminal: { id: terminal },
...value,
candidate: {
...this.dialogData.candidate,
terminal: { id: terminal },
...value,
weight: weightNum,
},
others: isPercent
? this.dialogData.others.map((c) => ({
...c,
weight:
c.weight && this.othersWeight
? Math.round(
(c.weight / this.othersWeight) *
(this.othersWeight -
(weight || 0) +
(percent
? Math.round((percent / 100) * this.othersWeight)
: 0)),
)
: 0,
}))
: this.dialogData.others,
});
}

private calcPercent(weight: number): number {
const res = this.dialogData.othersWeight
? (weight / (this.dialogData.othersWeight + weight)) * 100
: 100;
return round(Math.max(Math.min(res, 100), 0), 2);
}

private calcWeight(weightPercent: number): number {
const res = this.dialogData.othersWeight
? (weightPercent * this.dialogData.othersWeight) / (100 - weightPercent)
: weightPercent
? 1
: 0;
return round(Math.max(Math.min(res, 1_000_000), 0), 2);
}
}
6 changes: 5 additions & 1 deletion src/app/payments/payments.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
formControlName="invoice_ids"
label="Invoice and Payment Ids"
></v-list-field>
<v-input-field formControlName="external_id" label="External Id"></v-input-field>
<v-list-field
focusedHint="external_1, external_2"
formControlName="external_ids"
label="External Ids"
></v-list-field>
<cc-merchant-field formControlName="party_id"></cc-merchant-field>
<cc-shop-field formControlName="shop_ids" multiple></cc-shop-field>
<v-input-field formControlName="payment_first6" label="Card BIN"></v-input-field>
Expand Down
54 changes: 49 additions & 5 deletions src/app/payments/payments.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { endOfDay } from 'date-fns';
import { uniq } from 'lodash-es';
import isEqual from 'lodash-es/isEqual';
import { BehaviorSubject, merge, of } from 'rxjs';
import { distinctUntilChanged, map, shareReplay, startWith } from 'rxjs/operators';
import { distinctUntilChanged, map, shareReplay, startWith, switchMap } from 'rxjs/operators';

import { CommonModule } from '@angular/common';
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
Expand All @@ -11,6 +11,8 @@ import { FormsModule, NonNullableFormBuilder, ReactiveFormsModule } from '@angul
import { MatBadgeModule } from '@angular/material/badge';
import { MatButtonModule } from '@angular/material/button';

import { metadata$ } from '@vality/domain-proto';
import { DomainObject } from '@vality/domain-proto/domain';
import { StatPayment } from '@vality/magista-proto/magista';
import {
DateRange,
Expand Down Expand Up @@ -39,7 +41,10 @@ import { FailMachinesDialogComponent, Type } from '~/components/fail-machines-di
import { MerchantFieldModule } from '~/components/merchant-field/merchant-field.module';
import { PageLayoutModule } from '~/components/page-layout';
import { ShopFieldModule } from '~/components/shop-field';
import { MagistaThriftFormComponent } from '~/components/thrift-api-crud';
import {
DomainMetadataFormExtensionsService,
MagistaThriftFormComponent,
} from '~/components/thrift-api-crud';

import { DATE_RANGE_DAYS, DEBOUNCE_TIME_MS } from '../tokens';

Expand Down Expand Up @@ -84,6 +89,8 @@ export class PaymentsComponent implements OnInit {
private dateRangeDays = inject<number>(DATE_RANGE_DAYS);
private dr = inject(DestroyRef);
private debounceTimeMs = inject<number>(DEBOUNCE_TIME_MS);
private domainMetadataFormExtensionsService = inject(DomainMetadataFormExtensionsService);

isLoading$ = this.fetchPaymentsService.isLoading$;
payments$ = this.fetchPaymentsService.result$;
hasMore$ = this.fetchPaymentsService.hasMore$;
Expand All @@ -98,7 +105,7 @@ export class PaymentsComponent implements OnInit {
payment_rrn: undefined as string,
payment_email: undefined as string,
error_message: undefined as string,
external_id: undefined as string,
external_ids: [undefined as string[]],
});
otherFiltersControl = this.fb.control({
common_search_query_params: {},
Expand All @@ -117,10 +124,21 @@ export class PaymentsComponent implements OnInit {
'payment_rrn',
'error_message',
'external_id',
'external_ids',
].includes(data?.field?.name),
),
extension: () => of({ hidden: true }),
},
this.createDomainObjectsExtension(
(data) => of(data.field?.name === 'payment_terminal_id'),
'TerminalObject',
'terminal',
),
this.createDomainObjectsExtension(
(data) => of(data.field?.name === 'payment_provider_id'),
'ProviderObject',
'provider',
),
];
active$ = getValueChanges(this.filtersForm).pipe(
map((filters) =>
Expand Down Expand Up @@ -163,7 +181,7 @@ export class PaymentsComponent implements OnInit {
}

load({ filters, otherFilters, dateRange }: Filters, options?: LoadOptions) {
const { invoice_ids, party_id, shop_ids, external_id, ...paymentParams } = filters;
const { invoice_ids, party_id, shop_ids, external_ids, ...paymentParams } = filters;
const searchParams = clean({
...otherFilters,
common_search_query_params: {
Expand All @@ -174,7 +192,7 @@ export class PaymentsComponent implements OnInit {
to_time: getNoTimeZoneIsoString(endOfDay(dateRange.end)),
},
payment_params: { ...(otherFilters.payment_params || {}), ...paymentParams },
external_id,
external_ids,
invoice_ids,
});
this.fetchPaymentsService.load(searchParams, options);
Expand Down Expand Up @@ -229,4 +247,30 @@ export class PaymentsComponent implements OnInit {
createInvoiceTemplate() {
this.dialogService.open(CreateInvoiceTemplateDialogComponent);
}

private createDomainObjectsExtension(
determinant: ThriftFormExtension['determinant'],
objectType: string,
objectKey: keyof DomainObject,
convert = (v: unknown) => String(v),
): ThriftFormExtension {
return {
determinant,
extension: (...args) =>
metadata$.pipe(
switchMap((metadata) =>
this.domainMetadataFormExtensionsService
.createDomainObjectsOptionsByType(metadata, objectType, objectKey)[0]
.extension(...args),
),
map((extension) => ({
...extension,
options: extension.options?.map((o) => ({
...o,
value: convert(o.value),
})),
})),
),
};
}
}
Loading
Loading