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 stats call in tasks to platform [1] #2921

Merged
merged 74 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
9e33e2c
Minor
bistaastha Apr 18, 2024
e0851cd
Update reports.service.ts
bistaastha Apr 18, 2024
510af5d
Minor
bistaastha Apr 18, 2024
3ee6972
Minor
bistaastha Apr 19, 2024
8b6d202
Minor
bistaastha Apr 19, 2024
a4c88ba
Update reports.service.spec.ts
bistaastha Apr 19, 2024
e1a2cfe
Update reports.service.spec.ts
bistaastha Apr 19, 2024
20433c7
Update view-expense.page.ts
bistaastha Apr 19, 2024
6cd2788
Update view-mileage.page.ts
bistaastha Apr 19, 2024
0f6d646
Update view-per-diem.page.ts
bistaastha Apr 19, 2024
f0aa09b
Update reports.service.ts
bistaastha Apr 25, 2024
cafd8c3
feat: Move add expenses to platform (#2878)
bistaastha Apr 25, 2024
c2a8e74
Minor
bistaastha Apr 25, 2024
94a919d
Minor
bistaastha Apr 26, 2024
5eaefdf
Minor
bistaastha Apr 26, 2024
436ac68
Minor
bistaastha Apr 26, 2024
1943364
Update reports.service.spec.ts
bistaastha Apr 26, 2024
c6e9fcc
Update reports.service.ts
bistaastha Apr 26, 2024
597b6f4
Minor
bistaastha Apr 26, 2024
bf71e82
Mt push
bistaastha Apr 26, 2024
1272999
Update reports.service.spec.ts
bistaastha Apr 26, 2024
d51f7ad
Revert "Minor"
bistaastha Apr 26, 2024
ee8d684
Merge branch 'master' into FYLE-86cuqn6db-add-methods-to-get-reports
bistaastha Apr 26, 2024
5ce284f
Merge branch 'master' into FYLE-86cuqn6db-add-methods-to-get-reports
bistaastha Apr 26, 2024
c1fe7b0
Update reports.service.ts
bistaastha Apr 26, 2024
109fa15
Rename platform-stats-requesst-param.model.ts to platform-stats-reque…
bistaastha Apr 26, 2024
74be123
Update reports.service.ts
bistaastha Apr 26, 2024
bdb940a
Update reports.service.ts
bistaastha Apr 26, 2024
12fa61d
Update reports.service.ts
bistaastha Apr 26, 2024
b8e7994
Merge branch 'FYLE-86cuqn6db-add-methods-to-get-reports' into FYLE-86…
bistaastha Apr 26, 2024
4a812b6
Minor
bistaastha Apr 26, 2024
19cb290
Merge branch 'FYLE-86cuqn6db-add-methods-to-get-reports-approvers' of…
bistaastha Apr 26, 2024
1705f10
Minor
bistaastha Apr 26, 2024
d6614f4
Minor
bistaastha Apr 26, 2024
70482e5
Minor
bistaastha Apr 29, 2024
c7a604f
Minor
bistaastha Apr 29, 2024
c11842b
Minor
bistaastha Apr 29, 2024
f8ed65d
Minor
bistaastha Apr 29, 2024
ce1ea5d
Minor
bistaastha Apr 29, 2024
d8e2708
Update dashboard.service.spec.ts
bistaastha Apr 29, 2024
210ba44
Update dashboard.service.ts
bistaastha Apr 29, 2024
3488343
Minor
bistaastha Apr 30, 2024
3df1ea0
Minor
bistaastha Apr 30, 2024
8ace313
Minor
bistaastha Apr 30, 2024
c7eb6d7
Update tasks.service.ts
bistaastha Apr 30, 2024
97ca715
Minor
bistaastha Apr 30, 2024
951d095
Minor
bistaastha May 6, 2024
3e41fb8
Minor
bistaastha May 6, 2024
e09b877
Minor
bistaastha May 6, 2024
9c67170
Minor
bistaastha May 6, 2024
3a8d7e2
Merge branch 'FYLE-fix-reports-test-coverage' into FYLE-86cuqn6db-tasks
bistaastha May 6, 2024
7023bbf
fix: fix platform spender reports test coverage (#2950)
bistaastha May 7, 2024
1fd28ee
Minor
bistaastha May 7, 2024
a540c60
Minor
bistaastha May 7, 2024
f3f4991
Minor
bistaastha May 7, 2024
d368a85
Minor
bistaastha May 7, 2024
c6aea75
Minor
bistaastha May 7, 2024
fd01bbd
Minor
bistaastha May 7, 2024
b4aca49
Merge branch 'master' into FYLE-86cuqn6db-stats
bistaastha May 7, 2024
c6f4340
Update reports.service.spec.ts
bistaastha May 7, 2024
5aa0259
Minor
bistaastha May 7, 2024
35f7595
Merge branch 'FYLE-86cuqn6db-stats' of github.com:fylein/fyle-mobile-…
bistaastha May 7, 2024
eb3f340
Minor
bistaastha May 7, 2024
658393b
Minor
bistaastha May 7, 2024
6138be3
Minor
bistaastha May 7, 2024
0def6a0
Minor
bistaastha May 8, 2024
af1f6c1
Update reports.service.ts
bistaastha May 9, 2024
154c332
fix: Fix tests for tasks page stats changes [2] (#2928)
bistaastha May 13, 2024
d6b0150
Merge branch 'master' into FYLE-86cuqn6db-tasks
bistaastha May 13, 2024
ee2679d
fix: fix stats count call for orgs where user is not an approver
bistaastha May 14, 2024
0fbf100
Revert "fix: fix stats count call for orgs where user is not an appro…
bistaastha May 14, 2024
518256a
fix: fix stats call for orgs where user is not an approver (#2983)
bistaastha May 14, 2024
7a32e44
Merge branch 'master' into FYLE-86cuqn6db-tasks
bistaastha May 14, 2024
f705bd7
Merge branch 'master' into FYLE-86cuqn6db-tasks
bistaastha May 14, 2024
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
115 changes: 68 additions & 47 deletions src/app/core/mock-data/report-stats.data.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
import deepFreeze from 'deep-freeze-strict';

import { ReportStats } from '../models/report-stats.model';
import { PlatformReportsStatsResponse } from '../models/platform/v1/report-stats-response.model';

export const expectedReportStats: ReportStats = deepFreeze({
draft: {
count: 6,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
count: 2,
total_amount: 93165.91,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
report: {
count: 45,
count: 2,
total_amount: 5177243929.65219,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
approved: {
count: 56,
total_amount: 28758273650702.816,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
paymentPending: {
count: 4,
total_amount: 501602.12,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
processing: {
count: 7,
Expand All @@ -54,46 +55,66 @@ export const expectedEmptyReportStats: ReportStats = deepFreeze({
draft: {
total_amount: 0,
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
report: {
total_amount: 0,
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
approved: {
total_amount: 0,
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
paymentPending: {
total_amount: 0,
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
processing: {
total_amount: 0,
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
});

export const expectedSentBackResponse: PlatformReportsStatsResponse = deepFreeze({
total_amount: 4500,
count: 2,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
});

export const expectedSentBackResponseSingularReport: PlatformReportsStatsResponse = deepFreeze({
total_amount: 4500,
count: 1,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
});
22 changes: 18 additions & 4 deletions src/app/core/mock-data/task.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,24 @@ export const teamReportTaskSample = deepFreeze({
});

export const sentBackReportTaskSample = deepFreeze({
amount: '44.53',
amount: '4.5K',
count: 2,
header: 'Reports sent back!',
subheader: '2 reports worth ₹4.5K were sent back by your approver',
icon: TaskIcon.REPORT,
ctas: [
{
content: 'View Reports',
event: TASKEVENT.openSentBackReport,
},
],
});

export const sentBackReportTaskSingularSample = deepFreeze({
amount: '4.5K',
count: 1,
header: 'Report sent back!',
subheader: '1 report worth ₹44.53 was sent back by your approver',
subheader: '1 report worth ₹4.5K was sent back by your approver',
icon: TaskIcon.REPORT,
ctas: [
{
Expand Down Expand Up @@ -102,10 +116,10 @@ export const unreportedExpenseTaskSample2 = deepFreeze({
});

export const unsubmittedReportTaskSample = deepFreeze({
amount: '0.00',
amount: '93.17K',
count: 2,
header: 'Unsubmitted reports',
subheader: '2 reports remain in draft state',
subheader: '2 reports worth ₹93.17K remain in draft state',
icon: TaskIcon.REPORT,
ctas: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface PlatformStatsRequestParams {
state: string;
next_approver_user_ids?: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface ReportsStatsResponsePlatform {
export interface PlatformReportsStatsResponse {
count: number;
failed_amount: number;
failed_count: number;
Expand Down
12 changes: 6 additions & 6 deletions src/app/core/models/report-stats.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReportsStatsResponsePlatform } from './platform/v1/report-stats-response.model';
import { PlatformReportsStatsResponse } from './platform/v1/report-stats-response.model';
export interface ReportStats {
draft: ReportsStatsResponsePlatform;
report: ReportsStatsResponsePlatform;
approved: ReportsStatsResponsePlatform;
paymentPending: ReportsStatsResponsePlatform;
processing: ReportsStatsResponsePlatform;
draft: PlatformReportsStatsResponse;
report: PlatformReportsStatsResponse;
approved: PlatformReportsStatsResponse;
paymentPending: PlatformReportsStatsResponse;
processing: PlatformReportsStatsResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model';
import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model';
import { expectedReportStats } from 'src/app/core/mock-data/report-stats.data';
import { ReportState } from '../../../../models/platform/v1/report.model';

describe('ApproverReportsService', () => {
let approverReportsService: ApproverReportsService;
Expand Down Expand Up @@ -58,6 +59,15 @@ describe('ApproverReportsService', () => {
});
});

it('generateStatsQueryParams(): should generate stats query params', () => {
const queryParams = {
state: `eq.${ReportState.DRAFT}`,
};

const result = approverReportsService.generateStatsQueryParams(queryParams);
expect(result).toEqual('state=eq.DRAFT');
});

it('getReportsCount(): should get a count of reports', (done) => {
// Mock the response of getReportsByParams
spyOn(approverReportsService, 'getReportsByParams').and.returnValue(of(platformReportCountData));
Expand Down Expand Up @@ -158,14 +168,10 @@ describe('ApproverReportsService', () => {
});

it('getReportsStats(): should get advance request stats', (done) => {
const statsResponse: StatsResponse = {
count: 2,
total_amount: 1200,
};
approverPlatformApiService.post.and.returnValue(of({ data: expectedReportStats.draft }));

const params = {
state: 'eq.DRAFT',
state: `eq.${ReportState.DRAFT}`,
};

approverReportsService.getReportsStats(params).subscribe((res) => {
Expand Down
25 changes: 17 additions & 8 deletions src/app/core/services/platform/v1/approver/reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-quer
import { PAGINATION_SIZE } from 'src/app/constants';
import { Report } from 'src/app/core/models/platform/v1/report.model';
import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model';
import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model';
import { PlatformReportsStatsResponse } from 'src/app/core/models/platform/v1/report-stats-response.model';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -53,14 +53,23 @@ export class ApproverReportsService {
return this.approverPlatformApiService.get<PlatformApiResponse<Report[]>>('/reports', config);
}

getReportsStats(params: PlatformStatsRequestParams): Observable<StatsResponse> {
const queryParams = {
data: {
query_params: `state=${params.state}`,
},
};
generateStatsQueryParams(params: PlatformStatsRequestParams): string {
const paramKeys = Object.keys(params);
const queryParams = [];
paramKeys.forEach((key) => {
queryParams.push(`${key}=${params[key]}`);
});

return queryParams.join('&');
}

getReportsStats(params: PlatformStatsRequestParams): Observable<PlatformReportsStatsResponse> {
return this.approverPlatformApiService
.post<{ data: StatsResponse }>('/reports/stats', queryParams)
.post<{ data: PlatformReportsStatsResponse }>('/reports/stats', {
data: {
query_params: this.generateStatsQueryParams(params),
},
})
.pipe(map((res) => res.data));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/plat
import { CacheBuster } from 'ts-cacheable';
import { UserEventService } from '../../../user-event.service';
import { TransactionService } from '../../../transaction.service';
import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model';
import { PlatformReportsStatsResponse } from 'src/app/core/models/platform/v1/report-stats-response.model';

const reportsCacheBuster$ = new Subject<void>();

Expand Down Expand Up @@ -121,14 +121,14 @@ export class SpenderReportsService {
.pipe(map((res) => res.data));
}

getReportsStats(params: PlatformStatsRequestParams): Observable<ReportsStatsResponsePlatform> {
getReportsStats(params: PlatformStatsRequestParams): Observable<PlatformReportsStatsResponse> {
const queryParams = {
data: {
query_params: `state=${params.state}`,
},
};
return this.spenderPlatformV1ApiService
.post<{ data: ReportsStatsResponsePlatform }>('/reports/stats', queryParams)
.post<{ data: PlatformReportsStatsResponse }>('/reports/stats', queryParams)
.pipe(map((res) => res.data));
}
}
Loading
Loading