@servicetitan/acquisition-functions 0.12.0 → 5.7.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.
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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 } = (0, utils_1.FilterNameValidator)(filtersToIgnore, utils_1.UNKNOWN);
16
- properties
17
- .map(p => ({
18
- ...p,
19
- propertyusegroup: (0, utils_1.capitalizeFirstLetter)(p.propertyusegroup),
20
- propertyusestandardized: (0, utils_1.capitalizeFirstLetter)(p.propertyusestandardized),
21
- hvaccoolingdetail: (0, utils_1.capitalizeFirstLetter)(p.hvaccoolingdetail),
22
- hvacheatingdetail: (0, utils_1.capitalizeFirstLetter)(p.hvacheatingdetail),
23
- utilitieswatersource: (0, utils_1.capitalizeFirstLetter)(p.utilitieswatersource),
24
- utilitiessewageusage: (0, utils_1.capitalizeFirstLetter)(p.utilitiessewageusage),
25
- flooringmaterialprimary: (0, utils_1.capitalizeFirstLetter)(p.flooringmaterialprimary),
26
- }))
27
- .forEach(p => {
28
- if (isValidFilterName(p.propertyusestandardized.toLowerCase()) &&
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
- name,
66
- count: filterCount.propertyusegroup[name],
67
- }));
68
- const propertyusestandardizedCounts = Object.keys(filterCount.propertyusestandardized).map(key => {
69
- const [name, groupName] = key.split(utils_1.SEPARATOR_CHARACTER);
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
- name,
78
- count: filterCount.hvaccoolingdetail[name],
79
- }));
80
- const flooringmaterialprimaryCounts = Object.keys(filterCount.flooringmaterialprimary).map(name => ({
81
- name,
82
- count: filterCount.flooringmaterialprimary[name],
83
- }));
84
- const hvacheatingdetailCounts = Object.keys(filterCount.hvacheatingdetail).map(name => ({
85
- name,
86
- count: filterCount.hvacheatingdetail[name],
87
- }));
88
- const utilitieswatersourceCounts = Object.keys(filterCount.utilitieswatersource).map(name => ({
89
- name,
90
- count: filterCount.utilitieswatersource[name],
91
- }));
92
- const utilitiessewageusageCounts = Object.keys(filterCount.utilitiessewageusage).map(name => ({
93
- name,
94
- count: filterCount.utilitiessewageusage[name],
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFilterFetcherProcessor = getFilterFetcherProcessor;
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({ zipcode: zip });
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
- .collection('properties')
31
- .find({ zipcode: zip }, {
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
- .toArray()
60
- .then(results => {
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 = (0, calc_filter_count_1.calculateFilterCount)(properties, invalidFilters);
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;
@@ -1,52 +1,52 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPropertyUseGroupProcessor = getPropertyUseGroupProcessor;
4
- exports.propertyUseGroupProcessorAggregate = propertyUseGroupProcessorAggregate;
5
- const utils_1 = require("../utils/utils");
6
- const getPropertiesCollection = async (db) => {
1
+ import { isEmptyField } from '../utils/utils';
2
+ const getPropertiesCollection = async (db)=>{
7
3
  return db.collection('properties');
8
4
  };
9
5
  function fixPropertyName(propertyName) {
10
6
  return propertyName ? propertyName.toUpperCase() : '';
11
7
  }
12
- function getPropertyUseGroupProcessor(db) {
8
+ export function getPropertyUseGroupProcessor(db) {
13
9
  function fixPropertyNames(properties) {
14
- return properties
15
- .filter(p => p.propertyusegroup &&
16
- typeof p.propertyusegroup === 'string' &&
17
- !(0, utils_1.isEmptyField)(p.propertyusegroup))
18
- .map(p => {
10
+ return properties.filter((p)=>p.propertyusegroup && typeof p.propertyusegroup === 'string' && !isEmptyField(p.propertyusegroup)).map((p)=>{
19
11
  return {
20
12
  ...p,
21
- propertyusegroup: fixPropertyName(p.propertyusegroup),
13
+ propertyusegroup: fixPropertyName(p.propertyusegroup)
22
14
  };
23
15
  });
24
16
  }
25
- const updateProperties = async (properties) => {
17
+ const updateProperties = async (properties)=>{
26
18
  const collection = await getPropertiesCollection(db);
27
- const propQuery = properties.map(({ _id, ...p }) => ({
28
- updateOne: {
29
- filter: { _id },
30
- update: { $set: p },
31
- },
32
- }));
33
- return collection.bulkWrite(propQuery, { ordered: true, writeConcern: { w: 1 } });
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
+ });
34
35
  };
35
- const getProperties = (zip) => {
36
- return db
37
- .collection('properties')
38
- .find({ zipcode: zip }, {
36
+ const getProperties = (zip)=>{
37
+ return db.collection('properties').find({
38
+ zipcode: zip
39
+ }, {
39
40
  projection: {
40
- propertyusegroup: 1,
41
- },
42
- })
43
- .toArray();
41
+ propertyusegroup: 1
42
+ }
43
+ }).toArray();
44
44
  };
45
45
  return async function processZip(zip, errors) {
46
46
  const meta = {
47
47
  requests: 0,
48
48
  errors: 0,
49
- properties: 0,
49
+ properties: 0
50
50
  };
51
51
  if (!zip) {
52
52
  return meta;
@@ -64,8 +64,7 @@ function getPropertyUseGroupProcessor(db) {
64
64
  await updateProperties(convertedProperties);
65
65
  meta.properties += convertedProperties.length;
66
66
  meta.requests += 1;
67
- }
68
- catch (e) {
67
+ } catch (e) {
69
68
  console.error(e);
70
69
  errors.add(zip);
71
70
  meta.errors += 1;
@@ -74,7 +73,7 @@ function getPropertyUseGroupProcessor(db) {
74
73
  return meta;
75
74
  };
76
75
  }
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,23 +81,25 @@ async function propertyUseGroupProcessorAggregate(db) {
82
81
  propertyusegroup: {
83
82
  $function: {
84
83
  body: fixPropertyName.toString(),
85
- args: ['$propertyusegroup'],
86
- lang: 'js',
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
- } while (result);
104
+ }while (result)
104
105
  }
package/dist/index.js CHANGED
@@ -1,30 +1,17 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
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 = configureProcessor;
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
- __exportStar(require("./fix-property-use"), exports);
29
- __exportStar(require("./property-assessorlastsaledate-converter"), exports);
30
- __exportStar(require("./filter-fetcher"), exports);
15
+ export * from './fix-property-use';
16
+ export * from './property-assessorlastsaledate-converter';
17
+ export * from './filter-fetcher';
@@ -1,43 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAssessorLastSaleDateProcessor = getAssessorLastSaleDateProcessor;
4
- exports.propertiesAssessorLastSaleDateAggregate = propertiesAssessorLastSaleDateAggregate;
5
- const utils_1 = require("../utils/utils");
6
- const getPropertiesCollection = async (db) => {
1
+ import { convertStringToDate } from '../utils/utils';
2
+ const getPropertiesCollection = async (db)=>{
7
3
  return db.collection('properties');
8
4
  };
9
- function getAssessorLastSaleDateProcessor(db) {
10
- const getPropertiesAssessorLastSaleDate = async (zip) => {
5
+ export function getAssessorLastSaleDateProcessor(db) {
6
+ const getPropertiesAssessorLastSaleDate = async (zip)=>{
11
7
  const collection = await getPropertiesCollection(db);
12
- return collection
13
- .find({
8
+ return collection.find({
14
9
  zipcode: zip,
15
10
  assessorlastsaledate: {
16
11
  $exists: true,
17
- $type: 2,
18
- },
12
+ $type: 2
13
+ }
19
14
  }, {
20
15
  projection: {
21
- assessorlastsaledate: 1,
22
- },
23
- })
24
- .toArray();
16
+ assessorlastsaledate: 1
17
+ }
18
+ }).toArray();
25
19
  };
26
- const updateProperties = async (properties) => {
20
+ const updateProperties = async (properties)=>{
27
21
  const collection = await getPropertiesCollection(db);
28
- const propQuery = properties.map(({ _id, ...p }) => ({
29
- updateOne: {
30
- filter: { _id },
31
- update: { $set: p },
32
- },
33
- }));
34
- return collection.bulkWrite(propQuery, { ordered: true, writeConcern: { w: 1 } });
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
+ });
35
38
  };
36
39
  return async function processZip(zip, errors) {
37
40
  const meta = {
38
41
  requests: 0,
39
42
  errors: 0,
40
- properties: 0,
43
+ properties: 0
41
44
  };
42
45
  if (!zip) {
43
46
  return meta;
@@ -48,15 +51,14 @@ function getAssessorLastSaleDateProcessor(db) {
48
51
  if (!properties?.length) {
49
52
  return meta;
50
53
  }
51
- const convertedProperties = (0, utils_1.convertStringToDate)(properties, 'assessorlastsaledate');
54
+ const convertedProperties = convertStringToDate(properties, 'assessorlastsaledate');
52
55
  if (!convertedProperties.length) {
53
56
  return meta;
54
57
  }
55
58
  await updateProperties(convertedProperties);
56
59
  meta.properties += convertedProperties.length;
57
60
  meta.requests += 1;
58
- }
59
- catch (e) {
61
+ } catch (e) {
60
62
  console.error(e);
61
63
  meta.errors += 1;
62
64
  errors.add(zip);
@@ -65,16 +67,16 @@ function getAssessorLastSaleDateProcessor(db) {
65
67
  return meta;
66
68
  };
67
69
  }
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,23 +85,25 @@ async function propertiesAssessorLastSaleDateAggregate(db) {
83
85
  body: `function (d) {
84
86
  return new Date(d);
85
87
  }`,
86
- args: ['$assessorlastsaledate'],
87
- lang: 'js',
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
- } while (result);
108
+ }while (result)
105
109
  }
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export { };
@@ -10,13 +10,13 @@ export declare const convertStringToDate: (props: Property[], propName: keyof Pr
10
10
  addressunit: string;
11
11
  primarynumber: number;
12
12
  streetname: string;
13
- streetpredirection?: string;
14
- streetpostdirection?: string;
13
+ streetpredirection?: string | undefined;
14
+ streetpostdirection?: string | undefined;
15
15
  streetsuffix: string;
16
- secondarynumber?: number;
16
+ secondarynumber?: number | undefined;
17
17
  secondarydesignator: string;
18
- extrasecondarynumber?: number;
19
- extrasecondarydesignator?: string;
18
+ extrasecondarynumber?: number | undefined;
19
+ extrasecondarydesignator?: string | undefined;
20
20
  cityname: string;
21
21
  stateabbreviation: string;
22
22
  zipcode: string;