Skip to content

Commit

Permalink
portalicious: fix cached transactions in payment details table (#6279)
Browse files Browse the repository at this point in the history
AB#32149
  • Loading branch information
aberonni authored Dec 12, 2024
1 parent c40b3cb commit 3cf7b8d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 71 deletions.
38 changes: 27 additions & 11 deletions interfaces/Portalicious/src/app/domains/domain-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,71 @@ export abstract class DomainApiService {
>({
path,
processResponse,
requestOptions = {},
params = {},
responseAsBlob = false,
method = 'GET',
paginateQuery,
...opts
}: {
path: Parameters<typeof DomainApiService.prototype.pathToQueryKey>[0];
processResponse?: (data: BackendDataShape) => ProcessedResponseShape;
requestOptions?: Omit<
Perform121ServiceRequestParams,
'endpoint' | 'method'
params?: Record<
string,
| boolean
| number
| readonly (boolean | number | string)[]
| Signal<
boolean | number | readonly (boolean | number | string)[] | string
>
| string
>;
responseAsBlob?: boolean;
method?: Perform121ServiceRequestParams['method'];
paginateQuery?: Signal<PaginateQuery>;
} & Partial<UndefinedInitialDataOptions<ProcessedResponseShape>>) {
return () => {
const queryKey = this.pathToQueryKey(path);
const endpoint = queryKey.join('/');
const deSignalizedParams = Object.fromEntries(
Object.entries(params).map(([key, value]) => [
key,
isSignal(value) ? value() : value,
]),
);

return queryOptions({
...opts,
queryKey: [
...queryKey,
method,
endpoint,
JSON.stringify(requestOptions),
deSignalizedParams,
responseAsBlob,
paginateQuery && paginateQuery(),
processResponse,
],
queryFn: async () => {
// eslint-disable-next-line prefer-const
let { params, ...options } = requestOptions;
let httpParams = {
...deSignalizedParams,
};

if (paginateQuery) {
const paginateQueryParams =
this.paginateQueryService.paginateQueryToHttpParamsObject(
paginateQuery(),
);

params = {
...params,
httpParams = {
...httpParams,
...paginateQueryParams,
};
}

const response =
await this.httpWrapperService.perform121ServiceRequest<BackendDataShape>(
{
...options,
params,
responseAsBlob,
httpParams,
method,
endpoint,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ export class EventApiService extends DomainApiService {
}) {
return this.generateQueryOptions<Blob>({
path: BASE_ENDPOINT(projectId),
requestOptions: {
params,
responseAsBlob: true,
},
params,
responseAsBlob: true,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ export class MetricApiService extends DomainApiService {
}) {
return this.generateQueryOptions<Blob>({
path: [...BASE_ENDPOINT(projectId), 'export-list', type],
requestOptions: {
params,
responseAsBlob: true,
},
params,
responseAsBlob: true,
});
}

Expand All @@ -53,11 +51,9 @@ export class MetricApiService extends DomainApiService {
}) {
return this.generateQueryOptions<{ data: PaymentMetricDetails[] }>({
path: [...BASE_ENDPOINT(projectId), 'export-list', ExportType.payment],
requestOptions: {
params: {
minPayment: payment,
maxPayment: payment,
},
params: {
minPayment: payment,
maxPayment: payment,
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class PaymentApiService extends DomainApiService {
method: 'POST',
endpoint: this.pathToQueryKey([...BASE_ENDPOINT(projectId)]).join('/'),
body: paymentData,
params: {
httpParams: {
...this.paginateQueryService.paginateQueryToHttpParamsObject(
paginateQuery,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ProjectApiService extends DomainApiService {
>({
method: 'POST',
endpoint: BASE_ENDPOINT,
params: {
httpParams: {
importFromKobo: true,
koboToken: token,
koboAssetId: assetId,
Expand Down Expand Up @@ -93,12 +93,10 @@ export class ProjectApiService extends DomainApiService {
AttributeWithTranslatedLabel[]
>({
path: [BASE_ENDPOINT, projectId, 'attributes'],
requestOptions: {
params: {
includeProgramRegistrationAttributes,
includeTemplateDefaultAttributes,
filterShowInPeopleAffectedTable,
},
params: {
includeProgramRegistrationAttributes,
includeTemplateDefaultAttributes,
filterShowInPeopleAffectedTable,
},
processResponse: (attributes) => {
return uniqBy(attributes, 'name').map((attribute) => {
Expand Down Expand Up @@ -210,13 +208,11 @@ export class ProjectApiService extends DomainApiService {
projectId,
'financial-service-providers/intersolve-voucher/vouchers',
],
requestOptions: {
params: {
referenceId: voucherReferenceId,
payment: paymentId.toString(),
},
responseAsBlob: true,
params: {
referenceId: voucherReferenceId,
payment: paymentId.toString(),
},
responseAsBlob: true,
});
}

Expand All @@ -235,11 +231,9 @@ export class ProjectApiService extends DomainApiService {
projectId,
'financial-service-providers/intersolve-voucher/vouchers/balance',
],
requestOptions: {
params: {
referenceId: registrationReferenceId,
payment: paymentId,
},
params: {
referenceId: registrationReferenceId,
payment: paymentId,
},
});
}
Expand All @@ -265,10 +259,8 @@ export class ProjectApiService extends DomainApiService {
}) {
return this.generateQueryOptions<Dto<ActionReturnDto>>({
path: [BASE_ENDPOINT, projectId, 'actions'],
requestOptions: {
params: {
actionType,
},
params: {
actionType,
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class RegistrationApiService extends DomainApiService {
'message',
]).join('/'),
body,
params:
httpParams:
this.paginateQueryService.paginateQueryToHttpParamsObject(
paginateQuery,
),
Expand Down Expand Up @@ -161,7 +161,7 @@ export class RegistrationApiService extends DomainApiService {
method,
endpoint,
body,
params,
httpParams: params,
},
);
}
Expand Down Expand Up @@ -213,7 +213,7 @@ export class RegistrationApiService extends DomainApiService {
return this.httpWrapperService.perform121ServiceRequest({
method: 'PATCH',
endpoint,
params: {
httpParams: {
pause: pauseStatus,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class ProjectPaymentPageComponent {
{
field: 'financialserviceprovider',
header: $localize`FSP`,
type: QueryTableColumnType.MULTISELECT,
options: this.project
.data()
.programFinancialServiceProviderConfigurations.map((config) => ({
Expand Down
27 changes: 6 additions & 21 deletions interfaces/Portalicious/src/app/services/http-wrapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {
HttpErrorResponse,
HttpHeaders,
HttpParams,
HttpParamsOptions,
HttpStatusCode,
} from '@angular/common/http';
import { inject, Injectable, isSignal, Signal } from '@angular/core';
import { inject, Injectable } from '@angular/core';

import { get } from 'lodash';
import { lastValueFrom, of } from 'rxjs';
Expand All @@ -22,14 +23,7 @@ interface PerformRequestParams {
body?: unknown;
responseAsBlob?: boolean;
isUpload?: boolean;
params?: Record<
string,
| boolean
| number
| readonly (boolean | number | string)[]
| Signal<boolean | number | readonly (boolean | number | string)[] | string>
| string
>;
httpParams?: HttpParamsOptions['fromObject'];
}

export type Perform121ServiceRequestParams = { endpoint: string } & Omit<
Expand Down Expand Up @@ -149,34 +143,25 @@ export class HttpWrapperService {
body,
responseAsBlob = false,
isUpload = false,
params,
httpParams: params,
}: PerformRequestParams): Promise<T> {
console.log(`HttpWrapperService ${method}: ${url}`, body ?? '');

const deSignalizedParams = Object.fromEntries(
Object.entries(params ?? {}).map(([key, value]) => [
key,
isSignal(value) ? value() : value,
]),
);

try {
const response = await lastValueFrom<Error | HttpErrorResponse | T>(
this.http
.request(method, url, {
headers: this.createHeaders(isUpload),
responseType: responseAsBlob ? 'blob' : undefined,
withCredentials: true,
params: new HttpParams({ fromObject: deSignalizedParams }),
params: new HttpParams({ fromObject: params }),
body,
})
.pipe(
tap((response) => {
console.log(
`HttpWrapperService ${method}: ${url}${
params
? `\nParams ${JSON.stringify(deSignalizedParams, null, 2)}`
: ''
params ? `\nParams ${JSON.stringify(params, null, 2)}` : ''
}${body ? `\nBody: ${JSON.stringify(body, null, 2)}` : ''}`,
'\nResponse:',
response,
Expand Down

0 comments on commit 3cf7b8d

Please sign in to comment.