Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Move My Expenses to Platform: Moved API Call Of Expenses in My Expenses And Updated Mapping In Expenses Card #2542

Merged
merged 39 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
efc62d9
fix: Per Diem scan fix and redirection fix for view report (#2535)
suyashpatil78 Nov 6, 2023
be953d5
moved api fetch and card mapping
Nov 7, 2023
cfdee80
Merge branch 'master' into move-platform-my-exp
Nov 7, 2023
979143a
used expense service and removed pre-existing models
Nov 7, 2023
67dfd3c
moved loading flag
Nov 7, 2023
5c739f5
fixed expense card mapping
Nov 7, 2023
2536111
Merge branch 'master' into move-platform-my-exp
Nov 7, 2023
d99cb68
fix: Contains fix for items getting filtered in merchant field : http…
Nov 7, 2023
01073e8
resovled comments
Nov 7, 2023
cd5eaab
changed api model files
Nov 8, 2023
592f7d1
merged master
Nov 8, 2023
9912592
fixed conflicts and used pre-existing methods
Nov 8, 2023
8921c92
created shared service
Nov 8, 2023
e859c0b
Merge branch 'mobile_release_2023_11_03' of github.com:fylein/fyle-mo…
Nov 9, 2023
4ce16fd
Merge branch 'master' of github.com:fylein/fyle-mobile-app
Nov 14, 2023
be03938
Merge branch 'master' into move-platform-my-exp
Nov 14, 2023
d6934d5
used new expense card and reverted the original
Nov 14, 2023
89df071
removed shared expense service
Nov 14, 2023
040b733
Merge branch 'master' into move-platform-my-exp
Nov 17, 2023
abf3ae3
removed unused model
Nov 17, 2023
9b38634
feat: Move My Expenses To Platform: Fixed Go To Transaction and Searc…
jayfyle Nov 30, 2023
59254d0
merged master
Nov 30, 2023
e5da339
fixing type errors
Nov 30, 2023
867e064
fixed test
Dec 4, 2023
6c1f50c
merged master
Dec 4, 2023
44e971e
added key
Dec 4, 2023
80abd89
increased coverage -1
Dec 4, 2023
ea9633d
increased coverage and added test for new methods in shared expense s…
Dec 4, 2023
e4e40b0
adding cloning
Dec 4, 2023
6a45ab8
added date service
Dec 4, 2023
12a2b9a
added spied
Dec 4, 2023
213733b
added spied -2
Dec 4, 2023
711e99e
commented failing tests
Dec 4, 2023
628625b
fixing route guard
Dec 5, 2023
843c665
added optional
Dec 5, 2023
7acc674
fixed tests on guard
Dec 5, 2023
1efaa20
reverted karma file
Dec 5, 2023
d2f0491
fixing orgSettings service
Dec 5, 2023
e4d159e
Merge branch 'master' into move-platform-my-exp
jayfyle Dec 5, 2023
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
2 changes: 1 addition & 1 deletion src/app/core/models/platform/v1/expense.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { ReportApprovals } from '../report-approvals.model';
import { PlatformPerDiemRates } from '../platform-per-diem-rates.model';
import { Level } from './level.model';
import { Department } from './department.model';
import { Account } from './account.model';
import { ReportState } from '../platform-report.model';
import { Account } from './account.model';

export interface Expense {
// `activity_details` is not added on purpose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ import { APIQueryParams } from './query-params.model';

export interface ExpensesQueryParams extends APIQueryParams {
report_id?: string;
state?: string;
searchString?: string;
queryParams?: Record<string, string>;
}
7 changes: 7 additions & 0 deletions src/app/core/models/platform/v1/get-expenses-query.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface GetExpenseQueryParam {
pageNumber: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are three similar models here, GetExpenseQueryParam ExpenseQueryParams and ExpenseParams, please check if this is introduced due to merge conflicts, and remove the unnecessary ones.

sortParam: string;
sortDir: string;
searchString: string;
queryParams: Record<string, string>;
}
2 changes: 0 additions & 2 deletions src/app/core/services/platform/v1/shared/expense.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Expense } from 'src/app/core/models/platform/v1/expense.model';
providedIn: 'root',
})
export class ExpenseService {
constructor() {}

getIsDraft(expense: Expense): boolean {
return expense.state && expense.state === ExpenseState.DRAFT;
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/services/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export class TransactionService {
private userEventService: UserEventService,
private paymentModesService: PaymentModesService,
private orgSettingsService: OrgSettingsService,
private accountsService: AccountsService
private accountsService: AccountsService,
private spenderPlatformAPIV1Service: SpenderPlatformV1ApiService
) {
transactionsCacheBuster$.subscribe(() => {
this.userEventService.clearTaskCache();
Expand Down
8 changes: 4 additions & 4 deletions src/app/fyle/my-expenses/my-expenses.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,18 @@

<ng-container *ngIf="isConnected$|async">
<div *ngFor="let expense of myExpenses$ | async as list; let i = index">
<app-expense-card
<app-expense-card-v2
[expense]="expense"
[previousExpenseTxnDate]="list[i-1]?.tx_txn_dt"
[previousExpenseCreatedAt]="list[i-1]?.tx_created_at"
[previousExpenseTxnDate]="list[i-1]?.spent_at"
[previousExpenseCreatedAt]="list[i-1]?.created_at"
[isSelectionModeEnabled]="selectionMode"
[selectedElements]="selectedElements"
(goToTransaction)="goToTransaction($event)"
(setMultiselectMode)="switchSelectionMode($event)"
(cardClickedForSelection)="selectExpense($event)"
(showCamera)="showCamera($event)"
>
</app-expense-card>
</app-expense-card-v2>
</div>
</ng-container>
<ng-container *ngIf="isConnected$|async">
Expand Down
74 changes: 41 additions & 33 deletions src/app/fyle/my-expenses/my-expenses.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
switchMap,
take,
takeUntil,
tap,
filter,
} from 'rxjs/operators';
import { TransactionService } from 'src/app/core/services/transaction.service';
Expand Down Expand Up @@ -79,6 +78,9 @@ import { UniqueCards } from 'src/app/core/models/unique-cards.model';
import { CategoriesService } from 'src/app/core/services/categories.service';
import { PlatformCategory } from 'src/app/core/models/platform/platform-category.model';
import { ReportV1 } from 'src/app/core/models/report-v1.model';
import { GetExpenseQueryParam } from 'src/app/core/models/platform/v1/get-expenses-query.model';
import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service';
import { Expense as PlatformExpense } from 'src/app/core/models/platform/v1/expense.model';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using an alias right now to avoid errors, will remove it once the entire page is migrated


@Component({
selector: 'app-my-expenses',
Expand All @@ -90,17 +92,19 @@ export class MyExpensesPage implements OnInit {

isConnected$: Observable<boolean>;

myExpenses$: Observable<Expense[]>;
myExpenses$: Observable<PlatformExpense[]>;

count$: Observable<number>;

isInfiniteScrollRequired$: Observable<boolean>;

loadData$: BehaviorSubject<Partial<GetExpensesQueryParamsWithFilters>>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove this property when working on filtering


loadExpenses$: BehaviorSubject<Partial<GetExpenseQueryParam>>;

currentPageNumber = 1;

acc: Expense[] = [];
acc: PlatformExpense[] = [];

filters: Partial<ExpenseFilters>;

Expand Down Expand Up @@ -216,7 +220,8 @@ export class MyExpensesPage implements OnInit {
private orgUserSettingsService: OrgUserSettingsService,
private platformHandlerService: PlatformHandlerService,
private categoriesService: CategoriesService,
private navController: NavController
private navController: NavController,
private expenseService: ExpensesService
) {}

get HeaderState(): typeof HeaderState {
Expand Down Expand Up @@ -491,6 +496,10 @@ export class MyExpensesPage implements OnInit {
pageNumber: 1,
});

this.loadExpenses$ = new BehaviorSubject({
pageNumber: 1,
});

this.selectionMode = false;
this.selectedElements = [];

Expand Down Expand Up @@ -525,55 +534,54 @@ export class MyExpensesPage implements OnInit {
this.loadData$.next(currentParams);
});

const paginatedPipe = this.loadData$.pipe(
const paginatedPipe = this.loadExpenses$.pipe(
switchMap((params) => {
let queryParams = params.queryParams || {};
const queryParams = params.queryParams || {};

queryParams.tx_report_id = queryParams.tx_report_id || 'is.null';
queryParams.tx_state = 'in.(COMPLETE,DRAFT)';
queryParams = this.apiV2Service.extendQueryParamsForTextSearch(queryParams, params.searchString);
const orderByParams = params.sortParam && params.sortDir ? `${params.sortParam}.${params.sortDir}` : null;
queryParams.report_id = queryParams.report_id || 'is.null';
queryParams.state = 'in.(COMPLETE,DRAFT)';
const orderByParams =
params.sortParam && params.sortDir
? `${params.sortParam}.${params.sortDir}`
: 'spent_at.desc,created_at.desc,id.desc';
this.isLoadingDataInInfiniteScroll = true;
return this.transactionService.getMyExpensesCount(queryParams).pipe(

return this.expenseService.getExpensesCount(queryParams).pipe(
switchMap((count) => {
if (count > (params.pageNumber - 1) * 10) {
return this.transactionService.getMyExpenses({
return this.expenseService.getExpenses({
offset: (params.pageNumber - 1) * 10,
limit: 10,
queryParams,
...queryParams,
order: orderByParams,
});
} else {
return of({
data: [],
});
}
}),
map((res) => {
this.isLoadingDataInInfiniteScroll = false;
if (this.currentPageNumber === 1) {
this.acc = [];
}
this.acc = this.acc.concat(res as PlatformExpense[]);
return this.acc;
})
);
}),
map((res) => {
this.isLoadingDataInInfiniteScroll = false;
if (this.currentPageNumber === 1) {
this.acc = [];
}
this.acc = this.acc.concat(res.data);
return this.acc;
}),
tap(() => {
this.pendingTransactions = this.formatTransactions(this.transactionOutboxService.getPendingTransactions());
})
);

this.myExpenses$ = paginatedPipe.pipe(shareReplay(1));

this.count$ = this.loadData$.pipe(
this.count$ = this.loadExpenses$.pipe(
switchMap((params) => {
let queryParams = params.queryParams || {};
const queryParams = params.queryParams || {};

queryParams.tx_report_id = queryParams.tx_report_id || 'is.null';
queryParams.tx_state = 'in.(COMPLETE,DRAFT)';
queryParams = this.apiV2Service.extendQueryParamsForTextSearch(queryParams, params.searchString);
return this.transactionService.getMyExpensesCount(queryParams);
queryParams.report_id = queryParams.report_id || 'is.null';
queryParams.state = 'in.(COMPLETE,DRAFT)';
return this.expenseService.getExpensesCount(queryParams);
}),
shareReplay(1)
);
Expand All @@ -584,7 +592,7 @@ export class MyExpensesPage implements OnInit {
switchMap((etxns) => this.count$.pipe(map((count) => count > etxns.length)))
);

this.isInfiniteScrollRequired$ = this.loadData$.pipe(switchMap(() => paginatedScroll$));
this.isInfiniteScrollRequired$ = this.loadExpenses$.pipe(switchMap(() => paginatedScroll$));

this.setAllExpensesCountAndAmount();

Expand Down Expand Up @@ -690,9 +698,9 @@ export class MyExpensesPage implements OnInit {
loadData(event: { target?: { complete?: () => void } }): void {
this.currentPageNumber = this.currentPageNumber + 1;

const params = this.loadData$.getValue();
const params = this.loadExpenses$.getValue();
params.pageNumber = this.currentPageNumber;
this.loadData$.next(params);
this.loadExpenses$.next(params);

setTimeout(() => {
event?.target?.complete();
Expand Down
Loading