mirror of
https://github.com/valitydev/fraudbusters-ui.git
synced 2024-11-06 08:35:18 +00:00
Ft/fb 43/history (#64)
This commit is contained in:
parent
d2b0603794
commit
bbe9fe6af7
@ -61,6 +61,7 @@ export class PaymentListsService {
|
||||
saveListsRowsFromFile(listType: ListType, file: File): Observable<any> {
|
||||
const formData: FormData = new FormData();
|
||||
formData.append('file', file, file.name);
|
||||
formData.append('listType', listType);
|
||||
return this.http.post<any>(`${this.fbPaymentReferenceEndpoint}/csv`, formData, {
|
||||
reportProgress: true,
|
||||
observe: 'events',
|
||||
|
@ -28,7 +28,7 @@ export class HistoricalInspectResultsDataComponent {
|
||||
|
||||
private initParams(event) {
|
||||
return {
|
||||
paymentId: event.paymentId,
|
||||
paymentId: event.id,
|
||||
cardToken: event.cardToken,
|
||||
shopId: event.shopId,
|
||||
partyId: event.partyId,
|
||||
|
@ -13,11 +13,11 @@
|
||||
<div class="fb-body-2" fxFlex>{{ inspectResult.payment.clientInfo.email }}</div>
|
||||
<div class="fb-body-2" fxFlex>
|
||||
<a
|
||||
*ngIf="inspectResult.checkedTemplate != 'RULE_NOT_CHECKED'"
|
||||
*ngIf="inspectResult.checkedTemplate !== 'RULE_NOT_CHECKED'"
|
||||
href="../template/{{ inspectResult.checkedTemplate }}"
|
||||
>{{ inspectResult.checkedTemplate }}</a
|
||||
>
|
||||
<div *ngIf="inspectResult.checkedTemplate == 'RULE_NOT_CHECKED'">-</div>
|
||||
<div *ngIf="inspectResult.checkedTemplate === 'RULE_NOT_CHECKED'">-</div>
|
||||
</div>
|
||||
<div class="fb-body-2" fxFlex>{{ inspectResult.ruleChecked }}</div>
|
||||
<div class="fb-body-2" fxFlex="160px">
|
||||
|
@ -69,8 +69,7 @@
|
||||
type="file"
|
||||
#fileDropRef
|
||||
id="fileDropRef"
|
||||
multiple
|
||||
(change)="prepareFilesList($event.target.files)"
|
||||
(change)="saveFileWithList($event.target.files[0])"
|
||||
/>
|
||||
<button mat-button color="accent" (click)="fileDropRef.click()">Add from CSV</button>
|
||||
<button
|
||||
|
@ -55,8 +55,8 @@ export class AddRowListComponent implements OnInit {
|
||||
this.addRowListService.removeItem(index);
|
||||
}
|
||||
|
||||
prepareFilesList(files: Array<any>): void {
|
||||
this.addRowListService.prepareFilesList(files);
|
||||
saveFileWithList(file: File): void {
|
||||
this.addRowListService.saveFileWithListRaws(this.listType, file);
|
||||
}
|
||||
|
||||
save(): void {
|
||||
|
@ -11,6 +11,8 @@ import { CsvUtilsService } from '../../../../shared/services/utils/csv-utils.ser
|
||||
import { ListType } from '../../../constants/list-type';
|
||||
import { WbListService } from '../wb-list.service';
|
||||
|
||||
const SIZE_FILE_BYTE = 2097152;
|
||||
|
||||
@Injectable()
|
||||
export class AddGreyRowListService {
|
||||
created$: Observable<string[]>;
|
||||
@ -78,7 +80,7 @@ export class AddGreyRowListService {
|
||||
|
||||
prepareFilesList(files: Array<any>): void {
|
||||
Object.values(files)
|
||||
.filter((value) => this.csvUtilsService.isValidFile(value, 'text/csv', 2097152))
|
||||
.filter((value) => this.csvUtilsService.isValidFile(value, 'text/csv', SIZE_FILE_BYTE))
|
||||
.forEach((item) =>
|
||||
this.papa.parse(item, {
|
||||
skipEmptyLines: true,
|
||||
|
@ -2,7 +2,6 @@ import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { FormBuilder, Validators } from '@angular/forms';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { Papa } from 'ngx-papaparse';
|
||||
import { EMPTY, merge, Observable, Subject } from 'rxjs';
|
||||
import { catchError, filter, shareReplay, switchMap } from 'rxjs/operators';
|
||||
|
||||
@ -17,6 +16,7 @@ export class AddRowListService {
|
||||
inProgress$: Observable<boolean>;
|
||||
forms = this.fb.array([]);
|
||||
|
||||
private loadedFile$ = new Subject<any>();
|
||||
private create$ = new Subject<ListType>();
|
||||
private errors$ = new Subject();
|
||||
|
||||
@ -24,8 +24,7 @@ export class AddRowListService {
|
||||
private fb: FormBuilder,
|
||||
private wbListService: WbListService,
|
||||
private snackBar: MatSnackBar,
|
||||
private csvUtilsService: CsvUtilsService,
|
||||
private papa: Papa
|
||||
private csvUtilsService: CsvUtilsService
|
||||
) {
|
||||
this.addItem();
|
||||
this.created$ = this.create$.pipe(
|
||||
@ -46,6 +45,23 @@ export class AddRowListService {
|
||||
filter((r) => !!r),
|
||||
shareReplay(1, 1000)
|
||||
);
|
||||
|
||||
this.loadedFile$
|
||||
.pipe(
|
||||
switchMap((value) => {
|
||||
return this.wbListService.saveListRowsFromFile(value.listType, value.file).pipe(
|
||||
catchError((error: HttpErrorResponse) => {
|
||||
this.snackBar.open(`${error.status}: ${error.message}`, 'ERROR');
|
||||
this.errors$.next();
|
||||
return EMPTY;
|
||||
})
|
||||
);
|
||||
}),
|
||||
filter((r) => !!r),
|
||||
shareReplay(1, 1000)
|
||||
)
|
||||
.subscribe({ next: () => this.snackBar.open('File success send to load', 'OK') });
|
||||
|
||||
this.created$.subscribe(() => {
|
||||
this.forms = this.fb.array([]);
|
||||
this.addItem();
|
||||
@ -72,28 +88,10 @@ export class AddRowListService {
|
||||
this.forms.removeAt(i);
|
||||
}
|
||||
|
||||
prepareFilesList(files: Array<any>): void {
|
||||
Object.values(files)
|
||||
.filter((value) => this.csvUtilsService.isValidFile(value, 'text/csv', 2097152))
|
||||
.forEach((item) =>
|
||||
this.papa.parse(item, {
|
||||
skipEmptyLines: true,
|
||||
header: true,
|
||||
complete: (results) => {
|
||||
const data = results.data;
|
||||
if (this.csvUtilsService.isValidFormatCsv(data, item, ['listName', 'value'])) {
|
||||
this.processCsv(data);
|
||||
}
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private processCsv(data): void {
|
||||
for (const item of data) {
|
||||
this.forms.push(this.createItem(item.listName, item.partyId, item.shopId, item.value));
|
||||
saveFileWithListRaws(listType: ListType, file: File): void {
|
||||
if (this.csvUtilsService.isValidFile(file, 'text/csv', 2097152)) {
|
||||
this.loadedFile$.next({ file, listType });
|
||||
}
|
||||
this.forms.patchValue(this.forms.value);
|
||||
}
|
||||
|
||||
private createItem(listName = '', partyId = '', shopId = '', value = '') {
|
||||
|
@ -5,7 +5,6 @@ import { PaymentCountInfo } from '../../../api/fb-management/swagger-codegen/mod
|
||||
import { PaymentListRecord } from '../../../api/fb-management/swagger-codegen/model/paymentListRecord';
|
||||
import { PaymentListsService } from '../../../api/payments/lists/payment-lists.service';
|
||||
import { ListType } from '../../constants/list-type';
|
||||
import { OperationType } from '../../constants/operation-type';
|
||||
import { SortOrder } from '../../constants/sort-order';
|
||||
import { HttpSearchResponse } from '../../model/http-search-response';
|
||||
|
||||
@ -49,7 +48,7 @@ export class WbListService {
|
||||
return this.paymentListsService.saveListsRows(listType, rows);
|
||||
}
|
||||
|
||||
saveListRowsFromFile(type: OperationType, listType: ListType, file: File): Observable<any> {
|
||||
saveListRowsFromFile(listType: ListType, file: File): Observable<any> {
|
||||
return this.paymentListsService.saveListsRowsFromFile(listType, file);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user