@servicetitan/acquisition-functions 0.11.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/filter-fetcher/calc-filter-count.js +51 -65
- package/dist/filter-fetcher/index.js +28 -37
- package/dist/fix-property-use/index.js +43 -43
- package/dist/index.js +16 -30
- package/dist/property-assessorlastsaledate-converter/index.js +45 -42
- package/dist/types.d.ts +2 -2
- package/dist/types.js +1 -2
- package/dist/utils/utils.js +14 -23
- package/dist/zip-processor.d.ts +1 -1
- package/dist/zip-processor.js +20 -23
- package/package.json +2 -2
- package/dist/__tests__/assessorlastsaledate-converter.test.js +0 -79
- package/dist/__tests__/filter-fetcher.test.js +0 -92
- package/dist/__tests__/mock.js +0 -476
- package/dist/__tests__/property-fix-use-group.test.js +0 -63
- package/dist/__tests__/setup.js +0 -39
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.calculateFilterCount = void 0;
|
|
4
|
-
const utils_1 = require("../utils/utils");
|
|
5
|
-
const calculateFilterCount = (properties, filtersToIgnore) => {
|
|
1
|
+
import { UNKNOWN, SEPARATOR_CHARACTER, FilterNameValidator, capitalizeFirstLetter } from '../utils/utils';
|
|
2
|
+
export const calculateFilterCount = (properties, filtersToIgnore)=>{
|
|
6
3
|
const filterCount = {
|
|
7
4
|
propertyusegroup: {},
|
|
8
5
|
propertyusestandardized: {},
|
|
@@ -10,89 +7,79 @@ const calculateFilterCount = (properties, filtersToIgnore) => {
|
|
|
10
7
|
hvacheatingdetail: {},
|
|
11
8
|
utilitieswatersource: {},
|
|
12
9
|
utilitiessewageusage: {},
|
|
13
|
-
flooringmaterialprimary: {}
|
|
10
|
+
flooringmaterialprimary: {}
|
|
14
11
|
};
|
|
15
|
-
const { isValidFilterName } =
|
|
16
|
-
properties
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
isValidFilterName(p.propertyusegroup.toLowerCase())) {
|
|
30
|
-
const propertyUseKey = p.propertyusestandardized + utils_1.SEPARATOR_CHARACTER + p.propertyusegroup;
|
|
31
|
-
filterCount.propertyusestandardized[propertyUseKey] =
|
|
32
|
-
filterCount.propertyusestandardized[propertyUseKey] || 0;
|
|
12
|
+
const { isValidFilterName } = FilterNameValidator(filtersToIgnore, UNKNOWN);
|
|
13
|
+
properties.map((p)=>({
|
|
14
|
+
...p,
|
|
15
|
+
propertyusegroup: capitalizeFirstLetter(p.propertyusegroup),
|
|
16
|
+
propertyusestandardized: capitalizeFirstLetter(p.propertyusestandardized),
|
|
17
|
+
hvaccoolingdetail: capitalizeFirstLetter(p.hvaccoolingdetail),
|
|
18
|
+
hvacheatingdetail: capitalizeFirstLetter(p.hvacheatingdetail),
|
|
19
|
+
utilitieswatersource: capitalizeFirstLetter(p.utilitieswatersource),
|
|
20
|
+
utilitiessewageusage: capitalizeFirstLetter(p.utilitiessewageusage),
|
|
21
|
+
flooringmaterialprimary: capitalizeFirstLetter(p.flooringmaterialprimary)
|
|
22
|
+
})).forEach((p)=>{
|
|
23
|
+
if (isValidFilterName(p.propertyusestandardized.toLowerCase()) && isValidFilterName(p.propertyusegroup.toLowerCase())) {
|
|
24
|
+
const propertyUseKey = p.propertyusestandardized + SEPARATOR_CHARACTER + p.propertyusegroup;
|
|
25
|
+
filterCount.propertyusestandardized[propertyUseKey] = filterCount.propertyusestandardized[propertyUseKey] || 0;
|
|
33
26
|
filterCount.propertyusestandardized[propertyUseKey] += 1;
|
|
34
|
-
filterCount.propertyusegroup[p.propertyusegroup] =
|
|
35
|
-
filterCount.propertyusegroup[p.propertyusegroup] || 0;
|
|
27
|
+
filterCount.propertyusegroup[p.propertyusegroup] = filterCount.propertyusegroup[p.propertyusegroup] || 0;
|
|
36
28
|
filterCount.propertyusegroup[p.propertyusegroup] += 1;
|
|
37
29
|
}
|
|
38
30
|
if (isValidFilterName(p.hvaccoolingdetail.toLowerCase())) {
|
|
39
|
-
filterCount.hvaccoolingdetail[p.hvaccoolingdetail] =
|
|
40
|
-
filterCount.hvaccoolingdetail[p.hvaccoolingdetail] || 0;
|
|
31
|
+
filterCount.hvaccoolingdetail[p.hvaccoolingdetail] = filterCount.hvaccoolingdetail[p.hvaccoolingdetail] || 0;
|
|
41
32
|
filterCount.hvaccoolingdetail[p.hvaccoolingdetail] += 1;
|
|
42
33
|
}
|
|
43
34
|
if (isValidFilterName(p.hvacheatingdetail.toLowerCase())) {
|
|
44
|
-
filterCount.hvacheatingdetail[p.hvacheatingdetail] =
|
|
45
|
-
filterCount.hvacheatingdetail[p.hvacheatingdetail] || 0;
|
|
35
|
+
filterCount.hvacheatingdetail[p.hvacheatingdetail] = filterCount.hvacheatingdetail[p.hvacheatingdetail] || 0;
|
|
46
36
|
filterCount.hvacheatingdetail[p.hvacheatingdetail] += 1;
|
|
47
37
|
}
|
|
48
38
|
if (isValidFilterName(p.utilitieswatersource.toLowerCase())) {
|
|
49
|
-
filterCount.utilitieswatersource[p.utilitieswatersource] =
|
|
50
|
-
filterCount.utilitieswatersource[p.utilitieswatersource] || 0;
|
|
39
|
+
filterCount.utilitieswatersource[p.utilitieswatersource] = filterCount.utilitieswatersource[p.utilitieswatersource] || 0;
|
|
51
40
|
filterCount.utilitieswatersource[p.utilitieswatersource] += 1;
|
|
52
41
|
}
|
|
53
42
|
if (isValidFilterName(p.utilitiessewageusage.toLowerCase())) {
|
|
54
|
-
filterCount.utilitiessewageusage[p.utilitiessewageusage] =
|
|
55
|
-
filterCount.utilitiessewageusage[p.utilitiessewageusage] || 0;
|
|
43
|
+
filterCount.utilitiessewageusage[p.utilitiessewageusage] = filterCount.utilitiessewageusage[p.utilitiessewageusage] || 0;
|
|
56
44
|
filterCount.utilitiessewageusage[p.utilitiessewageusage] += 1;
|
|
57
45
|
}
|
|
58
46
|
if (isValidFilterName(p.flooringmaterialprimary.toLowerCase())) {
|
|
59
|
-
filterCount.flooringmaterialprimary[p.flooringmaterialprimary] =
|
|
60
|
-
filterCount.flooringmaterialprimary[p.flooringmaterialprimary] || 0;
|
|
47
|
+
filterCount.flooringmaterialprimary[p.flooringmaterialprimary] = filterCount.flooringmaterialprimary[p.flooringmaterialprimary] || 0;
|
|
61
48
|
filterCount.flooringmaterialprimary[p.flooringmaterialprimary] += 1;
|
|
62
49
|
}
|
|
63
50
|
});
|
|
64
|
-
const propertyusegroupCounts = Object.keys(filterCount.propertyusegroup).map(name
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const propertyusestandardizedCounts = Object.keys(filterCount.propertyusestandardized).map(key
|
|
69
|
-
const [name, groupName] = key.split(
|
|
51
|
+
const propertyusegroupCounts = Object.keys(filterCount.propertyusegroup).map((name)=>({
|
|
52
|
+
name,
|
|
53
|
+
count: filterCount.propertyusegroup[name]
|
|
54
|
+
}));
|
|
55
|
+
const propertyusestandardizedCounts = Object.keys(filterCount.propertyusestandardized).map((key)=>{
|
|
56
|
+
const [name, groupName] = key.split(SEPARATOR_CHARACTER);
|
|
70
57
|
return {
|
|
71
58
|
name,
|
|
72
59
|
groupName,
|
|
73
|
-
count: filterCount.propertyusestandardized[key]
|
|
60
|
+
count: filterCount.propertyusestandardized[key]
|
|
74
61
|
};
|
|
75
62
|
});
|
|
76
|
-
const hvaccoolingdetailCounts = Object.keys(filterCount.hvaccoolingdetail).map(name
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const flooringmaterialprimaryCounts = Object.keys(filterCount.flooringmaterialprimary).map(name
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const hvacheatingdetailCounts = Object.keys(filterCount.hvacheatingdetail).map(name
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const utilitieswatersourceCounts = Object.keys(filterCount.utilitieswatersource).map(name
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const utilitiessewageusageCounts = Object.keys(filterCount.utilitiessewageusage).map(name
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
63
|
+
const hvaccoolingdetailCounts = Object.keys(filterCount.hvaccoolingdetail).map((name)=>({
|
|
64
|
+
name,
|
|
65
|
+
count: filterCount.hvaccoolingdetail[name]
|
|
66
|
+
}));
|
|
67
|
+
const flooringmaterialprimaryCounts = Object.keys(filterCount.flooringmaterialprimary).map((name)=>({
|
|
68
|
+
name,
|
|
69
|
+
count: filterCount.flooringmaterialprimary[name]
|
|
70
|
+
}));
|
|
71
|
+
const hvacheatingdetailCounts = Object.keys(filterCount.hvacheatingdetail).map((name)=>({
|
|
72
|
+
name,
|
|
73
|
+
count: filterCount.hvacheatingdetail[name]
|
|
74
|
+
}));
|
|
75
|
+
const utilitieswatersourceCounts = Object.keys(filterCount.utilitieswatersource).map((name)=>({
|
|
76
|
+
name,
|
|
77
|
+
count: filterCount.utilitieswatersource[name]
|
|
78
|
+
}));
|
|
79
|
+
const utilitiessewageusageCounts = Object.keys(filterCount.utilitiessewageusage).map((name)=>({
|
|
80
|
+
name,
|
|
81
|
+
count: filterCount.utilitiessewageusage[name]
|
|
82
|
+
}));
|
|
96
83
|
return {
|
|
97
84
|
propertyusegroupCounts,
|
|
98
85
|
propertyusestandardizedCounts,
|
|
@@ -100,7 +87,6 @@ const calculateFilterCount = (properties, filtersToIgnore) => {
|
|
|
100
87
|
hvacheatingdetailCounts,
|
|
101
88
|
utilitieswatersourceCounts,
|
|
102
89
|
utilitiessewageusageCounts,
|
|
103
|
-
flooringmaterialprimaryCounts
|
|
90
|
+
flooringmaterialprimaryCounts
|
|
104
91
|
};
|
|
105
92
|
};
|
|
106
|
-
exports.calculateFilterCount = calculateFilterCount;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getFilterFetcherProcessor = void 0;
|
|
4
|
-
const calc_filter_count_1 = require("./calc-filter-count");
|
|
5
|
-
function getFilterFetcherProcessor(db) {
|
|
1
|
+
import { calculateFilterCount } from './calc-filter-count';
|
|
2
|
+
export function getFilterFetcherProcessor(db) {
|
|
6
3
|
let invalidFilters;
|
|
7
4
|
let fetchInvalidFiltersInProgress = null;
|
|
8
|
-
const getFiltersCollection = async ()
|
|
5
|
+
const getFiltersCollection = async ()=>{
|
|
9
6
|
return db.collection('filters');
|
|
10
7
|
};
|
|
11
|
-
const deleteZipFilter = async (zip)
|
|
8
|
+
const deleteZipFilter = async (zip)=>{
|
|
12
9
|
const collection = await getFiltersCollection();
|
|
13
|
-
return collection.deleteOne({
|
|
10
|
+
return collection.deleteOne({
|
|
11
|
+
zipcode: zip
|
|
12
|
+
});
|
|
14
13
|
};
|
|
15
|
-
const addZipFilters = async ({ zip, propertyusegroupCounts, propertyusestandardizedCounts, hvaccoolingdetailCounts, hvacheatingdetailCounts, utilitieswatersourceCounts, utilitiessewageusageCounts, flooringmaterialprimaryCounts
|
|
14
|
+
const addZipFilters = async ({ zip, propertyusegroupCounts, propertyusestandardizedCounts, hvaccoolingdetailCounts, hvacheatingdetailCounts, utilitieswatersourceCounts, utilitiessewageusageCounts, flooringmaterialprimaryCounts })=>{
|
|
16
15
|
const collection = await getFiltersCollection();
|
|
17
16
|
return collection.insertOne({
|
|
18
17
|
zipcode: zip,
|
|
@@ -22,13 +21,13 @@ function getFilterFetcherProcessor(db) {
|
|
|
22
21
|
hvacheatingdetail: hvacheatingdetailCounts,
|
|
23
22
|
utilitieswatersource: utilitieswatersourceCounts,
|
|
24
23
|
utilitiessewageusage: utilitiessewageusageCounts,
|
|
25
|
-
flooringmaterialprimary: flooringmaterialprimaryCounts
|
|
24
|
+
flooringmaterialprimary: flooringmaterialprimaryCounts
|
|
26
25
|
});
|
|
27
26
|
};
|
|
28
|
-
const getProperties = (zip)
|
|
29
|
-
return db
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const getProperties = (zip)=>{
|
|
28
|
+
return db.collection('properties').find({
|
|
29
|
+
zipcode: zip
|
|
30
|
+
}, {
|
|
32
31
|
projection: {
|
|
33
32
|
zipcode: 1,
|
|
34
33
|
propertyusegroup: 1,
|
|
@@ -38,29 +37,23 @@ function getFilterFetcherProcessor(db) {
|
|
|
38
37
|
utilitieswatersource: 1,
|
|
39
38
|
utilitiessewageusage: 1,
|
|
40
39
|
flooringmaterialprimary: 1,
|
|
41
|
-
_id: 0
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
.toArray();
|
|
40
|
+
_id: 0
|
|
41
|
+
}
|
|
42
|
+
}).toArray();
|
|
45
43
|
};
|
|
46
|
-
const getInvalidFilters = async ()
|
|
44
|
+
const getInvalidFilters = async ()=>{
|
|
47
45
|
if (invalidFilters !== undefined) {
|
|
48
46
|
return invalidFilters;
|
|
49
47
|
}
|
|
50
48
|
if (!fetchInvalidFiltersInProgress) {
|
|
51
|
-
fetchInvalidFiltersInProgress = db
|
|
52
|
-
.collection('badFilters')
|
|
53
|
-
.find({}, {
|
|
49
|
+
fetchInvalidFiltersInProgress = db.collection('badFilters').find({}, {
|
|
54
50
|
projection: {
|
|
55
51
|
_id: 0,
|
|
56
|
-
name: 1
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
.
|
|
60
|
-
|
|
61
|
-
invalidFilters = results.map(doc => doc.name);
|
|
62
|
-
})
|
|
63
|
-
.finally(() => {
|
|
52
|
+
name: 1
|
|
53
|
+
}
|
|
54
|
+
}).toArray().then((results)=>{
|
|
55
|
+
invalidFilters = results.map((doc)=>doc.name);
|
|
56
|
+
}).finally(()=>{
|
|
64
57
|
fetchInvalidFiltersInProgress = null;
|
|
65
58
|
});
|
|
66
59
|
}
|
|
@@ -72,7 +65,7 @@ function getFilterFetcherProcessor(db) {
|
|
|
72
65
|
requests: 0,
|
|
73
66
|
errors: 0,
|
|
74
67
|
properties: 0,
|
|
75
|
-
filters: 0
|
|
68
|
+
filters: 0
|
|
76
69
|
};
|
|
77
70
|
if (!zip) {
|
|
78
71
|
return meta;
|
|
@@ -80,21 +73,20 @@ function getFilterFetcherProcessor(db) {
|
|
|
80
73
|
try {
|
|
81
74
|
const [properties, invalidFilters] = await Promise.all([
|
|
82
75
|
getProperties(zip),
|
|
83
|
-
getInvalidFilters()
|
|
76
|
+
getInvalidFilters()
|
|
84
77
|
]);
|
|
85
78
|
meta.requests += 1;
|
|
86
79
|
meta.properties += properties.length;
|
|
87
|
-
const filters =
|
|
80
|
+
const filters = calculateFilterCount(properties, invalidFilters);
|
|
88
81
|
await deleteZipFilter(zip);
|
|
89
82
|
meta.requests += 1;
|
|
90
83
|
await addZipFilters({
|
|
91
84
|
zip,
|
|
92
|
-
...filters
|
|
85
|
+
...filters
|
|
93
86
|
});
|
|
94
87
|
meta.filters += 1;
|
|
95
88
|
meta.requests += 1;
|
|
96
|
-
}
|
|
97
|
-
catch (e) {
|
|
89
|
+
} catch (e) {
|
|
98
90
|
console.error(e);
|
|
99
91
|
errors.add(zip);
|
|
100
92
|
meta.errors += 1;
|
|
@@ -103,4 +95,3 @@ function getFilterFetcherProcessor(db) {
|
|
|
103
95
|
return meta;
|
|
104
96
|
};
|
|
105
97
|
}
|
|
106
|
-
exports.getFilterFetcherProcessor = getFilterFetcherProcessor;
|
|
@@ -1,51 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.propertyUseGroupProcessorAggregate = exports.getPropertyUseGroupProcessor = void 0;
|
|
4
|
-
const utils_1 = require("../utils/utils");
|
|
5
|
-
const getPropertiesCollection = async (db) => {
|
|
1
|
+
import { isEmptyField } from '../utils/utils';
|
|
2
|
+
const getPropertiesCollection = async (db)=>{
|
|
6
3
|
return db.collection('properties');
|
|
7
4
|
};
|
|
8
5
|
function fixPropertyName(propertyName) {
|
|
9
6
|
return propertyName ? propertyName.toUpperCase() : '';
|
|
10
7
|
}
|
|
11
|
-
function getPropertyUseGroupProcessor(db) {
|
|
8
|
+
export function getPropertyUseGroupProcessor(db) {
|
|
12
9
|
function fixPropertyNames(properties) {
|
|
13
|
-
return properties
|
|
14
|
-
.filter(p => p.propertyusegroup &&
|
|
15
|
-
typeof p.propertyusegroup === 'string' &&
|
|
16
|
-
!(0, utils_1.isEmptyField)(p.propertyusegroup))
|
|
17
|
-
.map(p => {
|
|
10
|
+
return properties.filter((p)=>p.propertyusegroup && typeof p.propertyusegroup === 'string' && !isEmptyField(p.propertyusegroup)).map((p)=>{
|
|
18
11
|
return {
|
|
19
12
|
...p,
|
|
20
|
-
propertyusegroup: fixPropertyName(p.propertyusegroup)
|
|
13
|
+
propertyusegroup: fixPropertyName(p.propertyusegroup)
|
|
21
14
|
};
|
|
22
15
|
});
|
|
23
16
|
}
|
|
24
|
-
const updateProperties = async (properties)
|
|
17
|
+
const updateProperties = async (properties)=>{
|
|
25
18
|
const collection = await getPropertiesCollection(db);
|
|
26
|
-
const propQuery = properties.map(({ _id, ...p })
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
const propQuery = properties.map(({ _id, ...p })=>({
|
|
20
|
+
updateOne: {
|
|
21
|
+
filter: {
|
|
22
|
+
_id
|
|
23
|
+
},
|
|
24
|
+
update: {
|
|
25
|
+
$set: p
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
return collection.bulkWrite(propQuery, {
|
|
30
|
+
ordered: true,
|
|
31
|
+
writeConcern: {
|
|
32
|
+
w: 1
|
|
33
|
+
}
|
|
34
|
+
});
|
|
33
35
|
};
|
|
34
|
-
const getProperties = (zip)
|
|
35
|
-
return db
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const getProperties = (zip)=>{
|
|
37
|
+
return db.collection('properties').find({
|
|
38
|
+
zipcode: zip
|
|
39
|
+
}, {
|
|
38
40
|
projection: {
|
|
39
|
-
propertyusegroup: 1
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
.toArray();
|
|
41
|
+
propertyusegroup: 1
|
|
42
|
+
}
|
|
43
|
+
}).toArray();
|
|
43
44
|
};
|
|
44
45
|
return async function processZip(zip, errors) {
|
|
45
46
|
const meta = {
|
|
46
47
|
requests: 0,
|
|
47
48
|
errors: 0,
|
|
48
|
-
properties: 0
|
|
49
|
+
properties: 0
|
|
49
50
|
};
|
|
50
51
|
if (!zip) {
|
|
51
52
|
return meta;
|
|
@@ -63,8 +64,7 @@ function getPropertyUseGroupProcessor(db) {
|
|
|
63
64
|
await updateProperties(convertedProperties);
|
|
64
65
|
meta.properties += convertedProperties.length;
|
|
65
66
|
meta.requests += 1;
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
67
|
+
} catch (e) {
|
|
68
68
|
console.error(e);
|
|
69
69
|
errors.add(zip);
|
|
70
70
|
meta.errors += 1;
|
|
@@ -73,8 +73,7 @@ function getPropertyUseGroupProcessor(db) {
|
|
|
73
73
|
return meta;
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
async function propertyUseGroupProcessorAggregate(db) {
|
|
76
|
+
export async function propertyUseGroupProcessorAggregate(db) {
|
|
78
77
|
const collection = await getPropertiesCollection(db);
|
|
79
78
|
const aggCursor = await collection.aggregate([
|
|
80
79
|
{
|
|
@@ -82,24 +81,25 @@ async function propertyUseGroupProcessorAggregate(db) {
|
|
|
82
81
|
propertyusegroup: {
|
|
83
82
|
$function: {
|
|
84
83
|
body: fixPropertyName.toString(),
|
|
85
|
-
args: [
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
args: [
|
|
85
|
+
'$propertyusegroup'
|
|
86
|
+
],
|
|
87
|
+
lang: 'js'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
90
91
|
},
|
|
91
92
|
{
|
|
92
93
|
$merge: {
|
|
93
94
|
into: 'properties',
|
|
94
95
|
on: '_id',
|
|
95
96
|
whenMatched: 'replace',
|
|
96
|
-
whenNotMatched: 'insert'
|
|
97
|
-
}
|
|
98
|
-
}
|
|
97
|
+
whenNotMatched: 'insert'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
99
100
|
]);
|
|
100
101
|
let result;
|
|
101
102
|
do {
|
|
102
103
|
result = await aggCursor.next(); // eslint-disable-line no-await-in-loop
|
|
103
|
-
}
|
|
104
|
+
}while (result)
|
|
104
105
|
}
|
|
105
|
-
exports.propertyUseGroupProcessorAggregate = propertyUseGroupProcessorAggregate;
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.configureProcessor = void 0;
|
|
18
|
-
const filter_fetcher_1 = require("./filter-fetcher");
|
|
19
|
-
const fix_property_use_1 = require("./fix-property-use");
|
|
20
|
-
const property_assessorlastsaledate_converter_1 = require("./property-assessorlastsaledate-converter");
|
|
21
|
-
const zip_processor_1 = require("./zip-processor");
|
|
22
|
-
function configureProcessor(config) {
|
|
23
|
-
const filterFetcher = (0, zip_processor_1.zipProcessor)(config.workers, (0, filter_fetcher_1.getFilterFetcherProcessor)(config.mongoDb));
|
|
24
|
-
const assessorLastSaleDateProcessor = (0, zip_processor_1.zipProcessor)(config.workers, (0, property_assessorlastsaledate_converter_1.getAssessorLastSaleDateProcessor)(config.mongoDb));
|
|
25
|
-
const propertyUseGroupProcessor = (0, zip_processor_1.zipProcessor)(config.workers, (0, fix_property_use_1.getPropertyUseGroupProcessor)(config.mongoDb));
|
|
26
|
-
return { filterFetcher, assessorLastSaleDateProcessor, propertyUseGroupProcessor };
|
|
1
|
+
import { getFilterFetcherProcessor } from './filter-fetcher';
|
|
2
|
+
import { getPropertyUseGroupProcessor } from './fix-property-use';
|
|
3
|
+
import { getAssessorLastSaleDateProcessor } from './property-assessorlastsaledate-converter';
|
|
4
|
+
import { zipProcessor } from './zip-processor';
|
|
5
|
+
export function configureProcessor(config) {
|
|
6
|
+
const filterFetcher = zipProcessor(config.workers, getFilterFetcherProcessor(config.mongoDb));
|
|
7
|
+
const assessorLastSaleDateProcessor = zipProcessor(config.workers, getAssessorLastSaleDateProcessor(config.mongoDb));
|
|
8
|
+
const propertyUseGroupProcessor = zipProcessor(config.workers, getPropertyUseGroupProcessor(config.mongoDb));
|
|
9
|
+
return {
|
|
10
|
+
filterFetcher,
|
|
11
|
+
assessorLastSaleDateProcessor,
|
|
12
|
+
propertyUseGroupProcessor
|
|
13
|
+
};
|
|
27
14
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
__exportStar(require("./filter-fetcher"), exports);
|
|
15
|
+
export * from './fix-property-use';
|
|
16
|
+
export * from './property-assessorlastsaledate-converter';
|
|
17
|
+
export * from './filter-fetcher';
|
|
@@ -1,42 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.propertiesAssessorLastSaleDateAggregate = exports.getAssessorLastSaleDateProcessor = void 0;
|
|
4
|
-
const utils_1 = require("../utils/utils");
|
|
5
|
-
const getPropertiesCollection = async (db) => {
|
|
1
|
+
import { convertStringToDate } from '../utils/utils';
|
|
2
|
+
const getPropertiesCollection = async (db)=>{
|
|
6
3
|
return db.collection('properties');
|
|
7
4
|
};
|
|
8
|
-
function getAssessorLastSaleDateProcessor(db) {
|
|
9
|
-
const getPropertiesAssessorLastSaleDate = async (zip)
|
|
5
|
+
export function getAssessorLastSaleDateProcessor(db) {
|
|
6
|
+
const getPropertiesAssessorLastSaleDate = async (zip)=>{
|
|
10
7
|
const collection = await getPropertiesCollection(db);
|
|
11
|
-
return collection
|
|
12
|
-
.find({
|
|
8
|
+
return collection.find({
|
|
13
9
|
zipcode: zip,
|
|
14
10
|
assessorlastsaledate: {
|
|
15
11
|
$exists: true,
|
|
16
|
-
$type: 2
|
|
17
|
-
}
|
|
12
|
+
$type: 2
|
|
13
|
+
}
|
|
18
14
|
}, {
|
|
19
15
|
projection: {
|
|
20
|
-
assessorlastsaledate: 1
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
.toArray();
|
|
16
|
+
assessorlastsaledate: 1
|
|
17
|
+
}
|
|
18
|
+
}).toArray();
|
|
24
19
|
};
|
|
25
|
-
const updateProperties = async (properties)
|
|
20
|
+
const updateProperties = async (properties)=>{
|
|
26
21
|
const collection = await getPropertiesCollection(db);
|
|
27
|
-
const propQuery = properties.map(({ _id, ...p })
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
const propQuery = properties.map(({ _id, ...p })=>({
|
|
23
|
+
updateOne: {
|
|
24
|
+
filter: {
|
|
25
|
+
_id
|
|
26
|
+
},
|
|
27
|
+
update: {
|
|
28
|
+
$set: p
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
return collection.bulkWrite(propQuery, {
|
|
33
|
+
ordered: true,
|
|
34
|
+
writeConcern: {
|
|
35
|
+
w: 1
|
|
36
|
+
}
|
|
37
|
+
});
|
|
34
38
|
};
|
|
35
39
|
return async function processZip(zip, errors) {
|
|
36
40
|
const meta = {
|
|
37
41
|
requests: 0,
|
|
38
42
|
errors: 0,
|
|
39
|
-
properties: 0
|
|
43
|
+
properties: 0
|
|
40
44
|
};
|
|
41
45
|
if (!zip) {
|
|
42
46
|
return meta;
|
|
@@ -47,15 +51,14 @@ function getAssessorLastSaleDateProcessor(db) {
|
|
|
47
51
|
if (!properties?.length) {
|
|
48
52
|
return meta;
|
|
49
53
|
}
|
|
50
|
-
const convertedProperties =
|
|
54
|
+
const convertedProperties = convertStringToDate(properties, 'assessorlastsaledate');
|
|
51
55
|
if (!convertedProperties.length) {
|
|
52
56
|
return meta;
|
|
53
57
|
}
|
|
54
58
|
await updateProperties(convertedProperties);
|
|
55
59
|
meta.properties += convertedProperties.length;
|
|
56
60
|
meta.requests += 1;
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
61
|
+
} catch (e) {
|
|
59
62
|
console.error(e);
|
|
60
63
|
meta.errors += 1;
|
|
61
64
|
errors.add(zip);
|
|
@@ -64,17 +67,16 @@ function getAssessorLastSaleDateProcessor(db) {
|
|
|
64
67
|
return meta;
|
|
65
68
|
};
|
|
66
69
|
}
|
|
67
|
-
|
|
68
|
-
async function propertiesAssessorLastSaleDateAggregate(db) {
|
|
70
|
+
export async function propertiesAssessorLastSaleDateAggregate(db) {
|
|
69
71
|
const collection = await getPropertiesCollection(db);
|
|
70
72
|
const aggCursor = collection.aggregate([
|
|
71
73
|
{
|
|
72
74
|
$match: {
|
|
73
75
|
assessorlastsaledate: {
|
|
74
76
|
$exists: true,
|
|
75
|
-
$type: 2
|
|
76
|
-
}
|
|
77
|
-
}
|
|
77
|
+
$type: 2
|
|
78
|
+
}
|
|
79
|
+
}
|
|
78
80
|
},
|
|
79
81
|
{
|
|
80
82
|
$set: {
|
|
@@ -83,24 +85,25 @@ async function propertiesAssessorLastSaleDateAggregate(db) {
|
|
|
83
85
|
body: `function (d) {
|
|
84
86
|
return new Date(d);
|
|
85
87
|
}`,
|
|
86
|
-
args: [
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
args: [
|
|
89
|
+
'$assessorlastsaledate'
|
|
90
|
+
],
|
|
91
|
+
lang: 'js'
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
91
95
|
},
|
|
92
96
|
{
|
|
93
97
|
$merge: {
|
|
94
98
|
into: 'properties',
|
|
95
99
|
on: '_id',
|
|
96
100
|
whenMatched: 'replace',
|
|
97
|
-
whenNotMatched: 'insert'
|
|
98
|
-
}
|
|
99
|
-
}
|
|
101
|
+
whenNotMatched: 'insert'
|
|
102
|
+
}
|
|
103
|
+
}
|
|
100
104
|
]);
|
|
101
105
|
let result;
|
|
102
106
|
do {
|
|
103
107
|
result = await aggCursor.next(); // eslint-disable-line no-await-in-loop
|
|
104
|
-
}
|
|
108
|
+
}while (result)
|
|
105
109
|
}
|
|
106
|
-
exports.propertiesAssessorLastSaleDateAggregate = propertiesAssessorLastSaleDateAggregate;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WithId } from 'mongodb';
|
|
2
|
-
export
|
|
2
|
+
export type Property = WithId<{
|
|
3
3
|
attomid: number;
|
|
4
4
|
fulladdress: string;
|
|
5
5
|
addressstreet: string;
|
|
@@ -232,7 +232,7 @@ export interface Group {
|
|
|
232
232
|
export interface GroupNamed extends Group {
|
|
233
233
|
groupName: string;
|
|
234
234
|
}
|
|
235
|
-
export
|
|
235
|
+
export type Filter = WithId<{
|
|
236
236
|
zipcode: string;
|
|
237
237
|
propertyusegroup: Group[];
|
|
238
238
|
propertyusestandardized: GroupNamed[];
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export { };
|