Skip to content

Commit

Permalink
feat: Move stats call in tasks to platform [1] (#2921)
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha committed May 14, 2024
1 parent 7139ab1 commit 53c7020
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 256 deletions.
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;
}
16 changes: 11 additions & 5 deletions src/app/core/services/platform/v1/approver/reports.service.spec.ts
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
6 changes: 3 additions & 3 deletions src/app/core/services/platform/v1/spender/reports.service.ts
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

0 comments on commit 53c7020

Please sign in to comment.