@@ -11,7 +11,7 @@ export function coerceToNumber(numericStrings) {
11
11
numericStrings
12
12
// filter out blank strings and undefined, which aren't meaningfully
13
13
// coercible in CRM
14
- . filter ( stringish => stringish !== "" && stringish !== undefined )
14
+ . filter ( stringish => stringish !== '' && stringish !== undefined )
15
15
. map ( stringish => {
16
16
// smelly; but let's prefer actual null
17
17
// coercing 'null' turns to 0, which we don't
@@ -21,7 +21,7 @@ export function coerceToNumber(numericStrings) {
21
21
// Coercing an empty string into a number returns
22
22
// NaN, which, although a number, is a Double in CRM
23
23
// which typically expects an Int
24
- if ( stringish === "" ) return stringish ;
24
+ if ( stringish === '' ) return stringish ;
25
25
26
26
return Number ( stringish ) ;
27
27
} )
@@ -39,25 +39,44 @@ export function mapInLookup(arrayOfStrings, lookupHash) {
39
39
}
40
40
41
41
export function all ( ...statements ) : string {
42
- return statements . filter ( Boolean ) . join ( " and " ) ;
42
+ const femaFloodZoneFilters = statements . filter ( statement => {
43
+ if ( statement . includes ( 'femafloodzone' ) && statement . includes ( 'true' ) )
44
+ return statement ;
45
+ } ) ;
46
+ const filters = statements . filter ( statement => {
47
+ if ( ! statement . includes ( 'femafloodzone' ) ) return statement ;
48
+ } ) ;
49
+
50
+ if ( femaFloodZoneFilters . length > 0 ) {
51
+ const femaFilterString = femaFloodZoneFilters . join ( ' and ' ) ;
52
+ const filterString = filters . filter ( Boolean ) . join ( ' and ' ) ;
53
+
54
+ const allStatements = filterString . concat (
55
+ ' and ' ,
56
+ `((${ femaFilterString } ))`
57
+ ) ;
58
+ return allStatements ;
59
+ }
60
+
61
+ return statements . filter ( Boolean ) . join ( ' and ' ) ;
43
62
}
44
63
45
64
export function any ( ...statements ) : string {
46
- return `(${ statements . join ( " or " ) } )` ;
65
+ return `(${ statements . join ( ' or ' ) } )` ;
47
66
}
48
67
49
68
export function comparisonOperator ( propertyName , operator , value ) {
50
69
let typeSafeValue = value ;
51
70
52
- if ( typeof value === " string" ) {
53
- if ( value !== " false" && value !== " true" ) {
71
+ if ( typeof value === ' string' ) {
72
+ if ( value !== ' false' && value !== ' true' ) {
54
73
typeSafeValue = `'${ value } '` ;
55
74
}
56
75
}
57
76
58
77
// most likely means it's a date. we want the date formatting that
59
78
// json stringify provides.
60
- if ( typeof value === " object" ) {
79
+ if ( typeof value === ' object' ) {
61
80
const stringyDate = JSON . stringify ( value ) . replace ( / " / g, "'" ) ;
62
81
63
82
typeSafeValue = `${ stringyDate } ` ;
@@ -72,22 +91,22 @@ export function containsString(propertyName, string) {
72
91
73
92
export function equalsAnyOf ( propertyName , strings = [ ] ) {
74
93
const querySegment = strings
75
- . map ( string => comparisonOperator ( propertyName , "eq" , string ) )
76
- . join ( " or " ) ;
94
+ . map ( string => comparisonOperator ( propertyName , 'eq' , string ) )
95
+ . join ( ' or ' ) ;
77
96
78
97
// Empty parenthases are invalid
79
- return querySegment ? `(${ querySegment } )` : "" ;
98
+ return querySegment ? `(${ querySegment } )` : '' ;
80
99
}
81
100
82
101
export function containsAnyOf ( propertyName , strings = [ ] , options ?) {
83
- const { childEntity = "" , comparisonStrategy = containsString , not = false } =
102
+ const { childEntity = '' , comparisonStrategy = containsString , not = false } =
84
103
options || { } ;
85
104
86
105
const containsQuery = strings
87
106
. map ( ( string , i ) => {
88
107
// in odata syntax, this character o is a variable for scoping
89
108
// logic for related entities. it needs to only appear once.
90
- const lambdaScope = childEntity && i === 0 ? `${ childEntity } :` : "" ;
109
+ const lambdaScope = childEntity && i === 0 ? `${ childEntity } :` : '' ;
91
110
const lambdaScopedProperty = childEntity
92
111
? `${ childEntity } /${ propertyName } `
93
112
: propertyName ;
@@ -97,18 +116,18 @@ export function containsAnyOf(propertyName, strings = [], options?) {
97
116
string
98
117
) } `;
99
118
} )
100
- . join ( " or " ) ;
101
- const lambdaQueryPrefix = childEntity ? `${ childEntity } /any` : "" ;
119
+ . join ( ' or ' ) ;
120
+ const lambdaQueryPrefix = childEntity ? `${ childEntity } /any` : '' ;
102
121
103
- return `(${ not ? " not " : "" } ${ lambdaQueryPrefix } (${ containsQuery } ))` ;
122
+ return `(${ not ? ' not ' : '' } ${ lambdaQueryPrefix } (${ containsQuery } ))` ;
104
123
}
105
124
106
125
export const dateParser = function ( key , value ) {
107
- if ( typeof value === " string" ) {
126
+ if ( typeof value === ' string' ) {
108
127
// YYYY-MM-DDTHH:mm:ss.sssZ => parsed as UTC
109
128
// YYYY-MM-DD => parsed as local date
110
129
111
- if ( value != "" ) {
130
+ if ( value != '' ) {
112
131
const a = / ^ ( \d { 4 } ) - ( \d { 2 } ) - ( \d { 2 } ) T ( \d { 2 } ) : ( \d { 2 } ) : ( \d { 2 } (?: \. \d * ) ? ) Z $ / . exec (
113
132
value
114
133
) ;
@@ -148,7 +167,7 @@ export const dateParser = function(key, value) {
148
167
return value ;
149
168
} ;
150
169
151
- const COMMUNITY_DISPLAY_TOKEN = " @OData.Community.Display.V1.FormattedValue" ;
170
+ const COMMUNITY_DISPLAY_TOKEN = ' @OData.Community.Display.V1.FormattedValue' ;
152
171
153
172
// CRM provides numeric codes for picklist types
154
173
// for example, "yes" might appear as "1"
@@ -161,7 +180,7 @@ export function overwriteCodesWithLabels(records, targetFields) {
161
180
// parent record
162
181
Object . keys ( record )
163
182
. filter ( key => key . includes ( COMMUNITY_DISPLAY_TOKEN ) )
164
- . map ( key => key . replace ( COMMUNITY_DISPLAY_TOKEN , "" ) )
183
+ . map ( key => key . replace ( COMMUNITY_DISPLAY_TOKEN , '' ) )
165
184
. forEach ( key => {
166
185
if ( targetFields . includes ( key ) ) {
167
186
newRecord [ key ] = record [ `${ key } ${ COMMUNITY_DISPLAY_TOKEN } ` ] ;
@@ -182,7 +201,7 @@ export function overwriteCodesWithLabels(records, targetFields) {
182
201
183
202
Object . keys ( record )
184
203
. filter ( key => key . includes ( COMMUNITY_DISPLAY_TOKEN ) )
185
- . map ( key => key . replace ( COMMUNITY_DISPLAY_TOKEN , "" ) )
204
+ . map ( key => key . replace ( COMMUNITY_DISPLAY_TOKEN , '' ) )
186
205
. forEach ( key => {
187
206
if ( targetFields . includes ( key ) ) {
188
207
newRecord [ key ] = record [ `${ key } ${ COMMUNITY_DISPLAY_TOKEN } ` ] ;
0 commit comments