@servicetitan/acquisition-functions 0.2.0 → 0.4.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/README.md CHANGED
@@ -14,6 +14,7 @@ const { configureProcessor } = require('@servicetitan/acquisition-functions');
14
14
  const { filterFetcher } = configureProcessor({
15
15
  workers: 10,
16
16
  mongoDb: mongoDbConnectionToDb,
17
+ fetchProperties: (zip) => mongoDbConnectionToDb.collection('properties').find({zipcode: zip}, {_id: 0}),
17
18
  });
18
19
 
19
20
  exports = async () => {
@@ -4,19 +4,23 @@ const globals_1 = require("@jest/globals");
4
4
  const index_1 = require("../index");
5
5
  const setup_1 = require("./setup");
6
6
  describe('property-assessorlastsaledate-converter', () => {
7
- let processor;
8
7
  let base;
9
8
  let metadata;
10
9
  (0, globals_1.beforeAll)(async () => {
11
10
  const client = await (0, setup_1.openConnection)();
12
11
  base = client.db('test');
13
12
  await (0, setup_1.setupProperties)(base);
14
- processor = (0, index_1.configureProcessor)({
13
+ const { filterFetcher } = (0, index_1.configureProcessor)({
15
14
  workers: 10,
16
15
  mongoDb: base,
16
+ fetchProperties: (0, setup_1.getFetchPropertiesForFilters)(base),
17
17
  });
18
- const { filterFetcher, propertyUseGroupProcessor } = processor;
19
- await propertyUseGroupProcessor.start('90001');
18
+ const { propertyUseGroupProcessor } = (0, index_1.configureProcessor)({
19
+ workers: 10,
20
+ mongoDb: base,
21
+ fetchProperties: (0, setup_1.getFetchPropertiesForFix)(base),
22
+ });
23
+ await propertyUseGroupProcessor.start(['90001', '90002']);
20
24
  metadata = await filterFetcher.start(['90001', '90002']);
21
25
  });
22
26
  (0, globals_1.test)('should have empty filter for missing zip', async () => {
@@ -17,6 +17,7 @@ describe('property-use-group-converter', () => {
17
17
  processor = (0, index_1.configureProcessor)({
18
18
  workers: 1,
19
19
  mongoDb: base,
20
+ fetchProperties: (0, setup_1.getFetchPropertiesForFix)(base),
20
21
  });
21
22
  const { propertyUseGroupProcessor } = processor;
22
23
  metadata = await propertyUseGroupProcessor.start('90001');
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.closeConnection = exports.openConnection = exports.setupProperties = void 0;
3
+ exports.getFetchPropertiesForFix = exports.getFetchPropertiesForFilters = exports.closeConnection = exports.openConnection = exports.setupProperties = void 0;
4
4
  const mongodb_1 = require("mongodb");
5
5
  const mock_1 = require("./mock");
6
6
  async function setupProperties(base) {
@@ -39,3 +39,32 @@ const openConnection = async () => {
39
39
  exports.openConnection = openConnection;
40
40
  const closeConnection = () => connectedMongoClient?.close();
41
41
  exports.closeConnection = closeConnection;
42
+ const getFetchPropertiesForFilters = (base) => async (zip) => {
43
+ return base
44
+ .collection('properties')
45
+ .find({ zipcode: zip }, {
46
+ projection: {
47
+ zipcode: 1,
48
+ propertyusegroup: 1,
49
+ propertyusestandardized: 1,
50
+ hvaccoolingdetail: 1,
51
+ hvacheatingdetail: 1,
52
+ utilitieswatersource: 1,
53
+ flooringmaterialprimary: 1,
54
+ _id: 0, // eslint-disable-line
55
+ },
56
+ })
57
+ .toArray();
58
+ };
59
+ exports.getFetchPropertiesForFilters = getFetchPropertiesForFilters;
60
+ const getFetchPropertiesForFix = (base) => async (zip) => {
61
+ return base
62
+ .collection('properties')
63
+ .find({ zipcode: zip }, {
64
+ projection: {
65
+ propertyusegroup: 1,
66
+ },
67
+ })
68
+ .toArray();
69
+ };
70
+ exports.getFetchPropertiesForFix = getFetchPropertiesForFix;
@@ -2,30 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFilterFetcherProcessor = void 0;
4
4
  const calc_filter_count_1 = require("./calc-filter-count");
5
- function getFilterFetcherProcessor(db) {
6
- const getPropertiesCollection = async () => {
7
- return db.collection('properties');
8
- };
5
+ function getFilterFetcherProcessor({ mongoDb: db, fetchProperties }) {
9
6
  const getFiltersCollection = async () => {
10
7
  return db.collection('filters');
11
8
  };
12
- const getProperties = async (zip) => {
13
- const collection = await getPropertiesCollection();
14
- return collection
15
- .find({ zipcode: zip }, {
16
- projection: {
17
- zipcode: 1,
18
- propertyusegroup: 1,
19
- propertyusestandardized: 1,
20
- hvaccoolingdetail: 1,
21
- hvacheatingdetail: 1,
22
- utilitieswatersource: 1,
23
- flooringmaterialprimary: 1,
24
- _id: 0, // eslint-disable-line
25
- },
26
- })
27
- .toArray();
28
- };
29
9
  const deleteZipFilter = async (zip) => {
30
10
  const collection = await getFiltersCollection();
31
11
  return collection.deleteOne({ zipcode: zip });
@@ -53,7 +33,7 @@ function getFilterFetcherProcessor(db) {
53
33
  return meta;
54
34
  }
55
35
  try {
56
- const properties = await getProperties(zip);
36
+ const properties = await fetchProperties(zip);
57
37
  meta.requests += 1;
58
38
  meta.properties += properties.length;
59
39
  const filters = (0, calc_filter_count_1.calculateFilterCount)(properties);
@@ -8,17 +8,7 @@ const getPropertiesCollection = async (db) => {
8
8
  function fixPropertyName(propertyName) {
9
9
  return propertyName ? propertyName.toUpperCase() : '';
10
10
  }
11
- function getPropertyUseGroupProcessor(db) {
12
- const getProperties = async (zip) => {
13
- const collection = await getPropertiesCollection(db);
14
- return collection
15
- .find({ zipcode: zip }, {
16
- projection: {
17
- propertyusegroup: 1,
18
- },
19
- })
20
- .toArray();
21
- };
11
+ function getPropertyUseGroupProcessor({ mongoDb: db, fetchProperties }) {
22
12
  function fixPropertyNames(properties) {
23
13
  return properties
24
14
  .filter(p => p.propertyusegroup &&
@@ -52,9 +42,9 @@ function getPropertyUseGroupProcessor(db) {
52
42
  return meta;
53
43
  }
54
44
  try {
55
- const properties = await getProperties(zip);
45
+ const properties = await fetchProperties(zip);
56
46
  meta.requests += 1;
57
- if (!properties || !properties.length) {
47
+ if (!properties?.length) {
58
48
  return meta;
59
49
  }
60
50
  const convertedProperties = fixPropertyNames(properties);
package/dist/index.js CHANGED
@@ -6,9 +6,9 @@ const fix_property_use_1 = require("./fix-property-use");
6
6
  const property_assessorlastsaledate_converter_1 = require("./property-assessorlastsaledate-converter");
7
7
  const zip_processor_1 = require("./zip-processor");
8
8
  function configureProcessor(config) {
9
- const filterFetcher = (0, zip_processor_1.zipProcessor)(config, (0, filter_fetcher_1.getFilterFetcherProcessor)(config.mongoDb));
9
+ const filterFetcher = (0, zip_processor_1.zipProcessor)(config, (0, filter_fetcher_1.getFilterFetcherProcessor)(config));
10
10
  const assessorLastSaleDateProcessor = (0, zip_processor_1.zipProcessor)(config, (0, property_assessorlastsaledate_converter_1.getAssessorLastSaleDateProcessor)(config.mongoDb));
11
- const propertyUseGroupProcessor = (0, zip_processor_1.zipProcessor)(config, (0, fix_property_use_1.getPropertyUseGroupProcessor)(config.mongoDb));
11
+ const propertyUseGroupProcessor = (0, zip_processor_1.zipProcessor)(config, (0, fix_property_use_1.getPropertyUseGroupProcessor)(config));
12
12
  return { filterFetcher, assessorLastSaleDateProcessor, propertyUseGroupProcessor };
13
13
  }
14
14
  exports.configureProcessor = configureProcessor;
@@ -45,7 +45,7 @@ function getAssessorLastSaleDateProcessor(db) {
45
45
  try {
46
46
  const properties = await getPropertiesAssessorLastSaleDate(zip);
47
47
  meta.requests += 1;
48
- if (!properties || !properties.length) {
48
+ if (!properties?.length) {
49
49
  return meta;
50
50
  }
51
51
  const convertedProperties = (0, utils_1.convertStringToDate)(properties, 'assessorlastsaledate');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/acquisition-functions",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
@@ -28,5 +28,5 @@
28
28
  "cli": {
29
29
  "webpack": false
30
30
  },
31
- "gitHead": "7c93d00316dcd4bd83e1a42720579ed22c6ce208"
31
+ "gitHead": "b6eb3ea4bcc2edd37b3337067048605589f8972d"
32
32
  }