3
3
TransactionsGetResponse ,
4
4
IdentityGetResponse ,
5
5
InvestmentsHoldingsGetResponse ,
6
+ InvestmentsTransactionsGetResponse ,
6
7
AccountsGetResponse ,
7
8
ItemGetResponse ,
8
9
InstitutionsGetByIdResponse ,
@@ -11,6 +12,9 @@ import {
11
12
AssetReportGetResponse ,
12
13
AssetReport ,
13
14
TransferGetResponse ,
15
+ IncomeVerificationPaystubsGetResponse ,
16
+ Paystub ,
17
+ Earnings ,
14
18
} from "plaid/dist/api" ;
15
19
16
20
const formatCurrency = (
@@ -63,6 +67,12 @@ interface InvestmentsDataItem {
63
67
name : string ;
64
68
}
65
69
70
+ interface InvestmentsTransactionItem {
71
+ amount : number ;
72
+ date : string ;
73
+ name : string ;
74
+ }
75
+
66
76
interface LiabilitiessDataItem {
67
77
amount : string ;
68
78
date : string ;
@@ -98,6 +108,12 @@ interface TransferDataItem {
98
108
network : string ;
99
109
}
100
110
111
+ interface IncomePaystubsDataItem {
112
+ description : string ;
113
+ currentAmount : number | null ;
114
+ currency : number | null ;
115
+ }
116
+
101
117
export interface ErrorDataItem {
102
118
error_type : string ;
103
119
error_code : string ;
@@ -113,11 +129,13 @@ export type DataItem =
113
129
| IdentityDataItem
114
130
| BalanceDataItem
115
131
| InvestmentsDataItem
132
+ | InvestmentsTransactionItem
116
133
| LiabilitiessDataItem
117
134
| ItemDataItem
118
135
| PaymentDataItem
119
136
| AssetsDataItem
120
- | TransferDataItem ;
137
+ | TransferDataItem
138
+ | IncomePaystubsDataItem ;
121
139
122
140
export type Data = Array < DataItem > ;
123
141
@@ -216,6 +234,21 @@ export const investmentsCategories: Array<Categories> = [
216
234
} ,
217
235
] ;
218
236
237
+ export const investmentsTransactionsCategories : Array < Categories > = [
238
+ {
239
+ title : "Name" ,
240
+ field : "name" ,
241
+ } ,
242
+ {
243
+ title : "Amount" ,
244
+ field : "amount" ,
245
+ } ,
246
+ {
247
+ title : "Date" ,
248
+ field : "date" ,
249
+ } ,
250
+ ] ;
251
+
219
252
export const liabilitiesCategories : Array < Categories > = [
220
253
{
221
254
title : "Name" ,
@@ -338,6 +371,21 @@ export const transferCategories: Array<Categories> = [
338
371
} ,
339
372
] ;
340
373
374
+ export const incomePaystubsCategories : Array < Categories > = [
375
+ {
376
+ title : "Description" ,
377
+ field : "description" ,
378
+ } ,
379
+ {
380
+ title : "Current Amount" ,
381
+ field : "currentAmount" ,
382
+ } ,
383
+ {
384
+ title : "Currency" ,
385
+ field : "currency" ,
386
+ }
387
+ ]
388
+
341
389
export const transformAuthData = ( data : AuthGetResponse ) => {
342
390
return data . numbers . ach ! . map ( ( achNumbers ) => {
343
391
const account = data . accounts ! . filter ( ( a ) => {
@@ -458,10 +506,41 @@ export const transformInvestmentsData = (data: InvestmentData) => {
458
506
} ) ;
459
507
} ;
460
508
461
- export const transformLiabilitiesData = ( data : LiabilitiesGetResponse ) => {
462
- const liabilitiesData = data . liabilities ;
509
+ interface InvestmentsTransactionData {
510
+ error : null ;
511
+ investments_transactions : InvestmentsTransactionsGetResponse ;
512
+ }
513
+
514
+ export const transformInvestmentTransactionsData = ( data : InvestmentsTransactionData ) => {
515
+ const investmentTransactionsData = data . investments_transactions . investment_transactions ! . sort ( function ( a , b ) {
516
+ if ( a . account_id > b . account_id ) return 1 ;
517
+ return - 1 ;
518
+ } ) ;
519
+ return investmentTransactionsData . map ( ( investmentTransaction ) => {
520
+ const security = data . investments_transactions . securities ! . filter (
521
+ ( sec ) => sec . security_id === investmentTransaction . security_id
522
+ ) [ 0 ] ;
523
+
524
+ const obj : DataItem = {
525
+ name : security . name ! ,
526
+ amount : investmentTransaction . amount ,
527
+ date : investmentTransaction . date ,
528
+ } ;
529
+ return obj ;
530
+ } ) ;
531
+ } ;
532
+
533
+ interface LiabilitiesDataResponse {
534
+ error : null ;
535
+ liabilities : LiabilitiesGetResponse ;
536
+ }
537
+
538
+ export const transformLiabilitiesData = ( data : LiabilitiesDataResponse ) => {
539
+ const liabilitiesData = data . liabilities . liabilities ;
540
+ //console.log(liabilitiesData)
541
+ //console.log("random")
463
542
const credit = liabilitiesData . credit ! . map ( ( credit ) => {
464
- const account = data . accounts . filter (
543
+ const account = data . liabilities . accounts . filter (
465
544
( acc ) => acc . account_id === credit . account_id
466
545
) [ 0 ] ;
467
546
const obj : DataItem = {
@@ -477,7 +556,7 @@ export const transformLiabilitiesData = (data: LiabilitiesGetResponse) => {
477
556
} ) ;
478
557
479
558
const mortgages = liabilitiesData . mortgage ?. map ( ( mortgage ) => {
480
- const account = data . accounts . filter (
559
+ const account = data . liabilities . accounts . filter (
481
560
( acc ) => acc . account_id === mortgage . account_id
482
561
) [ 0 ] ;
483
562
const obj : DataItem = {
@@ -493,7 +572,7 @@ export const transformLiabilitiesData = (data: LiabilitiesGetResponse) => {
493
572
} ) ;
494
573
495
574
const student = liabilitiesData . student ?. map ( ( student ) => {
496
- const account = data . accounts . filter (
575
+ const account = data . liabilities . accounts . filter (
497
576
( acc ) => acc . account_id === student . account_id
498
577
) [ 0 ] ;
499
578
const obj : DataItem = {
@@ -598,3 +677,24 @@ export const transformAssetsData = (data: AssetResponseData) => {
598
677
} ) ;
599
678
} ) ;
600
679
} ;
680
+
681
+ interface IncomePaystub {
682
+ paystubs : IncomeVerificationPaystubsGetResponse ,
683
+ }
684
+
685
+ export const transformIncomePaystubsData = ( data : IncomePaystub ) => {
686
+ const paystubsItemsArray : Array < Paystub > = data . paystubs . paystubs
687
+ var finalArray : Array < IncomePaystubsDataItem > = [ ]
688
+ for ( var i = 0 ; i < paystubsItemsArray . length ; i ++ ) {
689
+ var ActualEarningVariable : any = paystubsItemsArray [ i ] . earnings
690
+ for ( var j = 0 ; j < ActualEarningVariable . breakdown . length ; j ++ ) {
691
+ var payStubItem : IncomePaystubsDataItem = {
692
+ description : paystubsItemsArray [ i ] . employer . name + '_' + ActualEarningVariable . breakdown [ j ] . description ,
693
+ currentAmount : ActualEarningVariable . breakdown [ j ] . current_amount ,
694
+ currency : ActualEarningVariable . breakdown [ j ] . iso_currency_code
695
+ }
696
+ finalArray . push ( payStubItem )
697
+ }
698
+ }
699
+ return finalArray
700
+ }
0 commit comments