Commit d2e71c21 authored by Ryan Diehl's avatar Ryan Diehl

fix(address): move a utility function

parent 4d4021f7
Pipeline #113592 passed with stages
in 6 minutes and 50 seconds
import { Action, createFeatureSelector, createReducer, createSelector, on } from '@ngrx/store';
import { AddressVerificationResult } from '@psu/apis/address-verification';
import { AddressVerificationResult, combineAddressResults } from '@psu/apis/address-verification';
import { ScimAddress } from '@psu/apis/models';
import {
addressVerificationSelectionCancelled,
......@@ -65,39 +65,7 @@ export const selectAddressTransformedAddresses = createSelector(
export const selectAddressVerificationCombinedResults = createSelector(
selectAddressVerificationResult,
result => {
if (!result) {
return undefined;
}
const unmodified: ScimAddress[] = [];
const invalid: ScimAddress[] = [];
const functionallyEqual: ScimAddress[] = [];
const prompted: AddressVerificationResult[] = [];
result.forEach(address => {
if (!address.addressTransformed) {
// even if not transformed, we could still need to prompt the user for invalid addresses
if (address.isValid === false) {
invalid.push(address.inputAddress);
} else {
unmodified.push(address.inputAddress);
}
} else {
if (address.functionallyEqual) {
functionallyEqual.push(address.outputAddress);
} else {
prompted.push(address);
}
}
});
return {
unmodified,
invalid,
functionallyEqual,
prompted
};
}
result => combineAddressResults(result)
);
const reducer = createReducer(
......
......@@ -46,3 +46,37 @@ export function concatSelectedAddresses(
return undefined;
}
}
export function combineAddressResults(result: AddressVerificationResult[]): AddressVerificationCombinedResults {
if (!result) {
return undefined;
}
const unmodified: ScimAddress[] = [];
const invalid: ScimAddress[] = [];
const functionallyEqual: ScimAddress[] = [];
const prompted: AddressVerificationResult[] = [];
result.forEach(address => {
if (!address.addressTransformed) {
// even if not transformed, we could still need to prompt the user for invalid addresses
if (address.isValid === false) {
invalid.push(address.inputAddress);
} else {
unmodified.push(address.inputAddress);
}
} else {
if (address.functionallyEqual) {
functionallyEqual.push(address.outputAddress);
} else {
prompted.push(address);
}
}
});
return {
unmodified,
invalid,
functionallyEqual,
prompted
};
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment